i have 2 applets each in separate files. lets say i wan to click a button in applet1, and it will show applet2, hide applet1 and vice versa.
how can i achieve tat?

/**
 * @(#)ATM.java
 *
 *
 * @author 
 * @version 1.00 2010/3/1
 */

import java.awt.*;
import java.awt.event.*;
import javax.swing.*;

public class ATM extends JApplet implements ActionListener {
    
    JLabel lblAccount = new JLabel("Account Number");
    JTextField tfAccount = new JTextField(10);
    JLabel lblPassword = new JLabel("Password");
    JTextField tfPassword = new JTextField(4);
    JButton btnLogin = new JButton("Login");
    

    public void init() {
    	new ATM();
    }

    public ATM(){
	Container content = getContentPane();
    	content.setSize(400,70);
        JPanel controlArea = new JPanel(new GridLayout(2, 2));
        controlArea.add(lblAccount);
        controlArea.add(tfAccount);
        controlArea.add(lblPassword);
        controlArea.add(tfPassword);
        content.setLayout( new FlowLayout(FlowLayout.CENTER) );
        add(controlArea);
	add(btnLogin);
        btnLogin.addActionListener(this); 
        setVisible(true);
	}

    public void actionPerformed(ActionEvent e){
	setVisible(false);
    }
   
}
/**
 * @(#)ATM2.java
 *
 *
 * @author 
 * @version 1.00 2010/3/1
 */

import java.awt.*;
import java.awt.event.*;
import javax.swing.*;

public class ATM2 extends JApplet implements ActionListener {
    
    JLabel lblAccount2 = new JLabel("Account Number2");
    JTextField tfAccount2 = new JTextField(10);
    JLabel lblPassword2 = new JLabel("Password2");
    JTextField tfPassword2 = new JTextField(4);
    JButton btnLogin2 = new JButton("Login2");
    
    public void init(){
	new ATM2();
    }

    public ATM2(){
    	setSize(400,70);
        add(lblAccount2);
        add(tfAccount2);
        add(lblPassword2);
        add(tfPassword2);
	add(btnLogin2);
        btnLogin2.addActionListener(this); 	
    }

    public void actionPerformed(ActionEvent e){
	setVisible(false);
    }
   
}

stuck after setVisible(false);

Edited 6 Years Ago by chern4ever: n/a

This article has been dead for over six months. Start a new discussion instead.