// SE MUESTRA UNA CARITA GUINIENDO EL OJO
import javax.swing.*;
import java.awt.event.*;
import java.awt.*;
class Carita extends JFrame
{
Dibujo JP = new Dibujo();
public static void main(String R[]) { new Carita(); }
public Carita()
{
this.setBounds(100, 100, 800, 800);
this.setVisible(true);
JP = new Dibujo();
this.add(JP);
JP.setBounds(0,0,800, 800);
JP.setVisible(true);
}
protected void processWindowEvent(WindowEvent e)
{ if (e.getID() == WindowEvent.WINDOW_CLOSING) System.exit(0); }
}
class Dibujo extends JPanel implements Runnable
{
Thread Hilo = new Thread(this);
JButton OJO_I, OJO_D, NARIZ, BOCA;
int Elemento = 0; // 1=OJO_I, 2=OJO_D, 3=BOCA
public Dibujo()
{
this.setLayout(null);
OJO_I = new JButton("o"); OJO_D = new JButton("o");
NARIZ = new JButton("|"); BOCA = new JButton("-------");
OJO_I.setBounds(50, 50, 100, 50); OJO_D.setBounds(650, 50, 100, 50);
NARIZ.setBounds(400, 200, 50, 200); BOCA.setBounds(50, 600, 600, 50);
add(OJO_I); this.add(OJO_D); add(NARIZ); this.add(BOCA);
Hilo.start();
}
public void start( ) { if (Hilo == null) { Hilo.start(); } }
public void run( )
{
while( true )
{
try { Thread.sleep(1000); }
catch(InterruptedException r) { }
if (Elemento==3) Elemento=1;
else Elemento++;
switch (Elemento)
{
case 1: OJO_I.reshape(50, 90, 100, 10);
BOCA.reshape(50, 600, 600, 50);
break;
case 2: OJO_I.reshape(50, 50, 100, 50);
OJO_D.reshape(650, 90, 100, 10);
break;
case 3: OJO_D.reshape(650, 50, 100, 50);
BOCA.reshape(50, 640, 600, 10);
break;
}
}
}
}