package 按钮组件;
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
public class 按钮组件单选 {public static void main(String[] args) {new MyRadio("check单选窗口"); }
}
class MyRadio extends JFrame{JRadioButton rad1,rad2;JPanel jp,jp2;ButtonGroup bg;public MyRadio(String title){super(title);rad1=new JRadioButton("红色");rad2=new JRadioButton("绿色");bg=new ButtonGroup();jp=new JPanel();jp2=new JPanel();//匿名内部类rad1.addActionListener(new ActionListener(){public void actionPerformed(ActionEvent e){jp2.d);}});rad2.addActionListener(new ActionListener(){public void actionPerformed(ActionEvent e){jp2.setBackground(Color.GREEN);}});this.add(jp2,"Center");bg.add(rad1);bg.add(rad2);this.add(jp,"South");jp.add(rad1);jp.add(rad2);jp2.setBackground(Color.WHITE);//JFrame是透明的this.setLocation(300, 200);//设置位置this.setSize(300,200);//设置大小this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);//this.setVisible(true);//}
}
本文发布于:2024-02-01 22:32:49,感谢您对本站的认可!
本文链接:https://www.4u4v.net/it/170679796839866.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
留言与评论(共有 0 条评论) |