您好,欢迎访问三七文档
当前位置:首页 > 商业/管理/HR > 绩效管理 > java登陆系统——用oracle数据库实现
importjava.awt.BorderLayout;importjava.awt.Color;importjava.awt.Component;importjava.awt.Dimension;importjava.awt.Font;importjava.awt.Graphics;importjava.awt.GridBagConstraints;importjava.awt.GridBagLayout;importjava.awt.Insets;importjava.awt.Toolkit;importjava.awt.event.ActionEvent;importjava.awt.event.ActionListener;importjava.sql.Connection;importjava.sql.DriverManager;importjava.sql.PreparedStatement;importjava.sql.ResultSet;importjava.sql.SQLException;importjava.sql.Statement;importjavax.swing.BorderFactory;importjavax.swing.Icon;importjavax.swing.ImageIcon;importjavax.swing.JButton;importjavax.swing.JFrame;importjavax.swing.JLabel;importjavax.swing.JOptionPane;importjavax.swing.JPanel;importjavax.swing.JPasswordField;importjavax.swing.JTextField;importjavax.swing.text.AttributeSet;importjavax.swing.text.BadLocationException;importjavax.swing.text.PlainDocument;publicclassloggins{//数据库连接publicstaticfinalStringDBDRIVER=oracle.jdbc.driver.OracleDriver;publicstaticfinalStringDBURL=jdbc:oracle:thin:@127.0.0.1:1521:orcl;publicstaticfinalStringDBUSER=system;publicstaticfinalStringDBPASS=download;staticPreparedStatementpst=null;staticConnectionconn=null;staticStatementst=null;staticStatementst1=null;privatestaticfinallongserialVersionUID=4989865601776167372L;staticfinalintWIDTH=400;//顶层框架宽度staticfinalintHEIGHT=350;//顶层框架高度JFrameloginframe;/*publicvoidadd(Componentc,GridBagConstraintsconstraints,intx,inty,intw,inth){constraints.gridx=x;constraints.gridy=y;constraints.gridwidth=w;constraints.gridheight=h;add(c,constraints);}*///finalConnectJDBCjdbc=newConnectJDBC();publicloggins(){try{//数据库连接Class.forName(DBDRIVER);conn=DriverManager.getConnection(DBURL,DBUSER,DBPASS);//conn.close();}catch(Exceptione){e.printStackTrace();}//设置框架基本信息loginframe=newJFrame(乐豆通讯簿系统);loginframe.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);loginframe.setSize(WIDTH,HEIGHT);//下面这段设置背景图片JPanelpanel=newJPanel(){publicvoidpaintComponent(Graphicsg){super.paintComponent(g);ImageIconimg=newImageIcon(photo/1.jpg);g.drawImage(img.getImage(),0,0,600,this.getHeight(),null);}};panel.setPreferredSize(newDimension(400,350));//设置窗口居中Toolkitkit=Toolkit.getDefaultToolkit();DimensionscreenSize=kit.getScreenSize();intwidth=screenSize.width;intheight=screenSize.height;intx=(width-WIDTH)/2;inty=(height-HEIGHT)/2;loginframe.setLocation(x,y);//下面这段设置背景图片/*JLabellabelback=newJLabel();Iconicon=newImageIcon(photo/5.jpg);labelback.setIcon(icon);labelback.setBounds(0,0,icon.getIconWidth(),icon.getIconHeight());this.add(labelback,newInteger(Integer.MIN_VALUE));*///设置按钮字体及背景Fontfont=newFont(宋体,Font.BOLD,20);ImageIconicon=newImageIcon(photo/ok.gif);ImageIconicon1=newImageIcon(photo/okno.gif);JButtonok=newJButton(登陆);ok.setIcon(icon);ok.setBorder(null);ok.setForeground(Color.white);ok.setPreferredSize(newDimension(100,28));JButtoncancle=newJButton(退出);cancle.setIcon(icon1);cancle.setBorder(null);cancle.setPreferredSize(newDimension(100,28));JLabeltitle=newJLabel(htmlcolor=green请输入以下信息/color/html,JLabel.CENTER);title.setFont(font);title.setForeground(Color.red);JLabelname=newJLabel(用户名:);JLabelpassword=newJLabel(密码:);finalJTextFieldnameinput=newJTextField(newTextFiledDocument(10),,20);nameinput.setBorder(BorderFactory.createLoweredBevelBorder());finalJPasswordFieldpassinput=newJPasswordField(newTextFiledDocument(8),,20);passinput.setBorder(BorderFactory.createLoweredBevelBorder());//设置布局管理器GridBagLayoutlay=newGridBagLayout();panel.setLayout(lay);loginframe.add(panel,BorderLayout.WEST);GridBagConstraintsconstraints=newGridBagConstraints();constraints.fill=GridBagConstraints.HORIZONTAL;constraints.anchor=GridBagConstraints.WEST;constraints.insets=newInsets(10,0,8,10);constraints.weightx=0;constraints.weighty=0;//组件排列constraints.gridx=2;constraints.gridy=0;constraints.gridwidth=3;panel.add(title,constraints);constraints.gridx=1;constraints.gridy=1;constraints.gridwidth=1;constraints.ipady=0;panel.add(name,constraints);constraints.gridx=1;constraints.gridy=2;constraints.gridwidth=1;constraints.ipady=0;panel.add(password,constraints);constraints.gridx=2;constraints.gridy=1;constraints.gridwidth=7;constraints.ipady=0;panel.add(nameinput,constraints);constraints.gridx=2;constraints.gridy=2;constraints.gridwidth=7;constraints.ipady=0;panel.add(passinput,constraints);constraints.gridx=2;constraints.gridy=3;constraints.gridwidth=1;constraints.ipadx=3;panel.add(ok,constraints);constraints.gridx=6;constraints.gridy=3;constraints.gridwidth=1;panel.add(cancle,constraints);loginframe.setVisible(true);ok.addActionListener(newActionListener(){publicvoidactionPerformed(ActionEvente){Stringnametext=nameinput.getText().trim();char[]passtext=passinput.getPassword();Stringstr=newString(passtext);ResultSetrs=null;try{st=conn.createStatement();rs=st.executeQuery(selectname,passwordfromACOM_USERLOGINwherepassword='+str+');}catch(SQLExceptione3){e3.printStackTrace();}//if((nametext.length()==0)||(passtext.length==0))if(nametext.equals()||passtext.equals()){JOptionPane.showMessageDial
本文标题:java登陆系统——用oracle数据库实现
链接地址:https://www.777doc.com/doc-6204103 .html