⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 thewindow.java

📁 简单的小型超市管理
💻 JAVA
字号:
import java.awt.*;
import java.awt.event.*;

import javax.swing.*;
import javax.swing.border.*;
import java.sql.*;

class ConnectionSQL
{
	public static Connection con;
	public static Statement sql;
	public static ResultSet rs;
	ConnectionSQL()
	{
		try {
			Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
		}
		catch(ClassNotFoundException e)
		{
			JOptionPane.showMessageDialog(null, "JDBC-ODBC创建失败!", "提示", JOptionPane.INFORMATION_MESSAGE);
		}
		try {
			con = DriverManager.getConnection("jdbc:odbc:超市管理", "", "");			
		}
		catch(SQLException e)
		{
			JOptionPane.showMessageDialog(null, "数据库连接失败!", "提示", JOptionPane.INFORMATION_MESSAGE);
		}
	}
}

class Window extends JFrame implements ActionListener
{
	ConnectionSQL conSql;/////////////
	JMenuBar menubar;
	JMenuItem menu1, menu2, menu3, menu4, menu5, menu6;
	//JMenuItem item1, item2, item3, item4, item5, item6;
	JButton but, buyButn, findButn, saleButn, systemButn;    //列菜单按钮
	CustomerDlg CusDlg;        //客户添加
	CustomerList CusList;      //客户列表
	CustomerDel CusDel;        //客户删除
	JButton cusAdd, cusDel, cusLis;     //客户管理页的按钮
	
	BuyCargoDlg BuyDlg;        //采购货物
	BuyCargoList BuyList;      //进货列表
	BuyCargoDel BuyDel;        //退货
	BuyCargoBList BuyBL;       //退货列表
	JButton buyIn, buyIL, buyBac, buyBL;      //采购货物页的按钮
	
	SaleAdd SaAdd;             //销售货物
	SaleList SaList;
	JButton saleAdd, saleList;
	
	SearchCargo Search;       //货物查询
	Money theMoney;
	JButton search, money, fbuyIL, fsaleList;
	
	UserAdd UsAdd;// UsDel, UsChange;
	UserChange UsChange;
	UserDel UsDel;
	JButton userAdd, userDel, userChange;
	
	CardLayout card;
	JPanel pCenter;
	Window(String s)
	{
		super(s);
		Container con = getContentPane();
		setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);   //关闭
		//setBackground(Color.cyan);  //设置背景颜色
			
		Toolkit tool = getToolkit();
		Dimension dim = tool.getScreenSize();  //获得系统桌面大小
		menubar = new JMenuBar();
		menu1 = new JMenuItem("客户管理");		menu2 = new JMenuItem("采购入库");		menu3 = new JMenuItem("销售货物");
		menu4 = new JMenuItem("统计查询");		menu5 = new JMenuItem("系统管理");		menu6 = new JMenuItem("退出");
		menu6.setPreferredSize(new Dimension(400,20));
		
		menu1.addActionListener(this);			menu2.addActionListener(this);
		menu3.addActionListener(this);			menu4.addActionListener(this);
		menu5.addActionListener(this);			menu6.addActionListener(this);	
		menubar.add(menu1);		menubar.add(menu2);		menubar.add(menu3);
		menubar.add(menu4);		menubar.add(menu5);		menubar.add(menu6);
		setJMenuBar(menubar);
		
		but = new JButton("客户管理");
		buyButn = new JButton("采购入库");
		saleButn = new JButton("销售货物");
		findButn = new JButton("统计查询");		
		systemButn = new JButton("系统管理");
		but.addActionListener(this);
		buyButn.addActionListener(this);
		saleButn.addActionListener(this);
		findButn.addActionListener(this);
		systemButn.addActionListener(this);
		
		JPanel panelBar = new JPanel();
		panelBar.setLayout(new GridLayout(6, 1));
		panelBar.setBackground(new Color(100, 100, 90));
		panelBar.add(but);
		panelBar.add(buyButn);
		panelBar.add(saleButn);
		panelBar.add(findButn);		
		panelBar.add(systemButn);
		
