Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.awt.Graphics;
- import javax.swing.JFrame;
- import javax.swing.JOptionPane;
- public class SistemaSolar
- {
- static public CorpoCeleste list[] = new CorpoCeleste[10];
- static int planets = 0;
- public static void main(String[] args) throws InterruptedException
- {
- JFrame janela= new JFrame();
- janela.setTitle("Sistema Solar");
- janela.setSize(800,600);
- janela.setAlwaysOnTop(true);
- janela.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
- janela.setVisible(true);
- init();
- paint(janela.getGraphics());
- }
- public static void init()
- {
- list[planets++] = new Sol();
- list[planets++] = new Planeta();
- list[planets++] = new Planeta();
- list[planets++] = new Planeta();
- }
- public static void paint(Graphics g)
- {
- try
- {
- int sleepTime = 800;
- Thread.sleep(sleepTime);
- g.drawRect(50,50, 300, 300);
- for (int i = 0; i < planets; i++)
- {
- list[i].move();
- list[i].draw(g);
- }
- for(;;)
- {
- repaint(g);
- Thread.sleep(1000);
- }
- }
- catch (InterruptedException e)
- {
- //showStatus(e.toString());
- JOptionPane.showMessageDialog(null, e.toString());
- }
- }
- public static void repaint(Graphics g)
- {
- g.clearRect(50, 50, 300, 300);
- CorpoCeleste sol = list[0];
- sol.planetSize = (int)(Math.random() * 50) + 50;
- g.drawRect(50,50, 300, 300);
- for (int i = 0; i < planets; i++)
- {
- list[i].move();
- list[i].draw(g);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement