Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

show buttons in an applet

Status
Not open for further replies.

Beracosta

Programmer
Oct 25, 2000
47
0
0
SE
how do i show the buttons that i create in an applet with this code?

private JButton B1;
private JButton B2;

public void init()
{
// JApplet init with your code.

B1 = new JButton("Button 1");
B1.addActionListener(new ButtonActionListener()); // reg
B2 = new JButton("Button 2");
B2.addActionListener(new ButtonActionListener()); // reg

// more code you may want in the init.
}

// Inner Class for the Buttons.
class ButtonActionListener implements ActionListener
{
public void actionPerformed(ActionEvent ev)
{
if (ev.getSource() == B1)
{
// your code here for Button 1
}
if (ev.getSource() == B2)
{
// your code here for Button 2
}
}
}

pls help me!
 
you have to add the button to the applet. in the init() method, add these two lines of code:

add(B1);
add(B2);

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top