• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Applets

 
Patrick Mugabe
Ranch Hand
Posts: 132
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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();
panel.setLayout(gbl);
gbc.anchor = GridBagConstraints.NORTHWEST;
gbc.gridx = 2;
gbc.gridy = 2;
gbl.setConstraints(labelId, gbc);
panel.add(labelId);
gbc.anchor = GridBagConstraints.NORTHWEST;
gbc.gridx = 4;
gbc.gridy = 2;
gbl.setConstraints(txtId, gbc);
panel.add(txtId);
gbc.anchor = GridBagConstraints.NORTHWEST;
gbc.gridx = 2;
gbc.gridy = 4;
gbl.setConstraints(labelName, gbc);
panel.add(labelName);
gbc.anchor = GridBagConstraints.NORTHWEST;
gbc.gridx = 4;
gbc.gridy = 4;
gbl.setConstraints(txtName, gbc);
panel.add(txtName);
gbc.anchor = GridBagConstraints.NORTHWEST;
gbc.gridx = 2;
gbc.gridy = 6;
gbl.setConstraints(labelSurname, gbc);
panel.add(labelSurname);
gbc.anchor = GridBagConstraints.NORTHWEST;
gbc.gridx = 4;
gbc.gridy = 6;
gbl.setConstraints(txtSurname, gbc);
panel.add(txtSurname);
gbc.anchor = GridBagConstraints.NORTHWEST;
gbc.gridy = 3;
gbc.gridy = 8;
gbl.setConstraints(btOK, gbc);
panel.add(btOK);

}
public void actionPerformed(ActionEvent e)
{
//This is where the code that brings up the other
//applet should come
}
}
 
Rob Ross
Bartender
Posts: 2205
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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?
Rob
 
Patrick Mugabe
Ranch Hand
Posts: 132
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Rancher
Posts: 13055
6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
Bill
 
Maulin Vasavada
Ranch Hand
Posts: 1873
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Well,
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
regards
maulin.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic