// Applet that shows some very nice concepts involving
// components and java methods that can be used on them
// It shows some advanced features of JAVA that allow
// you to respond to user input (mouse clicks)
import java.awt.*;
import java.applet.*;
import java.net.*;
import java.awt.event.*;
public class Applet1 extends Applet implements ActionListener
{
Label heading = new Label("Use of Button components along with
methods");
int x3=5;
int position=1;
Font bigfont = new Font("ariel",Font.PLAIN,20);
Button slow = new Button("Press A");
Button fast = new Button("Press B");
public void init()
{
setLayout( null ); // position components abs.
heading.setFont(bigfont);
heading.setBounds(1,1,430,38);
slow.setBounds(80,150,80,40);
slow.addActionListener(this);
fast.setBounds(240,150,80,40);
fast.addActionListener(this);
add(heading);
add(slow);
add(fast);
}
public void actionPerformed(ActionEvent event)
{
if(event.getSource() == fast)
{
fast.setBounds(position,125,60,30);
add(fast);
}
else
{
slow.setBounds(position,75,100,20);
add(slow);
}
position+=10;
}
}
|