能源管理系统-源代码

整理文档很辛苦,赏杯茶钱您下走!

免费阅读已结束,点击下载阅读编辑剩下 ...

阅读已结束,您可以下载文档离线阅读编辑

资源描述

登陆界面的源代码packageloginframe;importjava.awt.BorderLayout;importjava.awt.GridBagLayout;importjava.awt.GridLayout;importjava.awt.event.ActionEvent;importjava.awt.event.ActionListener;importjava.awt.event.WindowAdapter;importjava.awt.event.WindowEvent;importjava.sql.Statement;importjava.sql.Connection;importjava.sql.DriverManager;importjava.sql.ResultSet;importjavax.swing.JButton;importjavax.swing.JFrame;importjavax.swing.JLabel;importjavax.swing.JOptionPane;importjavax.swing.JPanel;importjavax.swing.JTextField;importjava.awt.GridBagConstraints;importjava.awt.Insets;importjavax.swing.JPasswordField;importmainmenu.mainFrame;publicclassloginextendsJFrameimplementsActionListener{/****/privatestaticfinallongserialVersionUID=1L;privateConnectioncon=null;Statementstmt=null;privateResultSetr=null;privateJLabelidlabel=newJLabel(ID);privateJTextFieldid=newJTextField(10);privateJLabelpwdlabel=newJLabel(密码);privateJPasswordFieldpwd=newJPasswordField(10);privateJButtoncommit=newJButton(登陆);privateStringcommand=null;publiclogin(){setTitle(能源管理系统);setSize(236,248);addWindowListener(newWindowAdapter(){publicvoidwindowClosing(WindowEvente){System.exit(0);}});getContentPane().setLayout(newGridBagLayout());JPaneljp1=newJPanel();GridBagConstraintsgbc_jp1=newGridBagConstraints();gbc_jp1.anchor=GridBagConstraints.SOUTHEAST;gbc_jp1.insets=newInsets(0,0,5,0);gbc_jp1.gridx=0;gbc_jp1.gridy=0;getContentPane().add(jp1,gbc_jp1);jp1.add(idlabel);jp1.add(id);JPaneljp2=newJPanel();jp2.add(pwdlabel);jp2.add(pwd);JPaneljp9=newJPanel();jp9.setLayout(newGridLayout(3,1));jp9.add(jp2);JPaneljp10=newJPanel();jp10.setLayout(newBorderLayout());jp10.add(West,jp9);jp9.add(commit);commit.addActionListener(this);GridBagConstraintsgbc_jp10=newGridBagConstraints();gbc_jp10.insets=newInsets(0,0,5,0);gbc_jp10.gridx=0;gbc_jp10.gridy=1;getContentPane().add(jp10,gbc_jp10);try{Stringurl=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(loadok);stmt=con.createStatement();}catch(Exceptionex){System.out.println(ex.getMessage());}}publicvoidactionPerformed(ActionEventevt){try{Stringuid=id.getText().trim();Stringupwd=pwd.getText();Stringc1=like'+uid+';Stringc2=like'+upwd+';command=select*+frommanager_info+whereid+c1+andpassword+c2;r=stmt.executeQuery(command);if(uid.length()!=0||upwd.length()!=0){if(r.next()){JOptionPane.showMessageDialog(commit,登陆成功,提示,JOptionPane.INFORMATION_MESSAGE);mainFramemf=newmainFrame();mf.showf();setVisible(false);}else{JOptionPane.showMessageDialog(commit,ID或者密码错误,警告,JOptionPane.ERROR_MESSAGE);}}else{JOptionPane.showMessageDialog(commit,ID或者密码不能为空,警告,JOptionPane.ERROR_MESSAGE);}}catch(Exceptionex){System.out.println(ex.getMessage());}}publicstaticvoidmain(Stringargs[]){JFramemyframe=newlogin();myframe.setVisible(true);}}操作界面源代码packagemainmenu;importjava.awt.Container;importjava.awt.event.ActionEvent;importjava.awt.event.ActionListener;importjava.awt.event.InputEvent;importjava.awt.event.KeyEvent;importjavax.swing.JButton;importjavax.swing.JFrame;importjavax.swing.JMenu;importjavax.swing.JMenuBar;importjavax.swing.JMenuItem;importjavax.swing.JOptionPane;importjavax.swing.JToolBar;importjavax.swing.KeyStroke;importconsume_query.Queryconsume;importprice_management.queryprice;importprice_management.updateprice;importuser_info_insert.insert_user_information;importuser_info_insert.user_info_delete;importuser_record_insert.insert_user_record;importloginframe.login;publicclassmainFrameextendsJFrame{publicmainFrame(){}/****/privatestaticfinallongserialVersionUID=1L;publicstaticfinalinth=200;publicstaticfinalintw=370;JFramemainframe;publicvoidshowf(){mainframe=newJFrame();mainframe.setTitle(管理员操作);mainframe.setSize(500,130);mainframe.setResizable(true);meaushow();showtool();mainframe.show();}publicvoidmeaushow(){JMenuBarmeaubar=newJMenuBar();JMenufile=newJMenu(文件);JMenuItemlogout=newJMenuItem(注销,'L');JMenuItemexit=newJMenuItem(退出,'E');JMenuhelp=newJMenu(帮助);JMenuItemabout=newJMenuItem(关于,'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(newActionListener(){@OverridepublicvoidactionPerformed(ActionEvente){mainframe.setVisible(false);loginmyframe=newlogin();myframe.setVisible(true);}//TODOAuto-generatedmethodstub});exit.addActionListener(newActionListener(){@OverridepublicvoidactionPerformed(ActionEvente){System.exit(0);//TODOAuto-generatedmethodstub}});about.addActionListener(newActionListener(){@OverridepublicvoidactionPerformed(ActionEvente){JOptionPane.showMessageDialog(mainframe,这是一个能源管理收费系统,关于,JOptionPane.INFORMATION_MESSAGE);};});meaubar.add(file);meaubar.add(help);file.add(logout);file.add(exit);help.add(about);

1 / 25
下载文档,编辑使用

©2015-2020 m.777doc.com 三七文档.

备案号:鲁ICP备2024069028号-1 客服联系 QQ:2149211541

×
保存成功