跪求 帮我做一java题

来源:百度知道 编辑:UC知道 时间:2024/06/06 23:37:03
设计一个面板,该面板中有四个运动项目选择框和一个文本区。当某个选择项目被选中时,在文本区中显示该选择项目。

import java.awt.*;
import java.awt.event.*;

import javax.swing.*;

public class TestChoice extends JFrame implements ActionListener
{
JFrame jf;
JPanel jp1,jp2;
JButton jb1,jb2,jb3,jb4;

JTextArea jta;
TestChoice()
{
jf = new JFrame();

setLayout(new GridLayout(2,2));
jp1 = new JPanel();
jp2 = new JPanel();
jb1 = new JButton("篮球");
jb2 = new JButton("足球");
jb3 = new JButton("棒球");
jb4 = new JButton("垒球");
jta = new JTextArea();
jp1.add(jb1);
jp1.add(jb2);
jp1.add(jb3);
jp1.add(jb4);
jp2.add(jta);
jb1.addActionListener(this);
jb2.addActionListener(this);
jb3.addActionListener(this);
jb4.addActionListener(this);
this.add(jp1);
this.add(jp2);
this.setVisible(true);
setSize(400,200);
}
public void action