I have created my own payslip but then when I compiled it, they said that there are no more errors but I cannot view my output on the applet viewer............


is there something wrong with my code or is the viewer at fault here??

here is my code............

import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
public class payslip extends JFrame implements ActionListener
{

	private static int width=600;
	private static int height=300;
	private JLabel[] labelJL = new JLabel[17];
	private JTextField[] textJT = new JTextField[16];
	private JButton[] AddClearExit = new JButton[5];
	public payslip()
	{

		Container pane = getContentPane();
		pane.setBackground(Color.orange);
		setTitle("USING BUTTON EVENT");
		setSize(width,height);
		setLayout(null);

		labelJL[0] = new JLabel("MY PAYSLIP",0);
		labelJL[0].setFont(new Font("Comic Sans MS",Font.BOLD,30));
		labelJL[0].setLocation(400,20);
		labelJL[0].setSize(380,280);
		pane.add(labelJL[0]);

		labelJL[1] = new JLabel("Run Date",0);
		labelJL[1].setLocation(220,220);
		labelJL[1].setSize(100,20);
		pane.add(labelJL[1]);

		textJT[0] = new JTextField();
		textJT[0].setLocation(330,220);
		textJT[0].setSize(200,20);
		pane.add(textJT[0]);

		labelJL[2] = new JLabel("Days Worked",0);
		labelJL[2].setLocation(220,280);
		labelJL[2].setSize(100,20);
		pane.add(labelJL[2]);

		textJT[1] = new JTextField();
		textJT[1].setLocation(330,280);
		textJT[1].setSize(200,20);
		pane.add(textJT[1]);

		labelJL[3] = new JLabel("Basic Pay",0);
		labelJL[3].setLocation(220,320);
		labelJL[3].setSize(100,20);
		pane.add(labelJL[3]);

		textJT[2] = new JTextField();
		textJT[2].setLocation(330,320);
		textJT[2].setSize(200,20);
		textJT[2].setEditable(false);
		pane.add(textJT[2]);

		labelJL[4] = new JLabel("Overtime Worked",0);
		labelJL[4].setLocation(220,360);
		labelJL[4].setSize(100,20);
		pane.add(labelJL[4]);

		textJT[3] = new JTextField();
		textJT[3].setLocation(330,360);
		textJT[3].setSize(200,20);
		textJT[3].setEditable(false);
		pane.add(textJT[3]);

		labelJL[5] = new JLabel("Overtime Rate",0);
		labelJL[5].setLocation(220,390);
		labelJL[5].setSize(100,20);
		pane.add(labelJL[5]);

		textJT[4] = new JTextField();
		textJT[4].setLocation(330,390);
		textJT[4].setSize(200,20);
		textJT[4].setEditable(false);
		pane.add(textJT[4]);

		labelJL[6] = new JLabel("Cut off Date",0);
		labelJL[6].setLocation(660,220);
		labelJL[6].setSize(100,20);
		pane.add(labelJL[6]);

		textJT[5] = new JTextField();
		textJT[5].setLocation(760,220);
		textJT[5].setSize(200,20);
		textJT[5].setEditable(false);
		pane.add(textJT[5]);

		labelJL[7] = new JLabel("Name",0);
		labelJL[7].setLocation(660,280);
		labelJL[7].setSize(100,20);
		pane.add(labelJL[7]);

		textJT[6] = new JTextField();
		textJT[6].setLocation(760,280);
		textJT[6].setSize(200,20);
		pane.add(textJT[6]);

		labelJL[8] = new JLabel("Deduction",0);
		labelJL[8].setLocation(660,320);
		labelJL[8].setSize(100,20);
		pane.add(labelJL[8]);

		textJT[7] = new JTextField();
		textJT[7].setLocation(760,320);
		textJT[7].setSize(200,20);
		pane.add(textJT[7]);

		labelJL[9] = new JLabel("Tax Withheld",0);
		labelJL[9].setLocation(660,360);
		labelJL[9].setSize(100,20);
		pane.add(labelJL[9]);

		textJT[8] = new JTextField();
		textJT[8].setLocation(760,360);
		textJT[8].setSize(200,20);
		pane.add(textJT[8]);

		labelJL[10] = new JLabel("SSS",0);
		labelJL[10].setLocation(660,390);
		labelJL[10].setSize(100,20);
		pane.add(labelJL[10]);

		textJT[9] = new JTextField();
		textJT[9].setLocation(760,390);
		textJT[9].setSize(200,20);
		pane.add(textJT[9]);

		labelJL[11] = new JLabel("Medical",0);
		labelJL[11].setLocation(660,420);
		labelJL[11].setSize(760,20);
		pane.add(labelJL[11]);

		textJT[10] = new JTextField();
		textJT[10].setLocation(330,420);
		textJT[10].setSize(200,20);
		pane.add(textJT[10]);

		labelJL[12] = new JLabel("Pag-ibig",0);
		labelJL[12].setLocation(660,460);
		labelJL[12].setSize(100,20);
		pane.add(labelJL[12]);

		textJT[11] = new JTextField();
		textJT[11].setLocation(760,460);
		textJT[11].setSize(200,20);
		pane.add(textJT[11]);

		labelJL[13] = new JLabel("SSS Loan",0);
		labelJL[13].setLocation(660,480);
		labelJL[13].setSize(100,20);
		pane.add(labelJL[13]);

		textJT[12] = new JTextField();
		textJT[12].setLocation(760,480);
		textJT[12].setSize(200,20);
		pane.add(textJT[12]);

		labelJL[14] = new JLabel("Pag-ibig Loan",0);
		labelJL[14].setLocation(660,520);
		labelJL[14].setSize(100,20);
		pane.add(labelJL[14]);

		textJT[13] = new JTextField();
		textJT[13].setLocation(760,520);
		textJT[13].setSize(200,20);
		pane.add(textJT[13]);

		labelJL[15] = new JLabel("Total Deduction",0);
		labelJL[15].setLocation(660,560);
		labelJL[15].setSize(100,20);
		pane.add(labelJL[15]);

		textJT[14] = new JTextField();
		textJT[14].setLocation(760,560);
		textJT[14].setSize(200,20);
		pane.add(textJT[14]);

		labelJL[16] = new JLabel("Gross Pay",0);
		labelJL[16].setLocation(220,380);
		labelJL[16].setSize(100,20);
		pane.add(labelJL[16]);

		textJT[15] = new JTextField();
		textJT[15].setLocation(330,380);
		textJT[15].setSize(200,20);
		pane.add(textJT[15]);

		labelJL[17] = new JLabel("Net Pay",0);
		labelJL[17].setLocation(220,440);
		labelJL[17].setSize(100,20);
		pane.add(labelJL[17]);

		textJT[16] = new JTextField();
		textJT[16].setLocation(330,440);
		textJT[16].setSize(200,20);
		pane.add(textJT[16]);


		AddClearExit[0] = new JButton("Gross Pay");
		AddClearExit[0].setLocation(370,280);
		AddClearExit[0].setSize(150,20);
		AddClearExit[0].addActionListener(this);
		pane.add(AddClearExit[0]);

		AddClearExit[1] = new JButton("Net Pay");
		AddClearExit[1].setLocation(370,320);
		AddClearExit[1].setSize(150,20);
		AddClearExit[1].addActionListener(this);
		pane.add(AddClearExit[1]);

		AddClearExit[2] = new JButton("Total Deduction");
		AddClearExit[2].setLocation(370,360);
		AddClearExit[2].setSize(150,20);
		AddClearExit[2].addActionListener(this);
		pane.add(AddClearExit[2]);



		AddClearExit[3] = new JButton("Clear");
		AddClearExit[3].setLocation(450,470);
		AddClearExit[3].setSize(150,20);
		AddClearExit[3].addActionListener(this);
		pane.add(AddClearExit[3]);

		AddClearExit[4] = new JButton("Exit");
		AddClearExit[4].setLocation(629,470);
		AddClearExit[4].setSize(150,20);
		AddClearExit[4].addActionListener(this);
		pane.add(AddClearExit[4]);
		setVisible(true);
		setDefaultCloseOperation(EXIT_ON_CLOSE);


	}
		public void actionPerformed(ActionEvent ae)
		{
			String temp = "";
			long bp=0, otr=0, gp=0,d=0,tw=0, sss=0,m=0,p=0,sssl=0, pl=0,td=0;



	try
	{
		bp=Long.parseLong(textJT[2].getText());
                otr=Long.parseLong(textJT[4].getText());
                gp=Long.parseLong(textJT[15].getText());
                d=Long.parseLong(textJT[7].getText());
                tw=Long.parseLong(textJT[8].getText());
                sss=Long.parseLong(textJT[9].getText());
                m=Long.parseLong(textJT[10].getText());
                p=Long.parseLong(textJT[11].getText());
                sssl=Long.parseLong(textJT[12].getText());
                pl=Long.parseLong(textJT[13].getText());
                td=Long.parseLong(textJT[14].getText());

	}
		catch (Exception ne)
		{
		for(int x=0;x<16;textJT[x].setText(temp),x++);

		}


		if(ae.getActionCommand().equals("Gross Pay"))
			{temp+=grosspay(bp,otr);
					textJT[15].setText(temp);}
				else if(ae.getActionCommand().equals("Net Pay"))
				{temp+=netpay(gp,d);
						textJT[16].setText(temp);}
					else if(ae.getActionCommand().equals("Total Deduction"))
					{temp+=totaldeduction(d,tw,sss,m,p,sssl,pl);
							textJT[14].setText(temp);}

						 if(ae.getActionCommand().equals("Clear"))

				for(int x=0;x<16;textJT[x].setText(temp),x++);
				if(ae.getActionCommand().equals("Exit"))
					dispose();
		}



