?? loginframe2.java~8~
字號:
package jsjexample;
import java.awt.BorderLayout;
import javax.swing.JFrame;
import javax.swing.JLabel;
import java.awt.*;
import javax.swing.JTextField;
import javax.swing.JButton;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.JPasswordField;
public class LoginFrame2 extends JFrame {
public LoginFrame2() {
try {
jbInit();
} catch (Exception exception) {
exception.printStackTrace();
}
}
private void jbInit() throws Exception {
getContentPane().setLayout(null);
jLabel1.setBackground(Color.pink);
jLabel1.setOpaque(true);
jLabel1.setBounds(new Rectangle(44, 27, 167, 33));
jButton1.addActionListener(new LoginFrame2_jButton1_actionAdapter(this));
jButton2.addActionListener(new LoginFrame2_jButton2_actionAdapter(this));
jPasswordField1.setBounds(new Rectangle(86, 115, 126, 22));
this.getContentPane().add(jLabel1);
jButton2.setBounds(new Rectangle(143, 168, 98, 34));
jButton2.setMnemonic('C');
jButton2.setText("取消(C)");
jButton1.setBounds(new Rectangle(41, 166, 93, 36));
jButton1.setMnemonic('A');
jButton1.setText("確定(A)");
jLabel3.setText("密碼");
jLabel3.setBounds(new Rectangle(29, 116, 34, 16));
jTextField1.setBounds(new Rectangle(85, 73, 125, 22));
this.getContentPane().add(jLabel2);
this.getContentPane().add(jTextField1);
this.getContentPane().add(jLabel3);
this.getContentPane().add(jButton1);
this.getContentPane().add(jButton2);
this.getContentPane().add(jPasswordField1);
jLabel2.setText("姓名");
jLabel2.setBounds(new Rectangle(28, 74, 34, 16));
}
JLabel jLabel1 = new JLabel();
JLabel jLabel2 = new JLabel();
JTextField jTextField1 = new JTextField();
JLabel jLabel3 = new JLabel();
JButton jButton1 = new JButton();
JButton jButton2 = new JButton();
JPasswordField jPasswordField1 = new JPasswordField();
public static void main(String args[]) {
LoginFrame2 login = new LoginFrame2();
login.setSize(400, 300);
login.setLocation(100, 100);
login.setVisible(true);
}
public void jButton1_actionPerformed(ActionEvent e) {
String str1 = jTextField1.getText().trim();
String str2 = jPasswordField1.getText().trim();
if (str1.equals("aaa") && str2.equals("123")) {
jLabel1.setText("登陸成功!");
} else {
jLabel1.setText("用戶名或密碼錯誤!");
jTextField1.setText("");
}
}
public void jButton2_actionPerformed(ActionEvent e) {
System.exit(0);
}
}
class LoginFrame2_jButton2_actionAdapter implements ActionListener {
private LoginFrame2 adaptee;
LoginFrame2_jButton2_actionAdapter(LoginFrame2 adaptee) {
this.adaptee = adaptee;
}
public void actionPerformed(ActionEvent e) {
adaptee.jButton2_actionPerformed(e);
}
}
class LoginFrame2_jButton1_actionAdapter implements ActionListener {
private LoginFrame2 adaptee;
LoginFrame2_jButton1_actionAdapter(LoginFrame2 adaptee) {
this.adaptee = adaptee;
}
public void actionPerformed(ActionEvent e) {
adaptee.jButton1_actionPerformed(e);
}
}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -