1、 private Connection con = null; Statement stmt = null; private ResultSet r = null; private JLabel idlabel = new JLabel(ID ); private JTextField id = new JTextField(10); private JLabel pwdlabel = new JLabel(密码 private JPasswordField pwd = new JPasswordField(10); private JButton commit = new JButton(登
2、陆 private String command = null; public login() setTitle(能源管理系统 setSize(236, 248); addWindowListener(new WindowAdapter() public void windowClosing(WindowEvent e) System.exit(0); ); getContentPane().setLayout(new GridBagLayout(); JPanel jp1 = new JPanel(); GridBagConstraints gbc_jp1 = new GridBagCons
3、traints(); gbc_jp1.anchor = GridBagConstraints.SOUTHEAST; gbc_jp1.insets = new Insets(0, 0, 5, 0); gbc_jp1.gridx = 0; gbc_jp1.gridy = 0; getContentPane().add(jp1, gbc_jp1); jp1.add(idlabel); jp1.add(id); JPanel jp2 = new JPanel(); jp2.add(pwdlabel); jp2.add(pwd); JPanel jp9 = new JPanel(); jp9.setLa
4、yout(new GridLayout(3, 1); jp9.add(jp2); JPanel jp10 = new JPanel(); jp10.setLayout(new BorderLayout(); jp10.add(West, jp9); jp9.add(commit); commit.addActionListener(this); GridBagConstraints gbc_jp10 = new GridBagConstraints(); gbc_jp10.insets = new Insets(0, 0, 5, 0); gbc_jp10.gridx = 0; gbc_jp10
5、.gridy = 1; getContentPane().add(jp10, gbc_jp10); try String url = jdbc:sqlserver:/localhost:1433;databaseName=energy_management;integratedSecurity=true; Class.forName(com.microsoft.sqlserver.jdbc.SQLServerDriver System.out.println(驱动程序已装载即将连接数据库 con = DriverManager.getConnection(url, sa, 123456load
6、 ok stmt = con.createStatement(); catch (Exception ex) System.out.println(ex.getMessage(); public void actionPerformed(ActionEvent evt) String uid = id.getText().trim(); String upwd = pwd.getText(); String c1 = like + uid + String c2 = + upwd + command = select * + from manager_info where id + c1 +
7、and password + c2; r = stmt.executeQuery(command); if (uid.length() != 0 | upwd.length() != 0) if (r.next() JOptionPane.showMessageDialog(commit, 登陆成功提示, JOptionPane.INFORMATION_MESSAGE); mainFrame mf = new mainFrame(); mf.showf(); setVisible(false); else ID或者密码错误警告 JOptionPane.ERROR_MESSAGE); else
8、JOptionPane.showMessageDialog(commit, ID或者密码不能为空 JOptionPane.ERROR_MESSAGE); public static void main(String args) JFrame myframe = new login(); myframe.setVisible(true);操作界面源代码package mainmenu;import java.awt.Container;import java.awt.event.InputEvent;import java.awt.event.KeyEvent;import javax.swin
9、g.JMenu;import javax.swing.JMenuBar;import javax.swing.JMenuItem;import javax.swing.JToolBar;import javax.swing.KeyStroke;import consume_query.Queryconsume;import price_management.queryprice;import price_management.updateprice;import user_info_insert.insert_user_information;import user_info_insert.u
10、ser_info_delete;import user_record_insert.insert_user_record;import loginframe.login;public class mainFrame extends JFrame public mainFrame() public static final int h = 200; public static final int w = 370; JFrame mainframe; public void showf() mainframe = new JFrame(); mainframe.setTitle(管理员操作 mai
11、nframe.setSize(500, 130); mainframe.setResizable(true); meaushow(); showtool(); mainframe.show(); public void meaushow() JMenuBar meaubar = new JMenuBar(); JMenu file = new JMenu(文件 JMenuItem logout = new JMenuItem(注销, L JMenuItem exit = new JMenuItem(退出E JMenu help = new JMenu(帮助 JMenuItem about =
12、new JMenuItem(关于A logout.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_L, InputEvent.CTRL_MASK); exit.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_E, about.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_A, logout.addActionListener(new ActionListener() Override public void actionPerformed
13、(ActionEvent e) mainframe.setVisible(false); login myframe = new login(); myframe.setVisible(true); / TODO Auto-generated method stub exit.addActionListener(new ActionListener() / TODO Auto-generated method stub about.addActionListener(new ActionListener() JOptionPane.showMessageDialog(mainframe, 这是
14、一个能源管理收费系统, JOptionPane.INFORMATION_MESSAGE); ; meaubar.add(file); meaubar.add(help); file.add(logout); file.add(exit); help.add(about); mainframe.setJMenuBar(meaubar); public void showtool() JToolBar toolbar = new JToolBar(); JButton l1 = new JButton(用户信息录入 JButton l2 = new JButton(价格查询 JButton l3
15、= new JButton(价格更改 JButton l4 = new JButton(用户记录信息录入 JButton l5 = new JButton(收费查询 JButton l6 = new JButton(删除用户 toolbar.add(l1); toolbar.add(l2); toolbar.add(l3); toolbar.add(l4); toolbar.add(l5); toolbar.add(l6); Container contentpane = mainframe.getContentPane(); contentpane.add(toolbar); l1.addA
16、ctionListener(new ActionListener() JFrame myframe = new insert_user_information(); / TODO Auto-generated method stub l2.addActionListener(new ActionListener() JFrame myframe = new queryprice(); l3.addActionListener(new ActionListener() JFrame myframe = new updateprice(); l4.addActionListener(new Act
17、ionListener() JFrame myframe = new insert_user_record(); l5.addActionListener(new ActionListener() JFrame myframe = new Queryconsume(); l6.addActionListener(new ActionListener() JFrame mFrame=new user_info_delete(); mFrame.setVisible(true); / TODO Auto-generated method stub mainFrame mf = new mainFr
18、ame(); mf.showf();各个操作的源代码:(1)录入用户基本信息:package user_info_insert;import javax.swing.SwingConstants;public class insert_user_information extends JFrame implements ActionListener private JLabel Title = new JLabel(请输入新用户的信息, SwingConstants.CENTER);用户ID private JTextField id = new JTextField(15); private
19、 JLabel namelabel = new JLabel(姓名 private JTextField name = new JTextField(15); private JLabel sexlabel = new JLabel(性别 private JTextField sex = new JTextField(15); private JLabel addresslabel = new JLabel(家庭地址 private JTextField address = new JTextField(15); private JLabel telephonelabel = new JLab
20、el(电话 private JTextField telephone = new JTextField(15); private JLabel workplacelabel = new JLabel(工作地点 private JTextField workplace = new JTextField(15); private JLabel departmentlabel = new JLabel(部门 private JTextField department = new JTextField(15); private JLabel remarklabel = new JLabel(备注 private JTextField remark = new JTextField(15);提交 public insert_user_information() 用户
copyright@ 2008-2022 冰豆网网站版权所有
经营许可证编号:鄂ICP备2022015515号-1