Can anybody help, I would like to put a button on a JApplet, like a 'Help'
button that opens a new web page when pressed, so that the original JApplet is
still visisble. can anybody suggest a way of doing this please?
This is my code for the JApplet
import java.applet.*;
import java.awt.*;
import java.awt.event.*;
import javax.swing.JComponent.*;
public class LogIn extends Applet implements ActionListener //implements
ActionListener
{
private Label nameLabel, passwordLabel;
private TextField nameField, passwordField;
private Button submitButton,bHelp;
private String helpfile;
public void init()
{
GridBagLayout gridbag = new GridBagLayout(); //initiates a new
gridbaglayout
GridBagConstraints constraints = new GridBagConstraints(); //assigns the
constraints
constraints.fill = GridBagConstraints.HORIZONTAL; //aligns the fill
setBackground(Color.white);
nameLabel = new Label("Enter User Name"); //Label constructer
constraints.gridx=0; //aligns label
constraints.gridy=0; //aligns label
constraints.weightx=1.0; //distributes space among columns
gridbag.setConstraints(nameLabel,constraints); //sets the constraints
nameLabel.setForeground(Color.black); //colour of the text
nameLabel.setFont(new Font("Serif", Font.BOLD,18)); //font type of text
add(nameLabel); //adds the label to the gridbag
nameField = new TextField(12);
constraints.gridx=0;
constraints.gridy=1;
constraints.weightx=1.0;
gridbag.setConstraints(nameField,constraints);
add(nameField);
passwordLabel = new Label(" Enter Password");
constraints.gridx=1;
constraints.gridy=0;
constraints.weightx=1.0;
gridbag.setConstraints(passwordLabel,constraints);
passwordLabel.setForeground(Color.black);
passwordLabel.setFont(new Font("Serif", Font.BOLD,18));
add( passwordLabel);
passwordField = new TextField(12);
constraints.gridx=1;
constraints.gridy=1;
constraints.weightx=1.0;
gridbag.setConstraints(passwordField,constraints);
add(passwordField);
submitButton = new Button("Submit");
constraints.gridx=2;
constraints.gridy=2;
constraints.weightx=1.0;
gridbag.setConstraints(submitButton,constraints);
submitButton.addActionListener(this);
add(submitButton);
bHelp = new Button("Help");
constraints.gridx=2;
constraints.gridy=1;
constraints.weightx=1.0;
gridbag.setConstraints(submitButton,constraints);
submitButton.addActionListener(this);
add(bHelp);
setSize(300,200); //stes the size of the display window
}
public void actionPerformed (ActionEvent e) //method to act on any actions
{
if (e.getSource() == submitButton) //if the submit button is clicked
{
nameField.setText("Thanks"); //put text in nameField just to make sure
the actionlistener is working
}
//end action performed
}
}