📄 loginframe.java
字号:
package edu.sm.view;
import java.awt.BorderLayout;
import java.awt.Button;
import java.awt.FlowLayout;
import java.awt.Frame;
import java.awt.Label;
import java.awt.Panel;
import java.awt.TextField;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;
/**
* 登录界面
* @author wy
*
*/
public class LoginFrame extends BaseFrame {
/**
* 用户名
*/
private TextField name;
/**
* 密码
*/
private TextField password;
/**
* 提示窗口
*/
private Label message;
public LoginFrame() {
super("登陆界面", 150, 200, 300, 180);
message = new Label();
this.addWindowListener(new WindowAdapter() {
@Override
public void windowClosing(WindowEvent e) {
System.exit(0);
}
});
Panel p1 = new Panel();
Panel p2 = new Panel();
Label l1 = new Label("用户名");
name = new TextField(10);
Label l2 = new Label("密码");
password = new TextField(10);
Panel t1 = new Panel();
t1.setLayout(new FlowLayout(FlowLayout.CENTER));
t1.add(l1);
t1.add(name);
Panel t2 = new Panel();
t2.setLayout(new FlowLayout(FlowLayout.CENTER));
t2.add(l2);
t2.add(password);
p1.setLayout(new BorderLayout());
p1.add(BorderLayout.NORTH,t1);
p1.add(BorderLayout.SOUTH,t2);
p2.setLayout(new FlowLayout(FlowLayout.CENTER));
Button ok = new Button("登录");
p2.add(message);
p2.add(ok);
this.setLayout(new BorderLayout());
this.add(BorderLayout.NORTH,p1);
this.add(BorderLayout.SOUTH,p2);
add(BorderLayout.CENTER,p1);
add(BorderLayout.SOUTH,p2);
pack();
ok.addActionListener(new LoginAction(this));
this.setVisible(true);
}
private class LoginAction implements ActionListener {
private Frame lf;
LoginAction(Frame lf) {
this.lf = lf;
}
@Override
public void actionPerformed(ActionEvent e) {
String names = name.getText();
String pas = password.getText();
if("root".equalsIgnoreCase(names)&&"root".equalsIgnoreCase(pas)) {
lf.dispose();
new MainFrame();
} else {
message.setText("用户名或密码错误!");
}
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -