Win a copy of Re-engineering Legacy Software this week in the Refactoring forum
or Docker in Action in the Cloud/Virtualization forum!
  • 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,
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
Posts: 349
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 7610
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Applets are not an SCJP objective anymore.
I'm moving this to Applets...
 
Tim Holloway
Saloon Keeper
Pie
Posts: 18020
47
Android Eclipse IDE Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic