?? mainframe.java~30~
字號:
package login;
import java.awt.*;
import java.awt.event.*;
import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.JMenuBar;
import javax.swing.JMenu;
import javax.swing.JMenuItem;
import javax.swing.JLabel;
import java.awt.BorderLayout;
import java.awt.Rectangle;
import javax.swing.BorderFactory;
import javax.swing.JTextField;
import javax.swing.JPasswordField;
import javax.swing.JButton;
import java.sql.*;
import java.io.File;
/**
* <p>Title: </p>
*
* <p>Description: </p>
*
* <p>Copyright: Copyright (c) 2007</p>
*
* <p>Company: </p>
*
* @author not attributable
* @version 1.0
*/
public class MainFrame extends JFrame {
String url="jdbc:odbc:Driver={MicroSoft Access Driver (*.mdb)};DBQ=E:/java/JBuilder/Telent/Login/src/login/user.mdb";
JPanel contentPane;
JMenuBar jMenuBar1 = new JMenuBar();
JMenu jMenuFile = new JMenu();
JMenuItem jMenuFileExit = new JMenuItem();
JMenu jMenuHelp = new JMenu();
JMenuItem jMenuHelpAbout = new JMenuItem();
JLabel jLabel1 = new JLabel();
JLabel jLabel2 = new JLabel();
JTextField jTextField1 = new JTextField();
JPasswordField jPasswordField1 = new JPasswordField();
JButton jButton1 = new JButton();
JButton jButton2 = new JButton();
public MainFrame() {
try {
setDefaultCloseOperation(EXIT_ON_CLOSE);
jbInit();
} catch (Exception exception) {
exception.printStackTrace();
}
}
/**
* Component initialization.
*
* @throws java.lang.Exception
*/
private void jbInit() throws Exception {
contentPane = (JPanel) getContentPane();
contentPane.setLayout(null);
setSize(new Dimension(240, 230));
setTitle("Frame Title");
jMenuFile.setText("File");
jMenuFileExit.setText("Exit");
jMenuFileExit.addActionListener(new
MainFrame_jMenuFileExit_ActionAdapter(this));
jMenuHelp.setText("Help");
jMenuHelpAbout.setText("About");
jMenuHelpAbout.addActionListener(new
MainFrame_jMenuHelpAbout_ActionAdapter(this));
jLabel1.setBorder(null);
jLabel1.setText("姓名:");
jLabel1.setBounds(new Rectangle(16, 17, 54, 30));
jLabel2.setBorder(null);
jLabel2.setText("密碼:");
jLabel2.setBounds(new Rectangle(17, 68, 54, 29));
jTextField1.setBounds(new Rectangle(81, 18, 119, 29));
jPasswordField1.setBounds(new Rectangle(81, 68, 119, 28));
jButton1.setBounds(new Rectangle(17, 124, 86, 28));
jButton1.setText("注冊");
jButton2.setBounds(new Rectangle(127, 124, 85, 27));
jButton2.setText("登陸");
jButton2.addActionListener(new MainFrame_jButton2_actionAdapter(this));
jMenuBar1.add(jMenuFile);
jMenuFile.add(jMenuFileExit);
jMenuBar1.add(jMenuHelp);
jMenuHelp.add(jMenuHelpAbout);
contentPane.add(jLabel1);
contentPane.add(jLabel2);
contentPane.add(jTextField1);
contentPane.add(jPasswordField1);
contentPane.add(jButton1);
contentPane.add(jButton2);
setJMenuBar(jMenuBar1);
}
/**
* File | Exit action performed.
*
* @param actionEvent ActionEvent
*/
void jMenuFileExit_actionPerformed(ActionEvent actionEvent) {
System.exit(0);
}
/**
* Help | About action performed.
*
* @param actionEvent ActionEvent
*/
void jMenuHelpAbout_actionPerformed(ActionEvent actionEvent) {
MainFrame_AboutBox dlg = new MainFrame_AboutBox(this);
Dimension dlgSize = dlg.getPreferredSize();
Dimension frmSize = getSize();
Point loc = getLocation();
dlg.setLocation((frmSize.width - dlgSize.width) / 2 + loc.x,
(frmSize.height - dlgSize.height) / 2 + loc.y);
dlg.setModal(true);
dlg.pack();
dlg.setVisible(true);
}
public void jButton2_actionPerformed(ActionEvent e) {
try{
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
}catch(java.lang.ClassNotFoundException e1){
System.out.println("forname"+e1.getMessage());
}
try{
Connection con = DriverManager.getConnection(url,"","");
Statement s = con.createStatement();
String sql="SELECT * FROM userlist";
ResultSet rs = s.executeQuery(sql);
while (rs.next()) {
if(jTextField1.getText().equalsIgnoreCase(rs.getString("name"))&&jPasswordField1.getText().equalsIgnoreCase(rs.getString("password"))){
ClientApp clp =new ClientApp();
System.out.println("OK");
System.out.println("姓名:" + rs.getString("name"));
System.out.println("密碼:" + rs.getString("password"));
}
}
rs.close();
con.close();
}catch(SQLException e1){
System.out.println("SQLException"+e1.getMessage());
}
}
}
class MainFrame_jButton2_actionAdapter implements ActionListener {
private MainFrame adaptee;
MainFrame_jButton2_actionAdapter(MainFrame adaptee) {
this.adaptee = adaptee;
}
public void actionPerformed(ActionEvent e) {
adaptee.jButton2_actionPerformed(e);
}
}
class MainFrame_jMenuFileExit_ActionAdapter implements ActionListener {
MainFrame adaptee;
MainFrame_jMenuFileExit_ActionAdapter(MainFrame adaptee) {
this.adaptee = adaptee;
}
public void actionPerformed(ActionEvent actionEvent) {
adaptee.jMenuFileExit_actionPerformed(actionEvent);
}
}
class MainFrame_jMenuHelpAbout_ActionAdapter implements ActionListener {
MainFrame adaptee;
MainFrame_jMenuHelpAbout_ActionAdapter(MainFrame adaptee) {
this.adaptee = adaptee;
}
public void actionPerformed(ActionEvent actionEvent) {
adaptee.jMenuHelpAbout_actionPerformed(actionEvent);
}
}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -