📄 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 + -