?? zhuce.java
字號:
//用戶注冊
import java.awt.event.*;
import java.sql.*;
import javax.swing.*;
import java.awt.*;
public class zhuce implements ActionListener{
JDialog dialog;
JComboBox combo;
JPasswordField passWd;
JTextField tF1=new JTextField();
//JTextField tF2=new JTextField();
//JTextField tF3=new JTextField();
zhuce(JFrame f)
{
dialog=new JDialog(f,"注冊信息",true);
Container dialogPane=dialog.getContentPane();
dialogPane.setLayout(new GridLayout(4,2));
dialogPane.add(new JLabel("用戶名:",SwingConstants.CENTER));
dialogPane.add(tF1);
dialogPane.add(new JLabel("密碼:",SwingConstants.CENTER));
passWd=new JPasswordField();
dialogPane.add(passWd);
//dialogPane.add(tF2);
dialogPane.add(new JLabel("權限:",SwingConstants.CENTER));
//dialogPane.add(tF3);
String[]data1={"1","2"};
combo=new JComboBox(data1);
combo.setEditable(true);
ComboBoxEditor editor=combo.getEditor();
combo.configureEditor(editor, "1為管理權限2為用戶權限");
dialogPane.add(combo);
JButton b1=new JButton("確定");
dialogPane.add(b1);
JButton b2=new JButton("取消");
dialogPane.add(b2);
b1.addActionListener(this);
b2.addActionListener(this);
dialog.setBounds(200,150,400,130);
dialog.setVisible(true);
}
public void actionPerformed(ActionEvent e)
{
String cmd=e.getActionCommand();
if(cmd.equals("確定"))
{
String username=tF1.getText();
String password=passWd.getText();
String unit=combo.getSelectedItem().toString();
if((username.equals(""))||(password.equals(""))||(unit.equals("")))
{
JOptionPane.showMessageDialog(dialog,"用戶名或密碼或權限不能為空");
}
else
{
try{
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
Connection con=
DriverManager.getConnection("jdbc:odbc:notebook","zxp","121");
Statement stmt=con.createStatement();
String SQLOrder="INSERT INTO users VALUES('"
+username+"','"+password+"','"+unit+"')";
dialog.dispose();
JOptionPane.showMessageDialog(dialog,"注冊成功");
stmt.executeUpdate(SQLOrder);
stmt.close();
con.close();
}catch(Exception ex){}
}
}else if(cmd.equals("取消"))
{
dialog.dispose();
}
}
}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -