• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • paul wheaton
  • Jeanne Boyarsky
  • Ron McLeod
Sheriffs:
  • Paul Clapham
  • Liutauras Vilda
  • Devaka Cooray
Saloon Keepers:
  • Tim Holloway
  • Roland Mueller
Bartenders:

Applets

 
Ranch Hand
Posts: 132
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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 ]
 
Ranch Hand
Posts: 349
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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 ]
 
Author & Gold Digger
Posts: 7617
6
IntelliJ IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Applets are not an SCJP objective anymore.
I'm moving this to Applets...
 
Saloon Keeper
Posts: 28481
210
Android Eclipse IDE Tomcat Server Redhat Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
look! it's a bird! it's a plane! It's .... a teeny tiny ad
Smokeless wood heat with a rocket mass heater
https://woodheat.net
reply
    Bookmark Topic Watch Topic
  • New Topic