菜鸟 求教!! 请大神们 帮帮忙忙
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
public class EventDemo1 extends JFrame {
private JButton button;
private Container container;
public EventDemo1(){
super("我爱你");
setSize(500,300);
try{
UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
}catch(Exception e){}
container=getContentPane();
button=new JButton("改变颜色");
button.setFont(new Font("Serif",Font.PLAIN,14));
button.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent event){
//为什么这儿 要写三个? 我写两个怎么是错误的呢 ?
int red=(int)(Math.random()*256);
int green=(int)(Math.random()*256);
int blue=(int)(Math.random()*256);
container.setBackground(new Color(red, green,blue));
}
});
container.add(button,BorderLayout.SOUTH);
setVisible(true);
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
}
public static void main(String args[]){
new EventDemo1();
}
}
[解决办法]
颜色RGB 是三个颜色~~~~~