package sxw_helloworld;
import java.awt.Color;
import java.awt.Frame;
import java.awt.Graphics;
import java.awt.Point;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;
import java.util.Random;
import java.util.ArrayList;
public class HellowWorldClassextends Frame{
/**
*
*/
privatestatic finallong serialVersionUID = 1L;
ArrayList
ArrayList
Random rd =new Random();
public void init() {
setSize(500,400);
setTitle("彩票号码生成器!(点击窗体任何位置重新生成)");
setVisible(true);
setLocationRelativeTo(null);
setResizable(false);
addWindowListener(new WindowAdapter() {
public void windowClosing(WindowEvent e) {
System.exit(0);
}
});
addMouseListener(new MouseAdapter() {
public void mouseClicked(MouseEvent e) {
repaint();
}
});
}
public void paint(Graphics g) {
Random rd =new Random();
ArrayList
g.drawString("本期中奖号码", 100, 100);
g.drawString("红色球是:", 100, 150);
g.drawString("蓝色球是", 100, 200);
for(inti = 0;i<6;i++){
int red = rd.nextInt(33)+ 1;
if (list.contains(red)) {
i--;
}
else {
list.add(red);
}
}
int blue = rd.nextInt(16)+1;
g.setColor(Color.blue);
g.drawString(blue +"", 200, 200);
g.setColor(Color.red);
for (inti = 0; i < 6;i++) {
g.drawString(list.get(i) +"", 200 + (i*50), 150);
}
}
public static void main(String[] args) {
// TODO Auto-generated method stub
new HellowWorldClass().init();
}
}