This week's book giveaway is in the OO, Patterns, UML and Refactoring forum.
We're giving away four copies of Refactoring for Software Design Smells: Managing Technical Debt and have Girish Suryanarayana, Ganesh Samarthyam & Tushar Sharma on-line!
See this thread for details.
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes Applets Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "Applets" Watch "Applets" New topic


Patrick Mugabe
Ranch Hand

Joined: Jan 08, 2002
Posts: 132
Hi everyone!!!
I have an applet which has 3 Labels and 3 TextFields and an OK Button. I want to bring up another applet when I click the OK Button. The two applets sit on the same directory on my machine.
How would I achieve this goal, ...Ideas PLEASE.
In case you may want to look at the code, here it is:
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
public class Applet1 extends JApplet implements ActionListener
JLabel labelId, labelName, labelSurname;
JTextField txtId, txtName, txtSurname;
JButton btOK;
GridBagConstraints gbc;
GridBagLayout gbl;
JPanel panel;
public void init()
labelId = new JLabel("Employee ID:");
txtId = new JTextField("00000",5);
labelName = new JLabel("Name:");
txtName = new JTextField(15);
labelSurname = new JLabel("Surname");
txtSurname = new JTextField(15);
btOK = new JButton(" OK ");
gbc= new GridBagConstraints();
gbl = new GridBagLayout();
panel = (JPanel)getContentPane();
gbc.anchor = GridBagConstraints.NORTHWEST;
gbc.gridx = 2;
gbc.gridy = 2;
gbl.setConstraints(labelId, gbc);
gbc.anchor = GridBagConstraints.NORTHWEST;
gbc.gridx = 4;
gbc.gridy = 2;
gbl.setConstraints(txtId, gbc);
gbc.anchor = GridBagConstraints.NORTHWEST;
gbc.gridx = 2;
gbc.gridy = 4;
gbl.setConstraints(labelName, gbc);
gbc.anchor = GridBagConstraints.NORTHWEST;
gbc.gridx = 4;
gbc.gridy = 4;
gbl.setConstraints(txtName, gbc);
gbc.anchor = GridBagConstraints.NORTHWEST;
gbc.gridx = 2;
gbc.gridy = 6;
gbl.setConstraints(labelSurname, gbc);
gbc.anchor = GridBagConstraints.NORTHWEST;
gbc.gridx = 4;
gbc.gridy = 6;
gbl.setConstraints(txtSurname, gbc);
gbc.anchor = GridBagConstraints.NORTHWEST;
gbc.gridy = 3;
gbc.gridy = 8;
gbl.setConstraints(btOK, gbc);

public void actionPerformed(ActionEvent e)
//This is where the code that brings up the other
//applet should come
Rob Ross

Joined: Jan 07, 2002
Posts: 2205
What do you mean "bring up another applet?"
Do you want to go to another web page and display another applet,or do you want to open an applet window external to the browser?

SCJP 1.4
Patrick Mugabe
Ranch Hand

Joined: Jan 08, 2002
Posts: 132
Re: Rob Ross's Response
I will try to eplain what I mean by saying "bring up an applet".
I have two applets in the same directory namely Apple1 and Applet2.
I want to get the screen for Applet2 when I click the OK button on Applet1. I hope you are answered and that you are now in a position to help.
William Brogden
Author and all-around good cowpoke

Joined: Mar 22, 2000
Posts: 13001
You can use the showDocument method of the AppletContext class to force the browser to switch to another page containing the other applet.
You can't make the second applet replace the current applet on the same page because the applet tag defines which applet class is loaded.
Maulin Vasavada
Ranch Hand

Joined: Nov 04, 2001
Posts: 1873
i would say "its not entirely" impossible to do what patrick wants but that'll require unecessary extra coding and u know kind of "fixing".
here is what u can do i guess,
-have first applet in ur html,
-make ur java applet code to work with Java Script using JSObject from netscape.javascript package available.
-notify JavaScript code from applet when "Ok" button is pressed in the applet.
- on that notification write DHTML to overwrite previous HTML for the first applet using document.write() method
-one point u need to keep in mind is, u gotta have some kind of HTML Layer (if NN4.77) or some ID field where u can replace inner content using DHTML.
i mean sth like this,
i 've table and TD tag in which first applet is there,
<table><tr><td ID="firstApplet">..applet tag code...</td></tr></table>
now in JavaScript u can replace using,
firstApplet.innerHTML('..applet tag code for second applet..')
i guess this shd work. i've not tired it tho. but that's lot of work, isnt it? instead just have another html page
I agree. Here's the link:
subject: Applets
It's not a secret anymore!