一个java的小程序中的问题 关于单选按钮的
来源:百度知道 编辑:UC知道 时间:2024/06/07 09:53:48
import java.awt.event.*;
import javax.swing.*;
public class CheckBoxDemo1 extends JFrame implements ItemListener
{
private JTextArea jta;
public CheckBoxDemo1()
{
setTitle("Check Box Demo");
setLocation(150,150);
jta=new JTextArea("Welcome to Java!",5,20);
jta.setFont(new Font("Serif",Font.PLAIN,20));
jta.setBackground(Color.pink);
JPanel p=new JPanel();
p.setLayout(new FlowLayout());
ButtonGroup bgroup=new ButtonGroup();
JRadioButton button20=new JRadioButton("20",true);
bgroup.add(button20);
p.add(button20);
JRadioButton button30=new JRadioButton("30",false);
bgroup.add(button30);
p.add(button30);
JRadioButton button60=new JRadioButton("60",false);
bgroup.add(button60);
p.add(button60);
getContentPane().setLayout(ne
button20, button30, button60 定义在里面了,另外那个方法看不到他们。
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
public class CheckBoxDemo1 extends JFrame implements ItemListener {
private JTextArea jta;
JRadioButton button20, button30, button60;
public CheckBoxDemo1() {
setTitle("Check Box Demo");
setLocation(150, 150);
jta = new JTextArea("Welcome to Java!", 5, 20);
jta.setFont(new Font("Serif", Font.PLAIN, 20));
jta.setBackground(Color.pink);
JPanel p = new JPanel();
p.setLayout(new FlowLayout());
ButtonGroup bgroup = new ButtonGroup();
button20 = new JRadioButton("20", true);
bgroup.add(button20);
p.add(button20);
button30 = new JRadioButton("30", false);
bgroup.add(button30);
p.add(button30);
button60 = new JRadioButton("60", false);
bgroup