运行环境:IDEA
JAVA版本:jdk1.8
import javax.swing.*;
import java.awt.*;
import java.util.Random;
public class Dog extends JFrame {
public Dog(int x,int y,int num){
setTitle("http://5hx.ink");
setBounds(x,y,350,150);
getContentPane().setLayout(null);
JPanel panel = new JPanel();
panel.setBounds(0, 0, 350, 200);
Color color[] = {Color.GREEN,Color.BLUE,Color.cyan,Color.MAGENTA,Color.RED,Color.YELLOW,Color.PINK,Color.WHITE};
panel.setBackground(color[num]);
getContentPane().add(panel);
JLabel label1 = new JLabel("你行不行啊,细狗~");
label1.setFont(new Font("宋体", Font.BOLD,26));
panel.add(label1);
setVisible(true);
setDefaultCloseOperation(EXIT_ON_CLOSE);
}
public static void main(String[] args) throws Exception{
for (int i = 0; i < 50; i++) {
Random random = new Random();
int x = random.nextInt(1300)+100;
int y = random.nextInt(600)+100;
int num = random.nextInt(8);
new Dog(x,y,num);
Thread.sleep(100);
}
}
}