	public long grosspay(long x,long y)
	{
		return x*y;

	}
	public long netpay(long x,long y)
	{
		return x-y;
	}
	public long totaldeduction(long x,long y,long z,long a,long b,long c,long d)
	{
		return x+y+z+a+b+c+d;
	}

	public static void main (String args[])
	{
		new Button();

		}
}

Recommended Answers

All 6 Replies

Ur program is not an applet, extends it as below.
if the error message is applet not initialized, include the following in your coding:

payslip extends JApplet;
payslip.init();

Ur program is not an applet, extends it as below.
if the error message is applet not initialized, include the following in your coding:

payslip extends JApplet;
payslip.init();

i tried it but it displayed:
cannot find symbol method setTitle(java.lang.String)
cannot find symbol variable EXIT_ON_CLOSE
cannot find symbol method dispose()

@ NormR1, good advice prohibiting plagiarism and spoon feeding.

@akasekaihime
Example, the closeDefaultOperation is not a method used in applets.

Google why these methods gives you errors! suggest u remove them.

@ NormR1, good advice prohibiting plagiarism and spoon feeding.

@akasekaihime
Example, the closeDefaultOperation is not a method used in applets.

Google why these methods gives you errors! suggest u remove them.

AAAAAAAAHHHHHH! ok........

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.