收藏 分销(赏)

能源管理系统-源代码教学内容.docx

上传人:丰**** 文档编号:3864303 上传时间:2024-07-22 格式:DOCX 页数:27 大小:21.03KB 下载积分:10 金币
下载 相关 举报
能源管理系统-源代码教学内容.docx_第1页
第1页 / 共27页
能源管理系统-源代码教学内容.docx_第2页
第2页 / 共27页


点击查看更多>>
资源描述
能源管理系统-源代码 精品文档 登陆界面的源代码 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.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; 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 "); private 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() { 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_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", 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.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("驱动程序已装载"); 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 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 (uid.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.showMessageDialog(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.ActionEvent; 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; 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.user_info_delete; import user_record_insert.insert_user_record; import loginframe.login; public class 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.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'); logout.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 public 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 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); mainframe.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); toolbar.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(); 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() { @Override 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.setVisible(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 public 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 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.swing.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; private 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 JTextField 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 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); 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 jp3 = 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); 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.setLayout(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.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 actionPerformed(ActionEvent evt) { String uid = id.getText().trim(); String uname = name.getText().trim(); 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 + "','" + uname + "','" + 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.showMessageDialog(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.BorderLayout; 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; 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("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("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.getConnection(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.length() != 0) { try { state.executeUpdate(command); JOptionPane.showMessageDialog(b, "删除成功!", "提示", JOptionPane.INFORMATION_MESSAGE); } catch (Exception e) { System.out.println(e.getMessage()); JOptionPane.showMessage
展开阅读全文

开通  VIP会员、SVIP会员  优惠大
下载10份以上建议开通VIP会员
下载20份以上建议开通SVIP会员


开通VIP      成为共赢上传

当前位置:首页 > 教育专区 > 其他

移动网页_全站_页脚广告1

关于我们      便捷服务       自信AI       AI导航        抽奖活动

©2010-2026 宁波自信网络信息技术有限公司  版权所有

客服电话:0574-28810668  投诉电话:18658249818

gongan.png浙公网安备33021202000488号   

icp.png浙ICP备2021020529号-1  |  浙B2-20240490  

关注我们 :微信公众号    抖音    微博    LOFTER 

客服