?? login.java
字號:
/* 學生注冊登記類 Login.java */
import java.awt.*;
import javax.swing.*;
import java.awt.event.*;
public class Login extends JFrame implements ActionListener
{JTextField tNo,tName,tBirthday,tSex,tScore,tRemarks;
JLabel lNo,lName,lBirthday,lSex,lScore,lRemarks;
JButton okButton,exitButton;
OperateDatabase op1=new OperateDatabase("students","sa","");
public Login() //構造方法
{ Container content=this.getContentPane();
content.setLayout(new GridLayout(4,4));
lNo = new JLabel("學號");
tNo = new JTextField(11);
lName = new JLabel("姓名");
tName = new JTextField(10);
lBirthday = new JLabel("出生年月");
tBirthday = new JTextField(10);
lSex = new JLabel("性別");
tSex = new JTextField(2);
lScore = new JLabel("入學成績");
tScore = new JTextField(5);
lRemarks = new JLabel("備注");
tRemarks = new JTextField(16);
okButton = new JButton("注冊");
exitButton=new JButton("退出");
content.add(lNo);
content.add(tNo);
content.add(lName);
content.add(tName);
content.add(lBirthday);
content.add(tBirthday);
content.add(lSex);
content.add(tSex);
content.add(lScore);
content.add(tScore);
content.add(lRemarks);
content.add(tRemarks);
content.add(new JLabel());
content.add(okButton);
content.add(exitButton);
content.add(new JLabel());
okButton.addActionListener(this);
exitButton.addActionListener(this);
this.pack();
this.setVisible(true);
this.setDefaultCloseOperation(this.EXIT_ON_CLOSE);
}//構造方法結束
public void actionPerformed(ActionEvent evt) //事件方法
{ Object obj = evt.getSource();
try
{if(obj == okButton)
{ String str1="insert into login values(?,?,?,?,?,?)";
String [] values=new String[6];
values[0]=tNo.getText();
values[1]=tName.getText();
values[2]=tBirthday.getText();
values[3]=tSex.getText();
values[4]=tScore.getText();
values[5]=tRemarks.getText();
op1.insert(str1,values); //調用對象插入方法,在數據表中插入一個記錄
tNo.setText("");
tName.setText("");
tScore.setText("0");
}
else
{ System.exit(0); }
}
catch(Exception e)
{ System.out.println("Error:"+e); }
}//事件方法結束
public static void main(String [] args)
{
new Login();
}
}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -