aspose file tools*
The moose likes Applets and the fly likes Applets Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Applets
Bookmark "Applets" Watch "Applets" New topic
Author

Applets

Patrick Mugabe
Ranch Hand

Joined: Jan 08, 2002
Posts: 132
Hi,
I have asked a similar question before but I still need more ideas.
I am working on my final year project and I am using Java.
I want to be able to access an applet on the click of a button using Java. Is that possible and if it is, how can it be done.
Can somebody give me an example, I would appreciate it very much because it would probably help me a lot.
In case you need to see my code:

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(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
}
}

Please format my code.
[ February 19, 2002: Message edited by: Patrick Mugabe ]
[ February 19, 2002: Message edited by: Patrick Mugabe ]
Rashid Ali
Ranch Hand

Joined: Jan 16, 2001
Posts: 349
I think you have to load the .html file in which applet tag is defined that will load the another applet for you when the button is pressed.
And i think you will have to defined the path of the above .html file in the url and encode it in the actionPerformed() method.
It's a hint, i am not sure that it will work. But hope it may help you. make your logic and try to apply it.
Hope other people here may suggest you better.
And it would be better if you post this question in the separate Applet Forum here in JavaRanch where you will get the answer more quickly.
Good luck with your final project.
Rashid Ali
[ February 19, 2002: Message edited by: Rashid Ali ]
Valentin Crettaz
Gold Digger
Sheriff

Joined: Aug 26, 2001
Posts: 7610
Applets are not an SCJP objective anymore.
I'm moving this to Applets...


SCJP 5, SCJD, SCBCD, SCWCD, SCDJWS, IBM XML
[Blog] [Blogroll] [My Reviews] My Linked In
Tim Holloway
Saloon Keeper

Joined: Jun 25, 2001
Posts: 16065
    
  21

I'm not sure what you mean here when you say "access an Applet". Normally you embed a reference to an Applet in an HTML page and it is automatically downloaded and executed when the page is displayed.


Customer surveys are for companies who didn't pay proper attention to begin with.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Applets