请实现上面CoachFrame类
时间: 2024-03-12 22:45:51 浏览: 10
好的,以下是我为您实现的CoachFrame类的代码:
```java
import javax.swing.*;
import java.awt.*;
public class CoachFrame extends JFrame {
private JLabel nameLabel;
private JLabel ageLabel;
private JLabel teamLabel;
private JTextField nameField;
private JTextField ageField;
private JTextField teamField;
private JButton saveButton;
public CoachFrame() {
// 设置窗口标题
setTitle("教练员信息");
// 创建组件
nameLabel = new JLabel("姓名:");
ageLabel = new JLabel("年龄:");
teamLabel = new JLabel("球队:");
nameField = new JTextField();
ageField = new JTextField();
teamField = new JTextField();
saveButton = new JButton("保存");
// 设置布局
setLayout(new GridLayout(4, 2));
// 添加组件
add(nameLabel);
add(nameField);
add(ageLabel);
add(ageField);
add(teamLabel);
add(teamField);
add(new JLabel());
add(saveButton);
// 设置窗口大小
setSize(300, 150);
// 设置窗口可见
setVisible(true);
}
}
```
这个类实现了一个简单的教练员信息录入窗口,包括教练员的姓名、年龄和所在球队。界面使用了GridLayout布局,可以根据需要进行调整。
相关推荐
![docx](https://img-home.csdnimg.cn/images/20210720083331.png)
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)
![docx](https://img-home.csdnimg.cn/images/20210720083331.png)
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)
![docx](https://img-home.csdnimg.cn/images/20210720083331.png)
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)
![docx](https://img-home.csdnimg.cn/images/20210720083331.png)
![docx](https://img-home.csdnimg.cn/images/20210720083331.png)
![docx](https://img-home.csdnimg.cn/images/20210720083331.png)
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)