java水果商城管理系统(界面框架代码)

实现前的准备,需要配置jdbc,导入jdbc驱动

jdbc驱动包下载地址:

http://junruocdn.zmide.com/mysql-connector-java-5.1.30.jar

正文开始

本项目模拟真实的超市管理模式,以管理员为面向对象,所要实现的功能是基本的增删改查,具体实现步骤如下:

管理员登录
进入欢迎界面
进入仓库管理界面
管理员进行增删改查

1,定义欢迎界面Welcome.java

本界面 主要针对按钮进行了部分优化并设置了面板的背景显示 用户通过点击“进入系统”按钮进入到“登录界面”

package com.fruit.main;
import java.util.prefs.BackingStoreException;

import javax.swing.ImageIcon;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;

public class Welcome extends JFrame{
	JButton b;
	ImageIcon image;
	JLabel label;
	public Welcome() {
		// TODO Auto-generated constructor stub
		this.setTitle("水果超市欢迎您!");
		this.setBounds(500, 100, 700, 600);
		this.setLayout(null);
		
		image = new ImageIcon("back.jpg");
		label = new JLabel(image);
        label.setBounds(0, 0, 700, 500);
		
        b = new JButton("进入系统");
		b.setBounds(200, 470, 280, 30);
		
		
		this.add(label);
		this.add(b);
		
		this.setVisible(true);
	}

	public static void main(String[] args) {
		// TODO Auto-generated method stub
		new Welcome();
		

	}



}

2,登录界面

部分代码如下:

Login.java

package com.fruit.main;

import java.awt.Color;
import java.awt.Font;
import java.util.List;
import java.util.Properties;

import javax.swing.ButtonGroup;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JOptionPane;
import javax.swing.JPasswordField;
import javax.swing.JRadioButton;
import javax.swing.JTextField;

import com.fruit.po.User;
import com.fruit.utils.BaseDao;

public class Login extends JFrame {

	JLabel l_username, l_password, l_per;
	JTextField t_username;
	JPasswordField t_password;
	JRadioButton r_per;
	JButton b_login, b_reg, b_reset, b_exit;

	public Login() {
		// TODO Auto-generated constructor stub
		this.setTitle("登录");
		this.setBounds(500, 100, 700, 600);
		this.setLayout(null);

//		界面设计

		l_username = new JLabel("用户名:");
		l_username.setBounds(190, 150, 60, 37);
		l_username.setForeground(Color.RED);

		t_username = new JTextField();
		t_username.setBounds(250, 155, 180, 30);
		t_username.setFont(new Font("宋体", Font.PLAIN, 20));

		l_password = new JLabel("密    码:");
		l_password.setBounds(190, 215, 60, 37);
		l_password.setForeground(Color.blue);

		t_password = new JPasswordField();
		t_password.setBounds(250, 220, 180, 30);
		t_password.setFont(new Font("宋体", Font.PLAIN, 20));

		l_per = new JLabel("权    限:");
		l_per.setBounds(190, 280, 130, 40);
		l_per.setForeground(Color.green);

		r_per = new JRadioButton("管理员");
		r_per.setBounds(255, 290, 100, 20);
		r_per.setSelected(true);

		b_login = new JButton("登录");
		b_login.setBounds(180, 350, 60, 30);

		b_reg = new JButton("注册");
		b_reg.setBounds(260, 350, 60, 30);

		b_reset = new JButton("重置");
		b_reset.setBounds(340, 350, 60, 30);

		b_exit = new JButton("退出");
		b_exit.setBounds(425, 350, 60, 30);

	

		this.add(l_username);
		this.add(l_password);
		this.add(l_per);
		this.add(t_username);
		this.add(t_password);
		this.add(r_per);
		this.add(b_login);
		this.add(b_reg);
		this.add(b_reset);
		this.add(b_exit);

		this.setVisible(true);

	}

	public static void main(String[] args) {
		// TODO Auto-generated method stub
//		new Login();
		new Welcome();
	}

}

3,注册界面reg.java

package com.fruit.main;
import java.awt.Color;
import java.awt.Font;
import java.io.FileOutputStream;
import java.util.List;
import java.util.Properties;

import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JOptionPane;
import javax.swing.JRadioButton;
import javax.swing.JTextField;

import com.fruit.po.User;
import com.fruit.utils.BaseDao;
import com.fruit.utils.PageUtil;

public class Reg extends JFrame{
	JLabel l_username, l_password;
	JTextField t_username,t_password;
	JButton b_login,b_reg,b_reset;
	
	public Reg() {
		// TODO Auto-generated constructor stub
		
		this.setTitle("注册");
		this.setBounds(500, 100, 700, 600);
		this.setLayout(null);

		

		
//		界面设计
		l_username = new JLabel("用户名:");
		l_username.setBounds(190, 150, 60, 37);
		l_username.setForeground(Color.RED);
		
		t_username=new JTextField();
		t_username.setBounds(250, 155,180, 30);
		t_username.setFont(new Font("宋体",Font.PLAIN,20));
		

		l_password = new JLabel("密    码:");
		l_password.setBounds(190, 215, 60, 37);
		l_password.setForeground(Color.blue);

		t_password=new JTextField();
		t_password.setBounds(250, 220,180, 30);
		t_password.setFont(new Font("宋体",Font.PLAIN,20));
		
		

		b_reg = new JButton("确定注册");
		b_reg.setBounds(190, 350, 90, 30);
		
	    
		b_login = new JButton("返回登录");
		b_login.setBounds(290, 350, 90, 30);
	 
		b_reset = new JButton("重置");
		b_reset.setBounds(390, 350, 90, 30);


	
		
		this.add(l_username);
		this.add(l_password);
		this.add(t_username);
		this.add(t_password);
		this.add(b_reg);
		this.add(b_login);
		this.add(b_reset);
		
		this.setVisible(true);

	}

	public static void main(String[] args) {
		// TODO Auto-generated method stub
//		new Reg();
	    new Welcome();
	}

}

4,商店界面Goods.java

package com.fruit.main;
import java.awt.Color;
import java.awt.Font;

import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JScrollPane;
import javax.swing.JTable;
import javax.swing.JTextField;

import com.fruit.utils.BaseDao;

public class Goods extends JFrame{
	JLabel listTitle,l_id,l_name,l_price,l_unit;
	
	JTable table;
	
	JScrollPane tablePane;//滚动
	
	JTextField j_add_id,j_add_name,j_add_price,j_add_unit
	,j_up_id,j_up_name,j_up_price,j_up_unit,j_de_id;
	
	JButton b_add,b_up,b_de,b_exit;
	
	public Goods() {
		// TODO Auto-generated constructor stub
		this.setTitle("超市货物管理");
		this.setBounds(500, 100, 700, 600);
		this.getContentPane().setBackground(Color.cyan);
		this.setLayout(null);
		
		
//		标题
		listTitle = new JLabel("水果列表"); 
		listTitle.setBounds(280, 15, 100, 20);
		listTitle.setFont(new Font("黑体",Font.PLAIN,20));
		this.add(listTitle);
		
//		退出登录
		b_exit = new JButton("退出登录");
		b_exit.setBounds(520, 15, 100, 20);
		b_exit.setFont(new Font("宋体",Font.PLAIN,16));
		add(b_exit);
		
		
		//表格
		table = new JTable();
		tablePane = new JScrollPane();
		
		table.getTableHeader().setReorderingAllowed(false);//列不可移动
		table.getTableHeader().setResizingAllowed(false);//不可拉动表格
		table.setEnabled(false);//不可更改数据
		tablePane.setBounds(30,50,630,270);
		tablePane.setViewportView(table);
		this.add(tablePane);
		
//		标签
		l_id = new JLabel("水果编号");
		l_name = new JLabel("水果名称");
		l_price = new JLabel("水果单价");
		l_unit = new JLabel("计价单位");
		
		l_id.setBounds(30, 330, 100, 30);
		l_id.setFont(new Font("宋体",Font.PLAIN,16));
		l_name.setBounds(150, 330, 100, 30);
		l_name.setFont(new Font("宋体",Font.PLAIN,16));
		l_price.setBounds(280, 330, 100, 30);
		l_price.setFont(new Font("宋体",Font.PLAIN,16));
		l_unit.setBounds(410, 330, 100, 30);
		l_unit.setFont(new Font("宋体",Font.PLAIN,16));
		
		
		this.add(l_id);
		this.add(l_name);
		this.add(l_price);
		this.add(l_unit);
		
		
//		增加
		j_add_id = new JTextField();
		j_add_name = new JTextField();
		j_add_price = new JTextField();
		j_add_unit = new JTextField();
		
		
		j_add_id.setBounds(30, 360, 80, 30);
		j_add_name.setBounds(150, 360, 80, 30);
		j_add_price.setBounds(280, 360, 80, 30);
		j_add_unit.setBounds(410, 360, 80, 30);
		
		this.add(j_add_id);
		this.add(j_add_name);
		this.add(j_add_price);
		this.add(j_add_unit);
		
		b_add = new JButton("提交");
		b_add.setBounds(540, 360, 80, 30);
		b_add.setFont(new Font("宋体",Font.PLAIN,16));
		this.add(b_add);
		
		
//		修改
		j_up_id = new JTextField();
		j_up_name = new JTextField();
		j_up_price = new JTextField();
		j_up_unit = new JTextField();
		
		j_up_id.setBounds(30, 410, 80, 30);
		j_up_name.setBounds(150, 410, 80, 30);
		j_up_price.setBounds(280, 410, 80, 30);
		j_up_unit.setBounds(410, 410, 80, 30);
		
		this.add(j_up_id);
		this.add(j_up_name);
		this.add(j_up_price);
		this.add(j_up_unit);
		
		b_up = new JButton("改动");
		b_up.setBounds(540, 410, 80, 36);
		b_up.setFont(new Font("宋体",Font.PLAIN,16));
		this.add(b_up);
		
		
		
//		删除
		j_de_id = new JTextField();
		
		j_de_id.setBounds(30, 460, 80, 36);//510
		this.add(j_de_id);
		
		b_de = new JButton("删除");
		b_de.setBounds(540, 460, 80, 36);//510
		b_de.setFont(new Font("宋体",Font.PLAIN,16));
		this.add(b_de);
		
		
		this.setVisible(true);
	}

	public static void main(String[] args) {
		// TODO Auto-generated method stub
		new Goods();
//		new Welcome();
	}



}
更多好资源,尽在“君若的小窝”
君若的小窝 » java水果商城管理系统(界面框架代码)