import java.awt.*;
import java.awt.event.*;
public class Eventest
{
Button btn1=new Button("单击");
Frame myframe=new Frame("测试单击事件");
public void init(){
btn1.setSize(30,26);
btn1.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent e){
if(btn1.getBackground()==Color.red)
btn1.setBackground(Color.white);
else
btn1.setBackground(Color.red);
}
});
myframe.setBounds(300,200,200,200);
myframe.add(btn1);
myframe.setVisible(true);
}
public static void main(String[] args)
{
new Eventest().init();
}
}
java中按钮设置颜色 javabutton设置颜色
转载本文章为转载内容,我们尊重原作者对文章享有的著作权。如有内容错误或侵权问题,欢迎原作者联系我们进行内容更正或删除文章。
提问和评论都可以,用心的回复会被更多人看到
评论
发布评论
相关文章
-
有趣的css - 颜色滑动切换按钮
当鼠标悬浮在按钮上方时,按钮背景色从左往右滑动变化一个变化切换按钮。
css动画 动效设计 交互设计 用户体验 按钮 -
html5颜色按钮 html中按钮怎么设置颜色
input与button按钮的区别input不自带边框属性button按钮自带一像素的边框btn.setTextColor(mContext.getResources()  ...页面效果:代码:html PUBLIC&n
html5颜色按钮 html链接按钮变化颜色 android html 控件