Advertisement
Kyrexar

LOL

Nov 5th, 2012
95
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.59 KB | None | 0 0
  1. import java.awt.*;
  2. import java.awt.event.*;
  3. import javax.swing.*;
  4.  
  5. public class Locura extends JComponent {
  6.  
  7.     private final static int ANCHO = 500, ALTO = 500;
  8.  
  9.     public Locura() {
  10.         setPreferredSize(new Dimension(ANCHO, ALTO));
  11.     }
  12.  
  13.     public void paint(Graphics g) {
  14.         g.setColor(Color.BLACK);
  15.         g.fillRect(0, 0, ANCHO, ALTO);
  16.         g.setColor(Color.WHITE);
  17.         g.fillOval( (int) (Math.random()*250+1), (int) (Math.random()*250+1), (int) (Math.random()*250+1), (int) (Math.random()*250+1) );
  18.     }
  19.  
  20.     private void dibuja() throws Exception {
  21.         SwingUtilities.invokeAndWait(new Runnable() {
  22.                 public void run() {
  23.                     paintImmediately(0, 0, ANCHO, ALTO);
  24.                 }
  25.             });
  26.     }
  27.  
  28.     public void tiempo() throws Exception {
  29.         long tiempoViejo = System.nanoTime();
  30.                
  31.         while (true) {
  32.             long tiempoNuevo = System.nanoTime();
  33.             float dt = (tiempoNuevo - tiempoViejo) / 1000000000f;
  34.             tiempoViejo = tiempoNuevo;
  35.            
  36.             dibuja();
  37.         }
  38.     }
  39.  
  40.     public static void main(String[] args) throws Exception {
  41.         JFrame jf = new JFrame("Locura");
  42.         jf.addWindowListener(new WindowAdapter() {
  43.                 public void windowClosing(WindowEvent e) {
  44.                     System.exit(0);
  45.                 }
  46.             });
  47.         jf.setResizable(false);
  48.         Locura locura = new Locura();
  49.         jf.getContentPane().add(locura);
  50.         jf.pack();
  51.         jf.setVisible(true);
  52.         locura.tiempo();
  53.     }
  54. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement