超市登录界面代码

来源:互联网 发布:tb程序化交易软件 编辑:程序博客网 时间:2024/05/19 22:45
import javax.swing.JPanel; import javax.swing.JFrame; import java.awt.Color; import java.awt.Dimension; import java.awt.Font; import javax.swing.JTextField; import java.awt.Rectangle; import javax.swing.ImageIcon; import javax.swing.JComboBox; import javax.swing.JButton; import javax.swing.JLabel; import java.sql.*; import java.awt.event.*; import java.io.IOException; import java.io.InputStream; import javax.swing.JOptionPane; import javax.swing.JPasswordField; import sun.audio.AudioPlayer; public class pass extends JFrame implements ActionListener { private static final long serialVersionUID = 1L; private JPanel jContentPane = null; private JTextField jTextField1 = null; private JComboBox jComboBox1 = null; private JButton jButton1 = null; private JButton jButton2 = null; private JLabel jLabel1 = null; private JLabel jLabel2 = null; private JLabel jLabel3 = null; private static Connection conn; // @jve:decl-index=0: private static Statement sql; // @jve:decl-index=0: private static ResultSet rs; // @jve:decl-index=0: private static int n = 0; public static String userlevel; private JPasswordField jPasswordField1 = null; private JLabel jLabel4 = null; private mainframe mainframe1; /** * This is the default constructor */ public pass() { super(); initialize(); } /** * This method initializes this * * @return void */ private void initialize() { this.setSize(354, 278); this.setContentPane(getJContentPane()); this.setTitle("系统登陆"); this.setResizable(false); Dimension screen = getToolkit().getScreenSize(); this.setLocation((screen.width - getSize().width) / 2, (screen.height - getSize().height) / 2); this.setVisible(true); this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); /* * addWindowListener(new WindowAdapter() { public void * windowClosing(WindowEvent e) { System.exit(0); } }); */ } /** * This method initializes jContentPane * * @return javax.swing.JPanel */ private JPanel getJContentPane() { if (jContentPane == null) { jLabel4 = new JLabel(); jLabel4.setBounds(new Rectangle(80, 0, 175, 32)); jLabel4.setText("小型超市管理系统"); jLabel4.setFont(new Font("楷体_GB2312", Font.BOLD, 20)); jLabel4.setForeground(Color.blue); jLabel3 = new JLabel(); jLabel3.setBounds(new Rectangle(15, 148, 82, 28)); jLabel3.setText("用户类型:"); jLabel2 = new JLabel(); jLabel2.setBounds(new Rectangle(15, 89, 82, 28)); jLabel2.setText("用户密码:"); jLabel1 = new JLabel(); jLabel1.setBounds(new Rectangle(15, 40, 82, 28)); jLabel1.setText("用户帐号:"); jContentPane = new JPanel(); jContentPane.setLayout(null); jContentPane.add(getJTextField1(), null); jContentPane.add(getJComboBox1(), null); jContentPane.add(getJButton1(), null); jContentPane.add(getJButton2(), null); jContentPane.add(jLabel1, null); jContentPane.add(jLabel2, null); jContentPane.add(jLabel3, null); jContentPane.add(getJPasswordField1(), null); jContentPane.add(jLabel4, null); } return jContentPane; } /** * This method initializes jTextField1 * * @return javax.swing.JTextField */ private JTextField getJTextField1() { if (jTextField1 == null) { jTextField1 = new JTextField(); jTextField1.setBounds(new Rectangle(111, 39, 174, 28)); jTextField1.setFont(new Font("", Font.PLAIN, 16)); jTextField1.setForeground(Color.magenta); } return jTextField1; } /** * This method initializes jComboBox1 * * @return javax.swing.JComboBox */ private JComboBox getJComboBox1() { if (jComboBox1 == null) { jComboBox1 = new JComboBox(); jComboBox1.setBounds(new Rectangle(111, 148, 147, 28)); jComboBox1.setForeground(Color.magenta); jComboBox1.addItem("顾客"); jComboBox1.addItem("采购员"); jComboBox1.addItem("销售员"); jComboBox1.addItem("总经理"); jComboBox1.addItem("系统管理员"); } return jComboBox1; } /** * This method initializes jButton1 * * @return javax.swing.JButton */ private JButton getJButton1() { if (jButton1 == null) { // ImageIcon buttonIcon = new ImageIcon("1.jpg", "a background of // button"); jButton1 = new JButton(); jButton1.setBounds(new Rectangle(47, 194, 98, 29)); jButton1.setText("登 录"); jButton1.addActionListener(this); } return jButton1; } public void actionPerformed(ActionEvent e) { Object source = e.getSource(); String account = jTextField1.getText(); String password = jPasswordField1.getText(); String type = (String) jComboBox1.getSelectedItem(); if (source == jButton1) { try { Class.forName("sun.jdbc.odbc.JdbcOdbcDriver"); } catch (ClassNotFoundException e1) { System.out.println("" + e1); } try { conn = DriverManager.getConnection("jdbc:odbc:supershop", "", ""); sql = conn.createStatement(); rs = sql.executeQuery("select * from oper where 用户帐号='" + account + "' and 用户密码='" + password + "' and 用户类型='" + type + "'"); boolean boo = false; if ((boo = rs.next()) == false) { n = n + 1; if (n < 3) { JOptionPane.showMessageDialog(null, "您的输入有误,请重新输入!", "信息提示", JOptionPane.WARNING_MESSAGE); jTextField1.setText(""); jPasswordField1.setText(""); } else { JOptionPane.showMessageDialog(null, "您已经登录失败三次,退出系统!", "信息提示", JOptionPane.WARNING_MESSAGE); System.exit(0); } } else { try { InputStream is = getClass() .getResource("sound//启动.wav").openStream(); AudioPlayer.player.start(is); } catch (IOException e2) { } userlevel = (String) jComboBox1.getSelectedItem(); if (mainframe1 == null) { mainframe1 = new mainframe(); mainframe1.show(); this.dispose(); } } } catch (SQLException ee) { } } else if (source == jButton2) { System.exit(0); } } /** * This method initializes jButton2 * * @return javax.swing.JButton */ private JButton getJButton2() { if (jButton2 == null) { jButton2 = new JButton(); jButton2.setBounds(new Rectangle(198, 194, 98, 29)); jButton2.setText("取 消"); jButton2.addActionListener(this); } return jButton2; } /** * This method initializes jPasswordField1 * * @return javax.swing.JPasswordField */ private JPasswordField getJPasswordField1() { if (jPasswordField1 == null) { jPasswordField1 = new JPasswordField(); jPasswordField1.setBounds(new Rectangle(111, 90, 174, 28)); jPasswordField1.setFont(new Font("", Font.PLAIN, 16)); jPasswordField1.setEchoChar('●'); jPasswordField1.setForeground(Color.magenta); } return jPasswordField1; } } // @jve:decl-index=0:visual-constraint="165,14"