Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.awt.*;
- import java.awt.event.*;
- import javax.swing.*;
- public class Locura extends JComponent {
- private final static int ANCHO = 500, ALTO = 500;
- public Locura() {
- setPreferredSize(new Dimension(ANCHO, ALTO));
- }
- public void paint(Graphics g) {
- g.setColor(Color.BLACK);
- g.fillRect(0, 0, ANCHO, ALTO);
- g.setColor(Color.WHITE);
- g.fillOval( (int) (Math.random()*250+1), (int) (Math.random()*250+1), (int) (Math.random()*250+1), (int) (Math.random()*250+1) );
- }
- private void dibuja() throws Exception {
- SwingUtilities.invokeAndWait(new Runnable() {
- public void run() {
- paintImmediately(0, 0, ANCHO, ALTO);
- }
- });
- }
- public void tiempo() throws Exception {
- long tiempoViejo = System.nanoTime();
- while (true) {
- long tiempoNuevo = System.nanoTime();
- float dt = (tiempoNuevo - tiempoViejo) / 1000000000f;
- tiempoViejo = tiempoNuevo;
- dibuja();
- }
- }
- public static void main(String[] args) throws Exception {
- JFrame jf = new JFrame("Locura");
- jf.addWindowListener(new WindowAdapter() {
- public void windowClosing(WindowEvent e) {
- System.exit(0);
- }
- });
- jf.setResizable(false);
- Locura locura = new Locura();
- jf.getContentPane().add(locura);
- jf.pack();
- jf.setVisible(true);
- locura.tiempo();
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement