click on button opens the new frame in applet
I have applet with main frame with two buttons and both buttons on click are invoking new frame in application its working but when I changed to applet the main() I have changed but i donot know how to chnage for frame which are invoked by button click. I am showing below the code of my one button
class Button2 extends JFrame implements ActionListener {
void Button2(){
super("Button2");
icon = new ImageIcon("c:/arphoto.jpg");
JLabel iconlabel =new JLabel(icon, JLabel.CENTER);
JPanel panel = new JPanel();
panel.add(iconlabel);
getContentPane().add(panel);
addWindowListener(new WindowEventHandler());
pack();
}
class WindowEventHandler extends WindowAdapter{
public void windowClosing(WindowEvent e) {
System.exit(0);
}
}
public void actionPerformed(ActionEvent AE){
if (AE.getSource() == button2){
new Button2();
setVisible(true);
}//end of if
}//end of actionPerformed
}//end of class button2
pls help
[1061 byte] By [
seemapa] at [2007-10-2 15:09:41]

you need to declare 2 different frames or mutiple different frames and then add specific panels on those frames. Initially set your main frame visibiity to true and rest of them to false and then change it later depend on which button is clicked and which frame you would like to open.
Check this out, it maybe what you want:
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
public class Button2 extends JFrame implements ActionListener {
JButton button2;
ImageIcon icon;
JFrame mainFrm, frm2;
JPanel panel, panel2;
JLabel iconlabel, newLabel;
public Button2() {
mainFrm = new JFrame("Main Frame");
frm2 = new JFrame ("New Frame");
panel = new JPanel();
panel2 = new JPanel();
mainFrm.setSize(new Dimension(50, 50));
frm2.setSize(new Dimension(50, 50));
panel.setPreferredSize(new Dimension(200, 50));
panel2.setPreferredSize(new Dimension(200, 50));
mainFrm.getContentPane().add(panel);
frm2.getContentPane().add(panel2);
addExtraComponents ();
mainFrm.pack();
mainFrm.setVisible(true);
frm2.pack();
frm2.setVisible(false);
}
public void addExtraComponents () {
// icon = new ImageIcon("c:/arphoto.jpg");
// JLabel iconlabel =new JLabel(icon, JLabel.CENTER);
JLabel iconlabel = new JLabel("Frame one", JLabel.CENTER);
newLabel = new JLabel("I'm in new Frame", JLabel.CENTER);
button2 = new JButton ("Click Me");
button2.addActionListener(this);
panel.add(iconlabel);
panel.add(button2);
panel2.add(newLabel);
}
public void actionPerformed(ActionEvent AE){
if (AE.getSource() == button2){
mainFrm.setVisible(false);
frm2.setVisible(true);
}//end of if
}//end of actionPerformed
public static void main (String args []) {
new Button2();
}
}//end of class button2
Have fun !