1、能源管理系统源代码登陆界面的源代码package loginframe;import java.awt.BorderLayout;import java.awt.GridBagLayout;import java.awt.GridLayout;import java.awt.event.ActionEvent;import java.awt.event.ActionListener;import java.awt.event.WindowAdapter;import java.awt.event.WindowEvent;import java.sql.Statement;import java
2、.sql.Connection;import java.sql.DriverManager;import java.sql.ResultSet;import javax.swing.JButton;import javax.swing.JFrame;import javax.swing.JLabel;import javax.swing.JOptionPane;import javax.swing.JPanel;import javax.swing.JTextField;import java.awt.GridBagConstraints;import java.awt.Insets;impo
3、rt javax.swing.JPasswordField;import mainmenu.mainFrame;public class login extends JFrame implements ActionListener /* * */ private static final long serialVersionUID = 1L; private Connection con = null; Statement stmt = null; private ResultSet r = null; private JLabel idlabel = new JLabel(ID ); pri
4、vate JTextField id = new JTextField(10); private JLabel pwdlabel = new JLabel(密码 ); private JPasswordField pwd = new JPasswordField(10); private JButton commit = new JButton(登陆); private String command = null; public login() setTitle(能源管理系统); setSize(236, 248); addWindowListener(new WindowAdapter()
5、public void windowClosing(WindowEvent e) System.exit(0); ); getContentPane().setLayout(new GridBagLayout(); JPanel jp1 = new JPanel(); GridBagConstraints gbc_jp1 = new GridBagConstraints(); gbc_jp1.anchor = GridBagConstraints.SOUTHEAST; gbc_jp1.insets = new Insets(0, 0, 5, 0); gbc_jp1.gridx = 0; gbc
6、_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.setLayout(new GridLayout(3, 1); jp9.add(jp2); JPanel jp10 = new JPanel(); jp10.setLayout(new BorderLayout(); jp10.add(West, jp
7、9); 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.gridy = 1; getContentPane().add(jp10, gbc_jp10); try String url = jdbc:sqlserver:/localhost:1433;databaseName=energy_man
8、agement;integratedSecurity=true; Class.forName(com.microsoft.sqlserver.jdbc.SQLServerDriver); System.out.println(驱动程序已装载); System.out.println(即将连接数据库); con = DriverManager.getConnection(url, sa, 123456); System.out.println(load ok); stmt = con.createStatement(); catch (Exception ex) System.out.print
9、ln(ex.getMessage(); public void actionPerformed(ActionEvent evt) try String uid = id.getText().trim(); String upwd = pwd.getText(); String c1 = like + uid + ; String c2 = like + upwd + ; command = select * + from manager_info + where id + c1 + and password + c2; r = stmt.executeQuery(command); if (u
10、id.length() != 0 | upwd.length() != 0) if (r.next() JOptionPane.showMessageDialog(commit, 登陆成功, 提示, JOptionPane.INFORMATION_MESSAGE); mainFrame mf = new mainFrame(); mf.showf(); setVisible(false); else JOptionPane.showMessageDialog(commit, ID或者密码错误, 警告, JOptionPane.ERROR_MESSAGE); else JOptionPane.s
11、howMessageDialog(commit, ID或者密码不能为空, 警告, JOptionPane.ERROR_MESSAGE); catch (Exception ex) System.out.println(ex.getMessage(); public static void main(String args) JFrame myframe = new login(); myframe.setVisible(true); 操作界面源代码package mainmenu;import java.awt.Container;import java.awt.event.ActionEve
12、nt;import java.awt.event.ActionListener;import java.awt.event.InputEvent;import java.awt.event.KeyEvent;import javax.swing.JButton;import javax.swing.JFrame;import javax.swing.JMenu;import javax.swing.JMenuBar;import javax.swing.JMenuItem;import javax.swing.JOptionPane;import javax.swing.JToolBar;im
13、port 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.user_info_delete;import user_record_insert.insert_user_record;import loginframe.login;public cla
14、ss mainFrame extends JFrame public mainFrame() /* * */ private static final long serialVersionUID = 1L; public static final int h = 200; public static final int w = 370; JFrame mainframe; public void showf() mainframe = new JFrame(); mainframe.setTitle(管理员操作); mainframe.setSize(500, 130); mainframe.
15、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 = new JMenuItem(关于, A); logo
16、ut.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_L, InputEvent.CTRL_MASK); exit.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_E, InputEvent.CTRL_MASK); about.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_A, InputEvent.CTRL_MASK); logout.addActionListener(new ActionListener() Override pub
17、lic void actionPerformed(ActionEvent e) mainframe.setVisible(false); login myframe = new login(); myframe.setVisible(true); / TODO Auto-generated method stub ); exit.addActionListener(new ActionListener() Override public void actionPerformed(ActionEvent e) System.exit(0);/ TODO Auto-generated method
18、 stub ); about.addActionListener(new ActionListener() Override public void actionPerformed(ActionEvent e) JOptionPane.showMessageDialog(mainframe, 这是一个能源管理收费系统,关于, JOptionPane.INFORMATION_MESSAGE); ; ); meaubar.add(file); meaubar.add(help); file.add(logout); file.add(exit); help.add(about); mainfram
19、e.setJMenuBar(meaubar); public void showtool() JToolBar toolbar = new JToolBar(); JButton l1 = new JButton(用户信息录入); JButton l2 = new JButton(价格查询); JButton l3 = new JButton(价格更改); JButton l4 = new JButton(用户记录信息录入); JButton l5 = new JButton(收费查询); JButton l6 = new JButton(删除用户); toolbar.add(l1); too
20、lbar.add(l2); toolbar.add(l3); toolbar.add(l4); toolbar.add(l5); toolbar.add(l6); Container contentpane = mainframe.getContentPane(); contentpane.add(toolbar); l1.addActionListener(new ActionListener() Override public void actionPerformed(ActionEvent e) JFrame myframe = new insert_user_information()
21、; myframe.setVisible(true); / TODO Auto-generated method stub ); l2.addActionListener(new ActionListener() Override public void actionPerformed(ActionEvent e) JFrame myframe = new queryprice(); myframe.setVisible(true); / TODO Auto-generated method stub ); l3.addActionListener(new ActionListener() O
22、verride public void actionPerformed(ActionEvent e) JFrame myframe = new updateprice(); myframe.setVisible(true); / TODO Auto-generated method stub ); l4.addActionListener(new ActionListener() Override public void actionPerformed(ActionEvent e) JFrame myframe = new insert_user_record(); myframe.setVi
23、sible(true); / TODO Auto-generated method stub ); l5.addActionListener(new ActionListener() Override public void actionPerformed(ActionEvent e) JFrame myframe = new Queryconsume(); myframe.setVisible(true); / TODO Auto-generated method stub ); l6.addActionListener(new ActionListener() Override publi
24、c void actionPerformed(ActionEvent e) JFrame mFrame=new user_info_delete(); mFrame.setVisible(true); / TODO Auto-generated method stub ); public static void main(String args) mainFrame mf = new mainFrame(); mf.showf(); 各个操作的源代码:(1)录入用户基本信息:package user_info_insert;import java.awt.BorderLayout;import
25、 java.awt.GridBagLayout;import java.awt.GridLayout;import java.awt.event.ActionEvent;import java.awt.event.ActionListener;import java.sql.Statement;import java.sql.Connection;import java.sql.DriverManager;import javax.swing.JButton;import javax.swing.JFrame;import javax.swing.JLabel;import javax.swi
26、ng.JOptionPane;import javax.swing.JPanel;import javax.swing.JTextField;import javax.swing.SwingConstants;public class insert_user_information extends JFrame implements ActionListener /* * */ private static final long serialVersionUID = 1L; private Connection con = null; Statement stmt = null; privat
27、e JLabel Title = new JLabel(请输入新用户的信息, SwingConstants.CENTER); private JLabel idlabel = new JLabel(用户ID ); private JTextField id = new JTextField(15); private JLabel namelabel = new JLabel(姓名 ); private JTextField name = new JTextField(15); private JLabel sexlabel = new JLabel(性别 ); private JTextFie
28、ld sex = new JTextField(15); private JLabel addresslabel = new JLabel(家庭地址); private JTextField address = new JTextField(15); private JLabel telephonelabel = new JLabel(电话 ); private JTextField telephone = new JTextField(15); private JLabel workplacelabel = new JLabel(工作地点); private JTextField workp
29、lace = 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); private JButton commit = new JButton(提交); public insert_user_information() setTitle(用户
copyright@ 2008-2022 冰豆网网站版权所有
经营许可证编号:鄂ICP备2022015515号-1