| 12
 3
 4
 5
 6
 7
 8
 9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
 100
 101
 102
 103
 104
 105
 106
 
 | import java.awt.AWTException;
import java.awt.Color;
import java.awt.Container;
import java.awt.Graphics;
import java.awt.Robot;
 
import javax.management.relation.Role;
import javax.swing.JFrame;
import javax.swing.JMenu;
import javax.swing.JMenuBar;
import javax.swing.JMenuItem;
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
 
public class quenivelquieres extends JFrame {
 
 
 
private static final long serialVersionUID = 8585544783492126617L;
public static quenivelquieres app;	
public static final int APP_WIDTH = 500;
public static final int APP_HEIGHT = 500;
private JMenuBar Barra;
private JMenu Archivo;
private JMenuItem salir;
public static void main(String[] args) { 
app = new quenivelquieres ();
app.show();
}
 
 
public void paint(Graphics gfx) {
setLayout(null);
setDefaultCloseOperation (JFrame.EXIT_ON_CLOSE);
Barra = new JMenuBar();
Archivo = new JMenu ("Archivo");
Barra.add(Archivo);
salir = new JMenuItem ("Salir");
Archivo.add(salir);
salir.addActionListener(
new ActionListener() { 
public void actionPerformed( ActionEvent evento ){
System.exit( 0 );
}
}
);
this.setJMenuBar(Barra);
setVisible(true);
 
Container workArea = this.getContentPane();
Graphics workAreaGfx = workArea.getGraphics();
int z = 0;
while (z<1000){
 
int x = (int) (Math.random()*10+1);
 
 
 
if(x==5){x= x-1;}
if(x==6){x= x-3;}//3
if(x==7){x= x-5;}//2
if(x==8){x= x-7;}//1
if(x==9){x= x-5;}//4
 
if(x==10){x= x-9;}//1
 
 
 
if(x==1){
workAreaGfx.setColor(Color.blue);
int width = workArea.getWidth();
int height = workArea.getHeight();
workAreaGfx.fillRect(0,0, width/2, height/2);}
if(x==2){
workAreaGfx.setColor(Color.red);
int width = workArea.getWidth();
int height = workArea.getHeight();
workAreaGfx.fillRect(250,250, width,height);}
if(x==3){
workAreaGfx.setColor(Color.yellow);
int width = workArea.getWidth();
int height = workArea.getHeight();
workAreaGfx.fillRect(250,0, width/2, height/2);}
if(x==4){
workAreaGfx.setColor(Color.green);
int width = workArea.getWidth();
int height = workArea.getHeight();
workAreaGfx.fillRect(0,250, width/2, height/2);} 
 
 
z+=1;
this.setSize(APP_WIDTH, APP_HEIGHT);
this.setTitle("Dale al Azúl");
 
 
 
} 
 
 
 
}
 
 
 
} | 
Partager