		but.setPreferredSize(new Dimension(100, 40));  //设置按钮的大小
		
		con.add(panelBar, BorderLayout.WEST);
		
		JPanel pOn1 = new JPanel(), pOn2 = new JPanel(),
		   pOn3 = new JPanel(), pOn4 = new JPanel(),
		   pOn5 = new JPanel(), pOn6 = new JPanel();
	
		//客户管理页面*************************************************************
		cusAdd = new JButton("添加客户");
		cusDel = new JButton("删除客户");
		cusLis = new JButton("客户列表");
		cusAdd.setBackground(Color.lightGray);
		cusDel.setBackground(Color.lightGray);
		cusLis.setBackground(Color.lightGray);
		cusAdd.addActionListener(this);
		cusLis.addActionListener(this);
		cusDel.addActionListener(this);
		
		pOn1.setLayout(new GridLayout(2,2, 20,20));
		pOn1.add(cusAdd);
		pOn1.add(cusDel);
		pOn1.add(cusLis);
		//pOn1.add(new JButton());
		pOn1.setBorder(BorderFactory.createEmptyBorder(100, 100, 100, 100));
		pOn1.setBackground(Color.lightGray);
		//**************************************************************************
		
		//采购货物页面***************************************************************
		buyIn = new JButton("采购进货");
		buyIL = new JButton("采购列表");
		buyBac = new JButton("退货");
		buyBL = new JButton("退货列表");
		buyIn.setBackground(Color.lightGray);
		buyIL.setBackground(Color.lightGray);
		buyBac.setBackground(Color.lightGray);
		buyBL.setBackground(Color.lightGray);
		buyIn.addActionListener(this);
		buyIL.addActionListener(this);
		buyBac.addActionListener(this);
		buyBL.addActionListener(this);
		pOn2.setLayout(new GridLayout(2,2,20,20));
		pOn2.add(buyIn);
		pOn2.add(buyIL);
		pOn2.add(buyBac);
		pOn2.add(buyBL);
		pOn2.setBorder(BorderFactory.createEmptyBorder(100, 100, 100, 100));
		pOn2.setBackground(Color.lightGray);
		//**************************************************************************
		
		//销售货物页面*****************************************************************
		saleAdd = new JButton("销售货物");
		saleList = new JButton("销售列表");
		saleAdd.setBackground(Color.lightGray);
		saleList.setBackground(Color.lightGray);
		saleAdd.addActionListener(this);
		saleList.addActionListener(this);
		pOn3.setLayout(new GridLayout(1,2,20,0));//
		pOn3.add(saleAdd);
		pOn3.add(saleList);
		pOn3.setBorder(BorderFactory.createEmptyBorder(140, 100, 140, 100));
		pOn3.setBackground(Color.lightGray);
		//***************************************************************************
		
		//统计查询********************************************************************
		search = new JButton("货物查询");
		money = new JButton("收支情况");
		fbuyIL = new JButton("采购列表");
		fsaleList = new JButton("销售列表");
		money.setBackground(Color.lightGray);
		search.setBackground(Color.lightGray);
		fbuyIL.setBackground(Color.lightGray);
		fsaleList.setBackground(Color.lightGray);
		search.addActionListener(this);
		money.addActionListener(this);
		fbuyIL.addActionListener(this);
		fsaleList.addActionListener(this);
		pOn4.setLayout(new GridLayout(2,2,20,20));
		pOn4.add(search);
		pOn4.add(money);
		pOn4.add(fbuyIL);
		pOn4.add(fsaleList);
		pOn4.setBorder(BorderFactory.createEmptyBorder(100, 100, 100, 100));
		pOn4.setBackground(Color.lightGray);
		//***************************************************************************
		
		//系统管理*******************************************************************
		userAdd = new JButton("添加用户");
		userDel = new JButton("删除用户");
		userChange = new JButton("修改密码");
		userAdd.setBackground(Color.lightGray);
		userDel.setBackground(Color.lightGray);
		userChange.setBackground(Color.lightGray);
		userAdd.addActionListener(this);
		userDel.addActionListener(this);
		userChange.addActionListener(this);
		pOn5.setLayout(new GridLayout(2,2,20,20));
		pOn5.add(userAdd);
		pOn5.add(userDel);
		pOn5.add(userChange);
		pOn5.setBorder(BorderFactory.createEmptyBorder(100, 100, 100, 100));
		pOn5.setBackground(Color.lightGray);
		//**************************************************************************
		card = new CardLayout();
		pCenter = new JPanel();
		pCenter.setLayout(card);
		pCenter.add("1", pOn1);
		pCenter.add("2", pOn2);
		pCenter.add("3", pOn3);
		pCenter.add("4", pOn4);
		pCenter.add("5", pOn5);
		pCenter.add("6", pOn6);
		
		con.add(pCenter, BorderLayout.CENTER);
		
		setBounds(150,100,dim.width*3/4,dim.height*3/4);
		setVisible(true);
		validate();
	}
	public void actionPerformed(ActionEvent e) {
		// TODO 自动生成方法存根
		if(e.getSource()==but || e.getSource()==menu1)
		{
			card.show(pCenter, "1");
		}
		else if(e.getSource()==buyButn || e.getSource()==menu2)
		{
			card.show(pCenter, "2");
		}
		else if(e.getSource()==saleButn || e.getSource()==menu3)
		{
			card.show(pCenter, "3");
		}
		else if(e.getSource()==findButn || e.getSource()==menu4)
		{
			card.show(pCenter, "4");
		}
		else if(e.getSource()==systemButn || e.getSource()==menu5)
		{
			card.show(pCenter, "5");
		}
		else if(e.getSource()==menu6)
		{
			int message = JOptionPane.showConfirmDialog(this, "是否退出?", "询问", JOptionPane.YES_NO_OPTION);
			if(message==JOptionPane.YES_OPTION)
				System.exit(0);
		}
		else if(e.getSource()==cusAdd)    //客户管理
		{
			CusDlg = new CustomerDlg(this, "添加客户", true);
			CusDlg.setLocationRelativeTo(null);                //居中显示
			CusDlg.setVisible(true);
		}
		else if(e.getSource()==cusDel)
		{
			CusDel = new CustomerDel(this, "删除客户", true);
			CusDel.setLocationRelativeTo(null);
			CusDel.setVisible(true);
		}
		else if(e.getSource()==cusLis)
		{
			CusList = new CustomerList(this, "客户列表", true);
			CusList.setLocationRelativeTo(null);
			CusList.setVisible(true);
		}
		else if(e.getSource()==buyIn)     //采购货物
		{
			BuyDlg = new BuyCargoDlg(this, "采购货物", true);
			BuyDlg.setLocationRelativeTo(null);
			BuyDlg.setVisible(true);
		}
		else if(e.getSource()==buyIL || e.getSource()==fbuyIL)
		{
			BuyList = new BuyCargoList(this, "进货列表", true);
			BuyList.setLocationRelativeTo(null);
			BuyList.setVisible(true);
		}
		else if(e.getSource()==buyBac)
		{
			BuyDel = new BuyCargoDel(this, "退回货物", true);
			BuyDel.setLocationRelativeTo(null);			
			BuyDel.setVisible(true);
		}
		else if(e.getSource()==buyBL)
		{
			BuyBL = new BuyCargoBList(this, "退货列表", true);
			BuyBL.setLocationRelativeTo(null);
			BuyBL.setVisible(true);
		}
		else if(e.getSource()==saleAdd)   //销售货物
		{
			SaAdd = new SaleAdd(this, "销售货物", true);
			SaAdd.setLocationRelativeTo(null);
			SaAdd.setVisible(true);
		}
		else if(e.getSource()==saleList || e.getSource()==fsaleList)
		{
			SaList = new SaleList(this, "销售列表", true);
			SaList.setLocationRelativeTo(null);
			SaList.setVisible(true);
		}
		else if(e.getSource()==search)
		{
			Search = new SearchCargo(this, "货物查询", true);
			Search.setLocationRelativeTo(null);
			Search.setVisible(true);
		}
		else if(e.getSource()==money)
		{
			theMoney = new Money(this, "收支情况", true);
			theMoney.setLocationRelativeTo(null);
			theMoney.setVisible(true);
		}
		else if(e.getSource()==userAdd)
		{
			UsAdd = new UserAdd(this, "添加用户", true);
			UsAdd.setLocationRelativeTo(null);
			UsAdd.setVisible(true);
		}
		else if(e.getSource()==userChange)
		{
			UsChange = new UserChange(this, "修改密码", true);
			UsChange.setLocationRelativeTo(null);
			UsChange.setVisible(true);
		}
		else if(e.getSource()==userDel)
		{
			UsDel = new UserDel(this, "删除密码", true);
			UsDel.setLocationRelativeTo(null);
			UsDel.setVisible(true);
		}
	}
}

class LoginDlg extends JFrame implements ActionListener
{
	ConnectionSQL conSql;
	JButton yesButn, noButn;
	JTextField name;
	JPasswordField pasw;
	LoginDlg(String s)
	{
		super(s);
		Container con = getContentPane();
		setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
		
		yesButn = new JButton("确定");
		noButn = new JButton("取消");
		yesButn.addActionListener(this);
		noButn.addActionListener(this);
		name = new JTextField(8);
		pasw = new JPasswordField(8);
		
		JPanel panel = new JPanel();		
		panel.add(yesButn);
		panel.add(noButn);
		
		Box box1, box2, box3, box;
		box1 = Box.createVerticalBox();
		box1.add(new JLabel("用户名:"));
		box1.add(Box.createVerticalStrut(18));
		box1.add(new JLabel("密    码:"));
		box2 = Box.createVerticalBox();
		box2.add(Box.createVerticalStrut(18));
		box2.add(name);
		box2.add(Box.createVerticalStrut(8));
		box2.add(pasw);
		box2.add(Box.createVerticalStrut(18));
		box3 = Box.createHorizontalBox();
		box3.add(Box.createHorizontalStrut(18));
		box3.add(box1);
		box3.add(Box.createHorizontalStrut(8));
		box3.add(box2);
		box3.add(Box.createHorizontalStrut(18));
		box = Box.createVerticalBox();
		box.add(box3);
		box.add(panel);
		box.add(Box.createVerticalStrut(8));
		con.add(box);
		setVisible(true);
		setSize(200,180);
		setLocationRelativeTo(null);   //在桌面中点显示
		validate();
	}
	public void actionPerformed(ActionEvent e) {
		// TODO 自动生成方法存根
		if(e.getSource()==yesButn)
		{
			if(name.getText().equals("") || pasw.getText().equals(""))
				JOptionPane.showMessageDialog(this, "用户和密码不能为空!", "警告", JOptionPane.WARNING_MESSAGE);
			else
			{
				try {
					conSql = new ConnectionSQL();     //连接数据库
					conSql.sql = conSql.con.createStatement();
					conSql.rs = conSql.sql.executeQuery("select * from PASSWORDS where 用户名='"+name.getText()+"' and 密码='"+pasw.getText()+"'");
					if(conSql.rs.next())
					{
						Window WinFrame = new Window("超市");
						setVisible(false);
					}
					else
						JOptionPane.showMessageDialog(this, "用户名或密码不正确\n请查正", "警告", JOptionPane.WARNING_MESSAGE);
				}
				catch(SQLException ee) {}		
			}						
		}
		else if(e.getSource()==noButn)
		{
			System.exit(0);
		}
	}	
}
public class TheWindow {
	public static void main(String args[])
	{
		LoginDlg login = new LoginDlg("连接");
	}
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -