I compiled the code just fine. But It doesn't show on the webpage.
The error message is:
load: class C:\kenken\Xample1.class not found.
java.lang.ClassNotFoundException: C:.kenken.Xample1.class
at sun.applet.AppletClassLoader.findClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
at sun.applet.AppletClassLoader.loadClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
at sun.applet.AppletClassLoader.loadCode(Unknown Source)
at sun.applet.AppletPanel.createApplet(Unknown Source)
at sun.plugin.AppletViewer.createApplet(Unknown Source)
at sun.applet.AppletPanel.runLoader(Unknown Source)
at sun.applet.AppletPanel.run(Unknown Source)
at java.lang.Thread.run(Unknown Source)
I tried using appletviewer but it says "applet not initialized".
Here is the code
import java.applet.*;
import javax.swing.*;
import javax.swing.JOptionPane;
import java.awt.*;
import java.awt.event.*;
public class Xample1 extends Applet implements ActionListener, ItemListener
{
double otpay=0, gross=0, net=0, tax=0, sss=0, pagibig=0, med=0, tded=0;
Label lbl1 = new Label("Employee Number: ");
Label lbl2 = new Label("Employee Name: ");
Label lbl3 = new Label("No. of Hours Worked: ");
Label lbl4 = new Label("Rate per Hour: ");
Label lbl5 = new Label("Overtime Pay: ");
Label lbl6 = new Label("Gross Pay: ");
Label lbl7 = new Label("Deductions: ");
Label lbl8 = new Label("Total Deductions: ");
TextField txt1 = new TextField(15);
TextField txt2 = new TextField(15);
TextField txt3 = new TextField(15);
TextField txt4 = new TextField(15);
TextField txt5 = new TextField(15);
TextField txt6 = new TextField(15);
TextField txt7 = new TextField(15);
TextField txt8 = new TextField(15);
TextField txt9 = new TextField(15);
TextField txt10 = new TextField(15);
TextField txt11 = new TextField(15);
TextField txt12 = new TextField(15);
CheckboxGroup cbg = new CheckboxGroup();
Checkbox ot = new Checkbox("OT",false,cbg);
Button btnC1 = new Button("Compute 1");
Button btnC2 = new Button("Compute 2");
Button btnNet = new Button("Net Pay");
Button btnOk = new Button("OK");
Button btnClr = new Button("Clear");
Checkbox chk1 = new Checkbox("Tax");
Checkbox chk2 = new Checkbox("SSS");
Checkbox chk3 = new Checkbox("PagIbig");
Checkbox chk4 = new Checkbox("Medicare");
public void init()
{ add(lbl1); add(txt1); add(lbl2); add(txt2);
add(lbl3); add(txt3); add(lbl4); add(txt4);
add(lbl5); add(txt5); add(ot); add(lbl6); add(txt6);
add(btnC1); add(lbl7); add(chk1); add(txt7);
add(chk2); add(txt8); add(chk3); add(txt9);
add(chk4); add(txt10); add(lbl8); add(txt11);
add(btnC2);add(btnNet); add(txt12);
add(btnOk); add(btnClr);
txt5.setEnabled(false);
txt6.setEnabled(false);
txt7.setEnabled(false);
txt8.setEnabled(false);
txt9.setEnabled(false);
txt10.setEnabled(false);
txt11.setEnabled(false);
txt12.setEnabled(false);
btnOk.addActionListener(this);
btnClr.addActionListener(this);
btnC1.addActionListener(this);
btnC2.addActionListener(this);
btnNet.addActionListener(this);
ot.addItemListener(this);
chk1.addItemListener(this);
chk2.addItemListener(this);
chk3.addItemListener(this);
chk4.addItemListener(this);
}
public void actionPerformed(ActionEvent ae)
{
if(ae.getSource() == btnOk)
{
JOptionPane.showMessageDialog(null, "Employee Number: " + txt1.getText() + "\nEmployee Name: " + txt2.getText() + "\nGross Pay: " + String.valueOf(txt6.getText()) + "\nTotal Deductions: " + String.valueOf(txt11.getText()) + "\nNet Pay: " + String.valueOf(txt12.getText()), "Pay Slip", JOptionPane.INFORMATION_MESSAGE);
}
if(ae.getSource() == btnC1)
{ if (Double.parseDouble(txt3.getText()) > 40)
{ gross = (Double.parseDouble(txt4.getText()) * 40) + (Double.parseDouble(txt5.getText()));
txt6.setText(String.valueOf(gross));
}
else
{ gross = (Double.parseDouble(txt4.getText()) * Double.parseDouble(txt3.getText()));
txt6.setText(String.valueOf(gross));
}
}
if(ae.getSource() == btnC2)
{ tded = tax + sss + pagibig + med;
txt11.setText(String.valueOf(tded));
}
if(ae.getSource() == btnNet)
{ net = gross - tded;
txt12.setText(String.valueOf(net));
}
if(ae.getSource() == btnClr)
{
txt1.setText("");//number
txt2.setText("");//name
txt3.setText("");//hrs. worked
txt4.setText("");//rate per hr.
txt5.setText("");//ot pay
txt6.setText("");//gross pay
txt7.setText("");//tax
txt8.setText("");//sss
txt9.setText("");//pagibig
txt10.setText("");//medicare
txt11.setText("");//total deductions
txt12.setText("");//net pay
ot.setState(false);
chk1.setState(false);
chk2.setState(false);
chk3.setState(false);
chk4.setState(false);
txt1.requestFocus();
}
}
public void itemStateChanged(ItemEvent ie)
{
if(ot.getState() == true)
{ if (Double.parseDouble(txt3.getText()) > 40)
{ otpay = (Double.parseDouble(txt3.getText()) - 40) * (Double.parseDouble(txt4.getText())*1.5);
txt5.setText(String.valueOf(otpay));
}
else
{ ot.setState(false);
otpay = 0.00;
txt5.setText(String.valueOf(otpay));
}
}
if(chk1.getState() == true)
{ if(gross < 10000)
tax = gross * 0.05;
else if((gross >=10000) && (gross < 15000))
tax = gross * 0.075;
else if((gross >=15000) && (gross < 20000))
tax = gross * 0.10;
else if((gross >=20000) && (gross < 25000))
tax = gross * 0.15;
else if((gross >=25000) && (gross <= 30000))
tax = gross * 0.20;
else tax = gross * 0.25;
txt7.setText(String.valueOf(tax));
}
if(chk2.getState() == true)
{ sss = gross * 0.025;
txt8.setText(String.valueOf(sss));
}
if(chk3.getState() == true)
{ pagibig = gross * 0.02;
txt9.setText(String.valueOf(pagibig));
}
if(chk4.getState() == true)
{ med = gross * 0.03;
txt10.setText(String.valueOf(med));
}
}
}
And here is the html code
<html>
<applet code="C:\kenken\Xample1.class" height=250 width=200></applet>
</html>
I also tried to put the html file in the same folder so
<html>
<applet code="Xample1.class" height=250 width=200></applet>
</html>
but it also doesn't work. the same error message Xample1.class is not found.
But really, Xample.class is on that folder.
Please, I really need help. Thanks.