1.使用AWT包中的类,编程实现“登录窗口”图形用户界面(GUI)。参考界面如图。要求:采用词能达意的规范方式为类、成员属性和成员方法命名。 2.使用Swing包中的类,编程实现“运动员登录”图形用户界面
时间: 2024-03-18 21:41:50 浏览: 23
很抱歉,作为一个AI语言模型,我不能直接进行编程操作。但是,我可以为您提供一些相关的代码示例和参考链接,希望能够帮助到您。
1. 实现“登录窗口”图形用户界面(GUI):
```
import java.awt.*;
import java.awt.event.*;
public class LoginWindow extends Frame implements ActionListener {
private Label nameLabel;
private Label passwordLabel;
private TextField nameField;
private TextField passwordField;
private Button loginButton;
public LoginWindow() {
super("登录窗口");
nameLabel = new Label("用户名:");
passwordLabel = new Label("密码:");
nameField = new TextField(20);
passwordField = new TextField(20);
passwordField.setEchoChar('*');
loginButton = new Button("登录");
loginButton.addActionListener(this);
setLayout(new GridLayout(3, 2));
add(nameLabel);
add(nameField);
add(passwordLabel);
add(passwordField);
add(new Label());
add(loginButton);
pack();
setVisible(true);
}
public void actionPerformed(ActionEvent e) {
String name = nameField.getText();
String password = passwordField.getText();
if (name.equals("admin") && password.equals("123456")) {
System.out.println("登录成功!");
} else {
System.out.println("用户名或密码错误!");
}
}
public static void main(String[] args) {
new LoginWindow();
}
}
```
2. 实现“运动员登录”图形用户界面:
```
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
public class AthleteLogin extends JFrame implements ActionListener {
private JLabel nameLabel;
private JLabel passwordLabel;
private JTextField nameField;
private JPasswordField passwordField;
private JButton loginButton;
public AthleteLogin() {
super("运动员登录");
nameLabel = new JLabel("用户名:");
passwordLabel = new JLabel("密码:");
nameField = new JTextField(20);
passwordField = new JPasswordField(20);
loginButton = new JButton("登录");
loginButton.addActionListener(this);
JPanel panel = new JPanel();
panel.setLayout(new GridLayout(3, 2));
panel.add(nameLabel);
panel.add(nameField);
panel.add(passwordLabel);
panel.add(passwordField);
panel.add(new JLabel());
panel.add(loginButton);
add(panel);
pack();
setVisible(true);
}
public void actionPerformed(ActionEvent e) {
String name = nameField.getText();
String password = new String(passwordField.getPassword());
if (name.equals("athlete") && password.equals("123456")) {
System.out.println("登录成功!");
} else {
System.out.println("用户名或密码错误!");
}
}
public static void main(String[] args) {
new AthleteLogin();
}
}
```
以上代码仅供参考,具体实现还需要您进行深入学习和实践。希望能够帮助到您。