Advertisement
Guest User

Untitled

a guest
May 24th, 2015
224
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.87 KB | None | 0 0
  1. import java.awt.Graphics;
  2. import javax.swing.JFrame;
  3. import javax.swing.JOptionPane;
  4.  
  5. public class SistemaSolar
  6. {
  7.     static public CorpoCeleste list[] = new CorpoCeleste[10];
  8.     static int planets = 0;
  9.    
  10.     public static void main(String[] args) throws InterruptedException
  11.     {
  12.         JFrame janela= new JFrame();
  13.         janela.setTitle("Sistema Solar");
  14.         janela.setSize(800,600);
  15.         janela.setAlwaysOnTop(true);
  16.         janela.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
  17.         janela.setVisible(true);
  18.        
  19.         init();
  20.         paint(janela.getGraphics());
  21.     }
  22.    
  23.     public static void init()
  24.     {
  25.         list[planets++] = new Sol();
  26.         list[planets++] = new Planeta();
  27.         list[planets++] = new Planeta();
  28.         list[planets++] = new Planeta();
  29.     }
  30.    
  31.     public static void paint(Graphics g)
  32.     {
  33.         try
  34.         {
  35.             int sleepTime = 800;
  36.             Thread.sleep(sleepTime);
  37.            
  38.             g.drawRect(50,50, 300, 300);
  39.            
  40.             for (int i = 0; i < planets; i++)
  41.             {
  42.                 list[i].move();
  43.                 list[i].draw(g);
  44.             }
  45.        
  46.             for(;;)
  47.             {
  48.                 repaint(g);
  49.                 Thread.sleep(1000);
  50.             }
  51.         }
  52.         catch (InterruptedException e)
  53.         {
  54.             //showStatus(e.toString());
  55.             JOptionPane.showMessageDialog(null, e.toString());
  56.         }
  57.     }
  58.    
  59.     public static void repaint(Graphics g)
  60.     {
  61.         g.clearRect(50, 50, 300, 300);
  62.         CorpoCeleste sol = list[0];
  63.        
  64.         sol.planetSize = (int)(Math.random() * 50) + 50;
  65.        
  66.         g.drawRect(50,50, 300, 300);
  67.        
  68.         for (int i = 0; i < planets; i++)
  69.         {
  70.             list[i].move();
  71.             list[i].draw(g);
  72.         }
  73.     }
  74. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement