I have written an
Applet which opens in appletviewer but doesn't
open with a browser. I tried with IE5.5
Kindly help
The code is here :
import javax.swing.*;
import java.awt.*;
import java.applet.*;
import java.awt.event.*;
/*
<applet code = "Applicant.class" height = 300 width =500>
</applet>
*/
public class Applicant extends JApplet
{
//variabels for labels
JPanel panel;
//varaibles for labels
JLabel nc;
JLabel labelAppName;
JLabel labelAppAddress;
JLabel labelAppPosition;
JButton buttonAccept;
//variabels for data entry controls
JTextField nct;
JTextField textAppName;
JTextField textAppAddress;
JComboBox comboAppPosition;
//variables for the layout
GridBagLayout gl;
GridBagConstraints gbc;
public void init()
{
//initialise the layout variables
gl= new GridBagLayout();
gbc= new GridBagConstraints();
panel = (JPanel)getContentPane();
panel.setLayout(gl);
//initialise label controls
nc =new JLabel("Number of copies");
labelAppName= new JLabel("Name");
labelAppAddress= new JLabel("Address");
labelAppPosition = new JLabel("Country");
buttonAccept = new JButton("Order");
//initialize data entry controls
nct = new JTextField(5);
textAppName = new JTextField(30);
textAppAddress = new JTextField(30);
String positions[]={"India","US","Other"};
comboAppPosition= new JComboBox(positions);
//Add the Button
gbc.anchor = GridBagConstraints.NORTHEAST;
gbc.gridx = 8;
gbc.gridy = 11;
gl.setConstraints(buttonAccept,gbc);
panel.add(buttonAccept);
validateAction validateButton = new validateAction();
buttonAccept.addActionListener(validateButton);
//Add controls for Applicant Id
gbc.anchor=GridBagConstraints.NORTHWEST;
gbc.gridx= 1;
gbc.gridy= 1;
gbc.gridwidth=2;
gl.setConstraints(nc,gbc);
panel.add(nc);
gbc.anchor=GridBagConstraints.NORTHWEST;
gbc.gridx= 3;
gbc.gridy= 1;
gbc.gridwidth=1;
gl.setConstraints(nct,gbc);
panel.add(nct);
//Add controls for Applicant Name
gbc.anchor=GridBagConstraints.NORTHWEST;
gbc.gridx= 1;
gbc.gridy= 3;
gbc.gridwidth=2;
gl.setConstraints(labelAppName,gbc);
panel.add(labelAppName);
gbc.anchor=GridBagConstraints.NORTHWEST;
gbc.gridx= 3;
gbc.gridy= 3;
gbc.gridwidth=2;
gl.setConstraints(textAppName,gbc);
panel.add(textAppName);
//Add controls for Applicant Address
gbc.anchor=GridBagConstraints.NORTHWEST;
gbc.gridx= 1;
gbc.gridy= 5;
gbc.gridwidth=2;
gl.setConstraints(labelAppAddress,gbc);
panel.add(labelAppAddress);
gbc.anchor=GridBagConstraints.NORTHWEST;
gbc.gridx=3;
gbc.gridy= 5;
gbc.gridwidth=4;
gl.setConstraints(textAppAddress,gbc);
panel.add(textAppAddress);
//Add controls for Applicant Position
gbc.anchor=GridBagConstraints.NORTHWEST;
gbc.gridx= 1;
gbc.gridy= 7;
gbc.gridwidth=2;
gl.setConstraints(labelAppPosition,gbc);
panel.add(labelAppPosition);
gbc.anchor=GridBagConstraints.NORTHWEST;
gbc.gridx= 3;
gbc.gridy= 7;
gbc.gridwidth=2;
gl.setConstraints(comboAppPosition,gbc);
panel.add(comboAppPosition);
}
class validateAction implements ActionListener
{
public void actionPerformed(ActionEvent evt)
{
//extracting source of action
Object obj = evt.getSource();
if(obj == buttonAccept)
{
//Retrieving the number of copies from the textBox
String ncb = nct.getText();
//checking whether the user has entered the value
if(ncb.length() == 0)
{
//displ the error message on tyhe status bar
getAppletContext().showStatus("Please mention the number of copies");
return;
}
//Retrieving the Applicant Name from the textBox
String applicantName = textAppName.getText();
//checking whether the user has entered the value
if(applicantName.length() == 0)
{
//displ the error message on tyhe status bar
getAppletContext().showStatus("Name should be entered");
return;
}
//Retrieving the Applicant Address from the textBox
String applicantAddress = textAppAddress.getText();
//checking whether the user has entered the value
if(applicantAddress.length() == 0)
{
//displ the error message on tyhe status bar
getAppletContext().showStatus("Adress is required");
return;
}
getAppletContext().showStatus("Thank you for ordering the Bilingual Master");
}
}
}
}
------------------
Sathyajith