public class Button
extends Component
implements Accessible
Button b;
b1 = new Button("OK");
b2 = new Button("Quit");
b3 = new Button("Submit;
import java.awt.*;
import java.awt.event.*;
class ButtonDemo extends Frame implements
ActionListener
{
Button button1, button2, button3;
public ButtonDemo()
{
setLayout(new FlowLayout());
button1 = new Button("Reset");
button2 = new Button("Submit");
button3 = new Button("Quit");
button1.addActionListener(this);
button2.addActionListener(this);
button3.addActionListener(this);
add(button1);
add(button2);
add(button3);
setTitle("Buttons in AWT");
setSize(200, 150);
setVisible(true);
}
public void actionPerformed(ActionEvent e)
{
String str = e.getActionCommand();
if(str.equals("Reset"))
setBackground(Color.red);
else if(str.equals("Submit"))
setBackground(Color.green);
else if(str.equals("Quit"))
setBackground(Color.blue);
System.exit(0);
}
public static void main(String args[])
{
new ButtonDemo();
}
}
public class JButton
extends AbstractButton
implements Accessible
import javax.swing.JButton;
import javax.swing.JFrame;
public class JButtonDemo
{
JButtonDemo()
{
JFrame frame=new JFrame();
JButton b1 = new JButton("OK");
JButton b2 = new JButton("Quit");
b1.setBounds(50,50,90, 50);
b2.setBounds(150,50,90,50);
frame.add(b1);
frame.add(b2);
frame.setSize(300,200);
frame.setLayout(null);
frame.setVisible(true);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
}
public static void main(String[] args)
{
new JButtonDemo();
}
}