import javax.swing.*;
import java.awt.*;
public class MoonFrame extends JFrame{
public MoonFrame(){
MoonPanel panel=new MoonPanel();
Thread th=new Thread(panel);
th.start();
this.add(panel);
}
public void showMe(){
this.setTitle("月食");
this.setSize(800,600);
this.setDefaultCloseOperation(EXIT_ON_CLOSE);
this.setLocationRelativeTo(null);
this.setVisible(true);
}
public static void main(String[] args) {
// TODO Auto-generated method stub
MoonFrame mf=new MoonFrame();
mf.showMe();
}
}
import javax.swing.*;
import java.awt.*;
public class DrawStarFrame extends JFrame {
public void showMe(){
this.setTitle("满天星");
this.setSize(1000,600);
this.setDefaultCloseOperation(EXIT_ON_CLOSE);
this.setLocationRelativeTo(null);
//this.setResizable(false);
DrawStarPanel panel=new DrawStarPanel();
this.add(panel);
this.setVisible(true);
}
/**
* @param args
*/
public static void main(String[] args) {
// TODO Auto-generated method stub
DrawStarFrame ds=new DrawStarFrame();
ds.showMe();
}
}
import javax.swing.*;
import java.awt.*;
public class DrawStarPanel extends JPanel{
public void paint(Graphics g){
super.paint(g);
this.setBackground(Color.BLACK);
g.setColor(Color.yellow);
Font font=new Font("宋体",Font.BOLD,20);
g.setFont(font);
for(int i=0;i<500;i++){
g.drawString("★", (int)(Math.random()*1000),(int) (Math.random()*600));
}
g.fillOval(650, 100, 80, 80);
g.setColor(Color.BLACK);
g.fillOval(630, 80, 70, 80);
}
}