没有合适的资源?快使用搜索试试~ 我知道了~
按钮的颜色设置java代码
5星 · 超过95%的资源 需积分: 45 37 下载量 5 浏览量
2010-05-23
16:35:27
上传
评论
收藏 24KB DOC 举报
温馨提示
试读
2页
按钮的颜色设置java代码,可以根据本实例,主一反三,懂得其他的很多东西
资源推荐
资源详情
资源评论
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
public class Test {
public static void main(String[] args) {
new MyFrame("123",100,100,300,300);// TODO 自动生成方法存根
}
}
class MyFrame extends JFrame implements ActionListener{
private JRadioButton rb1,rb2;
MyFrame(String str,int x,int y,int w, int h){
super(str);
Container con = this.getContentPane();
con.setLayout(new FlowLayout());
ButtonGroup bg = new ButtonGroup();
rb1 = new JRadioButton("红色");
rb1.addActionListener(this);
rb2 = new JRadioButton("蓝色");
rb2.addActionListener(this);
bg.add(rb1); bg.add(rb2);
con.add(rb1); con.add(rb2);
this.setBounds(x, y, w, h);
this.setVisible(true);
this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
}
public void actionPerformed(ActionEvent e) {
Container con = this.getContentPane();
if(e.getSource()==rb1){
con.setBackground(Color.red);
}else if(e.getSource()==rb2){
con.setBackground(Color.blue);
}// TODO 自动生成方法存根
资源评论
- x19869272015-11-20有用,可以参考
- enyayan2014-12-30虽然没帮上什么 但是能帮助理解 谢谢
- fugang09052013-02-22很适合初学者
dding334179706
- 粉丝: 3
- 资源: 4
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功