♠ Posted by Unknown in Core Java at 05:46
Example: Applet [Button Class]
/*Make
an Applet that Create Two Buttons named "Red" and "Blue"
when a button is
pressed
the background color of the applets is set to the color named by that button's
label.*/
import java.awt.*;
import java.awt.event.*;
import java.applet.*;
public class ButtonApplet extends Applet implements ActionListener  {
    Button btnRed, btnBlue;
    public void init() {
            btnRed = new Button("Red");
            btnBlue = new Button("Blue");
            add(btnRed);
            add(btnBlue);
            btnRed.addActionListener(this);
            btnBlue.addActionListener(this);
    }
    public void actionPerformed(ActionEvent ae){
            if(ae.getSource() == btnRed)
                    setBackground(Color.red);
            else if(ae.getSource() == btnBlue)
                            setBackground(Color.blue);
    }
}
 


 
 
 
 
 
 
1 comments:
tatti code hai
Post a Comment