FileDocCategorySizeDatePackage
JButtonDemo.javaAPI DocExample1807Wed Jan 16 16:43:08 GMT 2002None

JButtonDemo

public class JButtonDemo extends JApplet implements ActionListener

Fields Summary
JTextField
jtf
Constructors Summary
Methods Summary
public voidactionPerformed(java.awt.event.ActionEvent ae)

    jtf.setText(ae.getActionCommand());
  
public voidinit()

  //initialise tha applet
    // Get content pane, we need to do this for swing because
    // there are more than one panes (only 1 for an awt applet)
    Container contentPane = getContentPane();
    contentPane.setLayout(new FlowLayout());
	
	
    // Add buttons to content pane
    ImageIcon canada = new ImageIcon("but_register[1].gif"); //load an icon
    JButton jb = new JButton(canada); //attach the icon to a new button
    
    jb.setActionCommand("Register");
    jb.addActionListener(this);
    contentPane.add(jb);  //notice we call the add method of the contentPane (for awt we just called add from the applet itself)

    ImageIcon germany = new ImageIcon("88x31[1].gif");
    jb = new JButton(germany);
    jb.setActionCommand("Swift Desk");
    jb.addActionListener(this);
    contentPane.add(jb);

    ImageIcon uk = new ImageIcon("property_bookit_button[1].gif");
    jb = new JButton(uk);
    jb.setActionCommand("Hotel Booking");
    jb.addActionListener(this);
    contentPane.add(jb);

    ImageIcon egypt = new ImageIcon("logo[1].gif");
    jb = new JButton(egypt);
    jb.setActionCommand("Barclaycard");
    jb.addActionListener(this);
    contentPane.add(jb);

    // Add text field to content pane
    jtf = new JTextField(15);
    contentPane.add(jtf);