insertuser.java
来自「用java2核心类库写的一个学生课程管理系统」· Java 代码 · 共 84 行
JAVA
84 行
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
public class InsertUser extends JFrame
{
private JPanel content;
private JLabel userLabel;
private JLabel passwordLabel ;
private JTextField userText;
private JTextField passwordText;
private JButton okBtn;
private JButton cancleBtn;
private static final InsertUser InserUser= new InsertUser();
public static InsertUser singleInsertUser()
{
return InserUser;
}
private InsertUser()
{
initInsertUser();
ClickActionListener cal = new ClickActionListener();
okBtn.addActionListener(cal);
cancleBtn.addActionListener(cal);
}
private void initInsertUser()
{
this.setTitle("添加用户");
content = new JPanel();
userLabel = new JLabel("用户名: ");
passwordLabel = new JLabel("密码: ");
userText= new JTextField(10);
passwordText = new JTextField(10);
okBtn = new JButton("添加");
cancleBtn=new JButton("清除");
content.add(userLabel);
content.add(userText);
content.add(passwordLabel);
content.add(passwordText);
content.add(okBtn);
content.add(cancleBtn);
content.setLayout(new FlowLayout());
this.add(content);
this.setSize(300,300);
}
class ClickActionListener implements ActionListener
{
public void actionPerformed(ActionEvent e)
{
String user= null;
String password= null;
System.out.println("insert button ");
if (e.getActionCommand() == "添加")
{
System.out.println("insert button is ok");
user = userText.getText();
password =passwordText.getText();
String sqlInsert = null;
sqlInsert = "insert into 用户信息 values (" +
"\'" + user + "\'" + "," +
"\'" + password + "\'" + ")" ;
System.out.println("sqlInsert = " + sqlInsert);
SMISDB insertUserDB = new SMISDB();
insertUserDB.getTable(sqlInsert,new JFrame(),true);
}
else if (e.getActionCommand()=="清除")
{
userText.setText("");
passwordText.setText("");
}
}
}
}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?