import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
import java.sql.*;
public class 注冊界面 implements ActionListener{
public void showFrame() {
JFrame fr = new JFrame();
fr.setTitle("注冊界面");
fr.setSize(335,375);
fr.setDefaultCloseOperation(3);
fr.setLocationRelativeTo(null);
FlowLayout flow = new java.awt.FlowLayout();
fr.setLayout(flow);
javax.swing.ImageIcon image = new javax.swing.ImageIcon("2.jpg");
javax.swing.JLabel jla = new JLabel(image);
java.awt.Dimension dm1 = new Dimension(400,150);
jla.setPreferredSize(dm1);
fr.add(jla);
JLabel jla1 = new JLabel("賬號:");
fr.add(jla1);
JTextField jtfd = new JTextField(12);
Dimension dm2 = new Dimension(250, 30);
jtfd.setPreferredSize(dm2);
fr.add(jtfd);
JLabel jla2 = new JLabel("密碼:");
fr.add(jla2);
JPasswordField jtf1 = new JPasswordField(6);
Dimension dm3 = new Dimension(250, 30);
jtf1.setPreferredSize(dm3);
fr.add(jtf1);
JButton jbu = new javax.swing.JButton("注冊");
jbu.setPreferredSize(dm2);
fr.add(jbu);
jbu.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
fr.dispose();
new 登錄界面().showFrame();
}
});
jbu.addActionListener(this);
fr.setVisible(true);
}
public void actionPerformed(ActionEvent e) {
try {
Class.forName("com.microsoft.sqlserver.jdbc.SQLServerDriver");
String url="jdbc:sqlserver://localhost:1433;DatabaseName=abc";
String userName="xzh";
String userPwd="xzh826268";
Connection conn=DriverManager.getConnection(url,userName,userPwd);
Statement st;
st=conn.createStatement();
st.executeUpdate("insert into 操作員(Id,PW) values('lisi','123456')");
conn.close();
}
catch(Exception e1) {
JOptionPane.showMessageDialog(null, "密碼只能填六位數","密碼錯誤",JOptionPane.WARNING_MESSAGE);
}
}
}
uj5u.com熱心網友回復:
在登錄按鈕的事件處理中獲得輸入值,然后處理uj5u.com熱心網友回復:
我在事件里加入了String id = jtfd.getText();
String password = jtf1.getText();
為什么無法獲取兩個文本框的內容
uj5u.com熱心網友回復:
我在事件里加入了String id = jtfd.getText();
char []pw=jtf1.getPassword();
String password=new String(pw);
為什么無法獲取兩個文本框的內容
轉載請註明出處,本文鏈接:https://www.uj5u.com/houduan/61769.html
標籤:Eclipse
上一篇:spring-boot-maven-plugin爆紅如何解決
下一篇:UDP 協議的那點事兒
