Anexo code
Código:
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
public class Applets extends JApplet implements ActionListener
{
//variables de referencia
JButton b1,b2,b3,b4,b5,b6;
int x=50, y=60, diametro=50, contador=0, n=0;
JPanel p1;
public void init ()
{
b1 = new JButton ("Aumentar");
b1.addActionListener(this);
b2 = new JButton ("Disminuir");
b2.addActionListener(this);
b3 = new JButton ("Derecha");
b3.addActionListener(this);
b4 = new JButton ("Izquierda");
b4.addActionListener(this);
b5 = new JButton ("Arriba");
b5.addActionListener(this);
b6 = new JButton ("Abajo");
b6.addActionListener(this);
setLayout (new FlowLayout ());
p1 = new JPanel ();
p1.setLayout(new GridLayout (3,3));
add(p1);
add(b1); add(b2); add(b3); add(b4); add(b5); add(b6);
p1.add(b1); p1.add(b2); p1.add(b3); p1.add(b4); p1.add(b5); p1.add(b6);
add (p1, BorderLayout.NORTH);
setSize (500, 500);
}
public void actionPerformed (ActionEvent e)
{
if (e.getSource()==b1)
{
diametro =diametro+15; //diametro = diametro+15; //diametro+=15;
repaint();
}
if (e.getSource()==b2)
{
diametro = diametro-8;
repaint();
}
if (e.getSource()==b3)
{
x = x+50;
repaint();
}
if (e.getSource()==b4)
{
x = x-30;
repaint();
}
if (e.getSource()==b5)
{
y = y-20;
repaint ();
}
if (e.getSource()==b6)
{
y = y+25;
repaint ();
}
}
public void paint (Graphics g)
{
Color fondo = g.getColor();
g.setColor(fondo);
g.setColor(Color.GREEN);
//g.fillOval(x, y, diametro, diametro);
g.drawOval(x, y, diametro, diametro);
showStatus ("Barra de Estado del Applet");
}
}