为什么用的随机数不能产生随机颜色和字体 不用随机数了颜色和字体的效果又能显示出来
import java.awt.*;
import javax.swing.*;
public class Char extends JFrame{
int i;
public Char(){
super("Draw characters");
setSize(300,300);
setVisible(true);
}
public void paint(Graphics g){
super.paint(g);
g.setColor(new Color((int)Math.random()*256,(int)Math.random()*256,(int)Math.random()*256));
i = (int)Math.random()*3;
switch(i){
case 0:
g.setFont(new Font("Serif",Font.BOLD,(int)Math.random()*8+12));
break;
case 1:
g.setFont(new Font("Monospaced",Font.ITALIC,(int)Math.random()*8+12));
break;
case 2:
g.setFont(new Font("SansSerif",Font.PLAIN,(int)Math.random()*8+12));
break;
default:
g.setFont(new Font("Serif",Font.ITALIC,(int)Math.random()*8+12));
break;
}
g.drawString("Happy New Year!",100,150);
}
public static void main(String args[]){
Char application = new Char() ;
application.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
}
}