能源管理系统-源代码.docx

上传人:豆**** 文档编号:28556440 上传时间:2022-07-28 格式:DOCX 页数:20 大小:18.48KB
返回 下载 相关 举报
能源管理系统-源代码.docx_第1页
第1页 / 共20页
能源管理系统-源代码.docx_第2页
第2页 / 共20页
点击查看更多>>
资源描述

《能源管理系统-源代码.docx》由会员分享,可在线阅读,更多相关《能源管理系统-源代码.docx(20页珍藏版)》请在taowenge.com淘文阁网|工程机械CAD图纸|机械工程制图|CAD装配图下载|SolidWorks_CaTia_CAD_UG_PROE_设计图分享下载上搜索。

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.Statem

2、ent;import java.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.

3、awt.Insets;import 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 );p

4、rivate 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() publi

5、c 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_jp1.gridy = 0;

6、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, jp9);jp9.add(commit);commit.a

7、ddActionListener(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_management;integratedSecurity=true;Cla

8、ss.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.println(ex.getMessage();public void actionPerf

9、ormed(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 (uid.length() != 0 | upwd.length() != 0) if (r.nex

10、t() JOptionPane.showMessageDialog(commit, 登陆成功, 提示,JOptionPane.INFORMATION_MESSAGE);mainFrame mf = new mainFrame();mf.showf();setVisible(false); else JOptionPane.showMessageDialog(commit, ID或者密码错误, 警告,JOptionPane.ERROR_MESSAGE); else JOptionPane.showMessageDialog(commit, ID或者密码不能为空, 警告,JOptionPane.E

11、RROR_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.ActionEvent;import java.awt.event.ActionListener;import java.awt.e

12、vent.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;import javax.swing.KeyStroke;import consume_query.Querycons

13、ume;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 class mainFrame extends JFrame public mainFrame() private st

14、atic 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.setResizable(true);meaushow();showtool();mainframe.show();public void me

15、aushow() 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);logout.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_L,InputEvent.CTRL_MASK);exit.

16、setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_E,InputEvent.CTRL_MASK);about.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_A,InputEvent.CTRL_MASK);logout.addActionListener(new ActionListener() Overridepublic void actionPerformed(ActionEvent e) mainframe.setVisible(false);login myframe = new l

17、ogin();myframe.setVisible(true);/ TODO Auto-generated method stubexit.addActionListener(new ActionListener() Overridepublic void actionPerformed(ActionEvent e) System.exit(0);/ TODO Auto-generated method stubabout.addActionListener(new ActionListener() Overridepublic void actionPerformed(ActionEvent

18、 e) JOptionPane.showMessageDialog(mainframe, 这是一个能源管理收费系统,关于,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(用户信息录入);J

19、Button l2 = new JButton(价格查询);JButton l3 = 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.getContentPa

20、ne();contentpane.add(toolbar);l1.addActionListener(new ActionListener() Overridepublic void actionPerformed(ActionEvent e) JFrame myframe = new insert_user_information();myframe.setVisible(true);/ TODO Auto-generated method stubl2.addActionListener(new ActionListener() Overridepublic void actionPerf

21、ormed(ActionEvent e) JFrame myframe = new queryprice();myframe.setVisible(true);/ TODO Auto-generated method stubl3.addActionListener(new ActionListener() Overridepublic void actionPerformed(ActionEvent e) JFrame myframe = new updateprice();myframe.setVisible(true);/ TODO Auto-generated method stubl

22、4.addActionListener(new ActionListener() Overridepublic void actionPerformed(ActionEvent e) JFrame myframe = new insert_user_record();myframe.setVisible(true);/ TODO Auto-generated method stubl5.addActionListener(new ActionListener() Overridepublic void actionPerformed(ActionEvent e) JFrame myframe

23、= new Queryconsume();myframe.setVisible(true);/ TODO Auto-generated method stubl6.addActionListener(new ActionListener() Overridepublic void actionPerformed(ActionEvent e) JFrame mFrame=new user_info_delete();mFrame.setVisible(true);/ TODO Auto-generated method stubpublic static void main(String arg

24、s) mainFrame mf = new mainFrame();mf.showf();各个操作的源代码:(1)录入用户基本信息:package user_info_insert;import java.awt.BorderLayout;import 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

25、;import java.sql.DriverManager;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 javax.swing.SwingConstants;public class insert_user_information extends JFrame implements Action

26、Listener private static final long serialVersionUID = 1L;private Connection con = null;Statement stmt = null;private JLabel Title = new JLabel(请输入新用户的信息, SwingConstants.CENTER);private JLabel idlabel = new JLabel(用户ID );private JTextField id = new JTextField(15);private JLabel namelabel = new JLabel

27、(姓名 );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 JLabel(电话 );private JTextField t

28、elephone = 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

29、= new JTextField(15);private JButton commit = new JButton(提交);public insert_user_information() setTitle(用户信息录入);setSize(400, 400);getContentPane().setLayout(new GridBagLayout();JPanel jp1 = new JPanel();jp1.add(idlabel);jp1.add(id);JPanel jp2 = new JPanel();jp2.add(namelabel);jp2.add(name);JPanel jp

30、3 = new JPanel();jp3.add(sexlabel);jp3.add(sex);JPanel jp4 = new JPanel();jp4.add(addresslabel);jp4.add(address);JPanel jp5 = new JPanel();jp5.add(telephonelabel);jp5.add(telephone);JPanel jp6 = new JPanel();jp6.add(workplacelabel);jp6.add(workplace);JPanel jp7 = new JPanel();jp7.add(departmentlabel

31、);jp7.add(department);JPanel jp8 = new JPanel();jp8.add(remarklabel);jp8.add(remark);JPanel jp9 = new JPanel();jp9.setLayout(new GridLayout(9, 1);jp9.add(Title);jp9.add(jp1);jp9.add(jp2);jp9.add(jp3);jp9.add(jp4);jp9.add(jp5);jp9.add(jp6);jp9.add(jp7);jp9.add(jp8);JPanel jp10 = new JPanel();jp10.set

32、Layout(new BorderLayout();jp10.add(Center, jp9);add(jp10);add(commit);commit.addActionListener(this);try String url = jdbc:sqlserver:/localhost:1433;databaseName=energy_management;integratedSecurity=true;Class.forName(com.microsoft.sqlserver.jdbc.SQLServerDriver);System.out.println(驱动程序已装载);System.o

33、ut.println(即将连接数据库);con = DriverManager.getConnection(url, sa, 123456);System.out.println(load ok);stmt = con.createStatement(); catch (Exception ex) System.out.println(ex.getMessage();public void actionPerformed(ActionEvent evt) String uid = id.getText().trim();String uname = name.getText().trim();

34、String usex = sex.getText().trim();String uadd = address.getText().trim();String utele = telephone.getText().trim();String uwork = workplace.getText().trim();String udepart = department.getText().trim();String ure = remark.getText().trim();String command = insert into user_info values( + uid + , + u

35、name+ , + usex + , + uadd + , + utele + , + uwork+ , + udepart + , + ure + );if (uid.length() != 0) try stmt.executeUpdate(command);JOptionPane.showMessageDialog(commit, 录入成功!, 提示,JOptionPane.INFORMATION_MESSAGE);stmt.close(); catch (Exception ex) System.out.println(ex.getMessage();JOptionPane.showM

36、essageDialog(commit, 输入错误, 警告,JOptionPane.ERROR_MESSAGE); else JOptionPane.showMessageDialog(commit, ID不能为空, 警告,JOptionPane.ERROR_MESSAGE);public static void main(String args) JFrame myframe = new insert_user_information();myframe.setVisible(true);(2)删除用户信息package user_info_insert;import java.awt.Bo

37、rderLayout;import java.awt.event.ActionEvent;import java.awt.event.ActionListener;import java.sql.Connection;import java.sql.DriverManager;import java.sql.Statement;import javax.swing.JButton;import javax.swing.JFrame;import javax.swing.JLabel;import javax.swing.JOptionPane;import javax.swing.JPanel

38、;import javax.swing.JTextField;public class user_info_delete extends JFrame implements ActionListener private static final long serialVersionUID = 1L;private Connection connection = null;private Statement state = null;private JLabel title = new JLabel(请输入删除用户的ID);private JLabel idlabel = new JLabel(

39、ID);private JTextField id = new JTextField(15);private JButton b = new JButton(提交);public user_info_delete() setTitle(删除用户信息);setSize(400, 400);JPanel j1 = new JPanel();j1.add(idlabel);j1.add(id);JPanel j2 = new JPanel();j2.setLayout(new BorderLayout();j2.add(North, title);j2.add(Center, j1);j2.add(

40、East, b);add(j2);pack();b.addActionListener(this);try String url = jdbc:sqlserver:/localhost:1433;databaseName=energy_management;integratedSecurity=true;Class.forName(com.microsoft.sqlserver.jdbc.SQLServerDriver);System.out.println(驱动程序已装载);System.out.println(即将连接数据库);connection = DriverManager.getC

41、onnection(url, sa, 123456);System.out.println(load ok);state = connection.createStatement(); catch (Exception ex) System.out.println(ex.getMessage();public void actionPerformed(ActionEvent evt) String uid = id.getText().trim();String command = delete from user_info where user_id= + uid+;if (uid.leng

42、th() != 0) try state.executeUpdate(command);JOptionPane.showMessageDialog(b, 删除成功!, 提示,JOptionPane.INFORMATION_MESSAGE); catch (Exception e) System.out.println(e.getMessage();JOptionPane.showMessageDialog(b, 输入错误, 警告,JOptionPane.ERROR_MESSAGE);/ TODO: handle exception else JOptionPane.showMessageDia

43、log(b, ID不能为空, 警告,JOptionPane.ERROR_MESSAGE);public static void main(String args) JFrame myframe = new user_info_delete();myframe.setVisible(true);价格查询:package price_management;import java.awt.BorderLayout;import java.awt.GridBagLayout;import java.awt.event.ActionEvent;import java.awt.event.ActionListener;import java.awt.event.WindowA

展开阅读全文
相关资源
相关搜索

当前位置:首页 > 教育专区 > 小学资料

本站为文档C TO C交易模式,本站只提供存储空间、用户上传的文档直接被用户下载,本站只是中间服务平台,本站所有文档下载所得的收益归上传人(含作者)所有。本站仅对用户上传内容的表现方式做保护处理,对上载内容本身不做任何修改或编辑。若文档所含内容侵犯了您的版权或隐私,请立即通知淘文阁网,我们立即给予删除!客服QQ:136780468 微信:18945177775 电话:18904686070

工信部备案号:黑ICP备15003705号© 2020-2023 www.taowenge.com 淘文阁