java applet program

Page 1 of 1

10 Replies - 1440 Views - Last Post: 04 August 2007 - 09:16 AM Rate Topic: ***-- 1 Votes

#1 zedenaka  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 32
  • Joined: 04-July 07

java applet program

Post icon  Posted 26 July 2007 - 06:23 AM

guys i need help on my program. i cant seem to find whats wrong. pls i need your help.

here is the .java code:
import java.awt.*;
import java.applet.*;
import java.awt.event.*;

public class mp1f extends Applet implements ActionListener

{

	 Label lnLbl=new Label("Last Name: ");
	 TextField lnTxt=new TextField(20);

	 Label fnLbl=new Label("First Name: ");
	 TextField fnTxt=new TextField(20);

	 Label miLbl=new Label("Middle Initial: ");
	 TextField miTxt=new TextField(20);

	 Label posLbl=new Label("Position: ");
	 TextField posTxt=new TextField(20);

	 Label hrsLbl=new Label("No. of Working Hours: ");
	 TextField hrsTxt=new TextField(20);

	 Button compButton=new Button("COMPUTE");

	 Button rstButton=new Button("RESET");

	 Label scLbl=new Label("Salary Computation:");

	 Label rateLbl=new Label("Rate: ");
	 TextField rateTxt=new TextField(20);

	 Label gpLbl=new Label("Gross Pay: ");
	 TextField gpTxt=new TextField(20);

	 Label dedLbl=new Label("Deductions:");

	 Label sssLbl=new Label("SSS: ");
	 TextField sssTxt=new TextField(20);

	 Label taxLbl=new Label("Tax: ");
	 TextField taxTxt=new TextField(20);

	 Label medLbl=new Label("Medicare: ");
	 TextField medTxt=new TextField(20);

	 Label tdLbl=new Label("Total Deductions: ");
	 TextField tdTxt=new TextField(20);

	 Label bonLbl=new Label("Bonus: ");
	 TextField bonTxt=new TextField(20);

	 Label npLbl=new Label("Net Pay of: ");
	 
	 
	 public void init()

	 {

		  add(lnLbl);
		  add(lnTxt);

		  add(fnLbl);
		  add(fnTxt);

		  add(miLbl);
		  add(miTxt);

		  add(posLbl);
		  add(posTxt);

		  add(hrsLbl);
		  add(hrsTxt);

		  add(compButton);
		  compButton.addActionListener(this);

		  add(rstButton);
		  rstButton.addActionListener(this);

		  add(scLbl);

		  add(rateLbl);
		  add(rateTxt);

		  add(gpLbl);
		  add(gpTxt);

		  add(dedLbl);
		
		  add(sssLbl);
		  add(sssTxt);

		  add(taxLbl);
		  add(taxTxt);

		  add(medLbl);
		  add(medTxt);

		  add(tdLbl);
		  add(tdTxt);

		  add(bonLbl);
		  add(bonTxt);

		  add(npLbl);

	 }

	 public void actionPerformed(ActionEvent e)

	 {

		  String arg,ln,fn,mi,pos;
		  int rate;
		  double gp,sss,tax,med,td,bon,np,hrs;				 

		  ln=lnTxt.getText();
		  fn=fnTxt.getText();
		  mi=miTxt.getText();
		  pos=posTxt.getText();
		  hrs=Double.parseDouble(hrsTxt.getText());   
		  gp=Double.parseDouble(gpTxt.getText());	 
		  sss=Double.parseDouble(sssTxt.getText());   
		  tax=Double.parseDouble(taxTxt.getText());   
		  med=Double.parseDouble(medTxt.getText());   
		  td=Double.parseDouble(tdTxt.getText());   
		  bon=Double.parseDouble(bonTxt.getText()); 
		  np=Double.parseDouble(npLbl.getText());   
		  rate=Integer.parseInt(rateTxt.getText());

		  arg=e.getActionCommand();
		  
		  if(pos=="manager")
		  {
		  rate=800;
		  rateTxt.setText("+rate"); 
		  }

		  else if(pos=="supervisor")
		  {
		  rate=500;
		  rateTxt.setText("+rate");
		  }

		  else if(pos=="employee")
		  {
		  rate=300;
		  rateTxt.setText("+rate");		  
		  }

		  else
		  {
		  rateTxt.setText("Wrong Input");
		  }
		  
		  arg=e.getActionCommand();												 

		  if(arg=="COMPUTE")
		  {
		  gp=rate*hrs;
		  gpTxt.setText("+gp");
							   
		  sss=(gp)*(0.5);
		  sssTxt.setText("+sss");

		  tax=(gp)*(0.10);
		  taxTxt.setText("+tax");

		  med=100;
		  medTxt.setText("+med");

		  td=(sss+tax)+med;
		  tdTxt.setText("+td");

		   if(bon>=20000)   
			{
			   bon=(gp)*(0.5);
			   bonTxt.setText("+bon"); 
			}
		   else if(bon<20000)
			{
			   bon=(gp)*(0.3);
			   bonTxt.setText("+bon");
			}

		  np=(gp-td)+bon;
		  npLbl.setText("Net Pay of" +fn+ "is" +np);

		  }

		  if(arg=="RESET")

		  {

		  lnTxt.setText(" ");
		  fnTxt.setText(" ");
		  miTxt.setText(" ");
		  posTxt.setText(" ");
		  hrsTxt.setText(" ");
		  rateTxt.setText(" ");
		  gpTxt.setText(" ");
		  sssTxt.setText(" ");
		  taxTxt.setText(" ");
		  medTxt.setText(" ");
		  tdTxt.setText(" ");
		  bonTxt.setText(" ");
		  npLbl.setText("Net Pay of:");

		  }

	  }
}



and here is for the html file

<html>
<applet code="mp1f.class" height=600 width=200>
</applet>
</html>



Is This A Good Question/Topic? 0
  • +

Replies To: java applet program

#2 Amadeus  Icon User is offline

  • g+ + -o drink whiskey.cpp
  • member icon

Reputation: 248
  • View blog
  • Posts: 13,506
  • Joined: 12-July 02

Re: java applet program

Posted 26 July 2007 - 06:31 AM

Great! Can you elaborate as to the problem? Are you getting errors? Undesired behaviuor?
Was This Post Helpful? 0
  • +
  • -

#3 zedenaka  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 32
  • Joined: 04-July 07

Re: java applet program

Posted 26 July 2007 - 06:40 AM

well you see when i run the program i can input the last name,first name, middle initial,position and no of hours worked. but when i click the compute button it wont create an output on the boxes below which should have the output. even when i click the clear button(which should clear all data) nothing happens. i think it is in this part which have the problem, but i cant seem to figure it out. pls help.

 public void actionPerformed(ActionEvent e)

	 {

		  String arg,ln,fn,mi,pos;
		  int rate;
		  double gp,sss,tax,med,td,bon,np,hrs;				 

		  ln=lnTxt.getText();
		  fn=fnTxt.getText();
		  mi=miTxt.getText();
		  pos=posTxt.getText();
		  hrs=Double.parseDouble(hrsTxt.getText());   
		  gp=Double.parseDouble(gpTxt.getText());	 
		  sss=Double.parseDouble(sssTxt.getText());   
		  tax=Double.parseDouble(taxTxt.getText());   
		  med=Double.parseDouble(medTxt.getText());   
		  td=Double.parseDouble(tdTxt.getText());   
		  bon=Double.parseDouble(bonTxt.getText()); 
		  np=Double.parseDouble(npLbl.getText());   
		  rate=Integer.parseInt(rateTxt.getText());

		  arg=e.getActionCommand();
		  
		  if(pos=="manager")
		  {
		  rate=800;
		  rateTxt.setText("+rate"); 
		  }

		  else if(pos=="supervisor")
		  {
		  rate=500;
		  rateTxt.setText("+rate");
		  }

		  else if(pos=="employee")
		  {
		  rate=300;
		  rateTxt.setText("+rate");		  
		  }

		  else
		  {
		  rateTxt.setText("Wrong Input");
		  }
		  
		  arg=e.getActionCommand();												 

		  if(arg=="COMPUTE")
		  {
		  gp=rate*hrs;
		  gpTxt.setText("+gp");
							   
		  sss=(gp)*(0.5);
		  sssTxt.setText("+sss");

		  tax=(gp)*(0.10);
		  taxTxt.setText("+tax");

		  med=100;
		  medTxt.setText("+med");

		  td=(sss+tax)+med;
		  tdTxt.setText("+td");

		   if(bon>=20000)   
			{
			   bon=(gp)*(0.5);
			   bonTxt.setText("+bon"); 
			}
		   else if(bon<20000)
			{
			   bon=(gp)*(0.3);
			   bonTxt.setText("+bon");
			}

		  np=(gp-td)+bon;
		  npLbl.setText("Net Pay of" +fn+ "is" +np);

		  }

		  if(arg=="RESET")

		  {

		  lnTxt.setText(" ");
		  fnTxt.setText(" ");
		  miTxt.setText(" ");
		  posTxt.setText(" ");
		  hrsTxt.setText(" ");
		  rateTxt.setText(" ");
		  gpTxt.setText(" ");
		  sssTxt.setText(" ");
		  taxTxt.setText(" ");
		  medTxt.setText(" ");
		  tdTxt.setText(" ");
		  bonTxt.setText(" ");
		  npLbl.setText("Net Pay of:");

		  }

	  }
}


Was This Post Helpful? 0
  • +
  • -

#4 zedenaka  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 32
  • Joined: 04-July 07

Re: java applet program

Posted 26 July 2007 - 06:50 AM

heres what the output should be but when i click on the compute button or the clear button it wont work

Attached image(s)

  • Attached Image

Was This Post Helpful? 0
  • +
  • -

#5 PennyBoki  Icon User is offline

  • system("revolution");
  • member icon

Reputation: 53
  • View blog
  • Posts: 2,334
  • Joined: 11-December 06

Re: java applet program

Posted 26 July 2007 - 06:52 AM

Hi you are comparing strings with ==, which is not ok
use the .equals("RESET") method, or better yet use the e.getSource method for the actionPerformed.
Was This Post Helpful? 0
  • +
  • -

#6 zedenaka  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 32
  • Joined: 04-July 07

Re: java applet program

Posted 26 July 2007 - 07:08 AM

View PostPennyBoki, on 26 Jul, 2007 - 06:52 AM, said:

Hi you are comparing strings with ==, which is not ok
use the .equals("RESET") method, or better yet use the e.getSource method for the actionPerformed.



hi PennyBoki! you see my problem is that.... im just new to java applets. our class has just started it.... sorry but i cannot understand what you told me.... we are just at the basics......so kindly elaborate more on what youre trying to tell me....or better yet....i beg you guys to modify my program using only the basics.....this program is as far as i go nothing more to it....

pls pls pls pls pls pls help me :(
Was This Post Helpful? 0
  • +
  • -

#7 PennyBoki  Icon User is offline

  • system("revolution");
  • member icon

Reputation: 53
  • View blog
  • Posts: 2,334
  • Joined: 11-December 06

Re: java applet program

Posted 26 July 2007 - 07:14 AM

instead of

Quote

if(arg=="RESET")

{

lnTxt.setText(" ");
fnTxt.setText(" ");
miTxt.setText(" ");
posTxt.setText(" ");
hrsTxt.setText(" ");
rateTxt.setText(" ");
gpTxt.setText(" ");
sssTxt.setText(" ");
taxTxt.setText(" ");
medTxt.setText(" ");
tdTxt.setText(" ");
bonTxt.setText(" ");
npLbl.setText("Net Pay of:");

}

}

do
if(e.getSource()==rstButton) //the name of the button

		  {

		  lnTxt.setText(" ");
		  fnTxt.setText(" ");
		  miTxt.setText(" ");
		  posTxt.setText(" ");
		  hrsTxt.setText(" ");
		  rateTxt.setText(" ");
		  gpTxt.setText(" ");
		  sssTxt.setText(" ");
		  taxTxt.setText(" ");
		  medTxt.setText(" ");
		  tdTxt.setText(" ");
		  bonTxt.setText(" ");
		  npLbl.setText("Net Pay of:");

		  }

	  }


Now do the same for the other button and now I ask you:
On what event you think these(below) would happen(take action)?

Quote

ln=lnTxt.getText();
fn=fnTxt.getText();
mi=miTxt.getText();
pos=posTxt.getText();
hrs=Double.parseDouble(hrsTxt.getText());
gp=Double.parseDouble(gpTxt.getText());
sss=Double.parseDouble(sssTxt.getText());
tax=Double.parseDouble(taxTxt.getText());
med=Double.parseDouble(medTxt.getText());
td=Double.parseDouble(tdTxt.getText());
bon=Double.parseDouble(bonTxt.getText());
np=Double.parseDouble(npLbl.getText());
rate=Integer.parseInt(rateTxt.getText());

Was This Post Helpful? 0
  • +
  • -

#8 zedenaka  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 32
  • Joined: 04-July 07

Re: java applet program

Posted 26 July 2007 - 08:51 AM

im not very sure about that cause our prof told us it used to convert a string to a number. thats why i used it. and because ln,fm,mi & pos are strings, i just use the .getText so i could input.

guys im trying to do my best but i cant still understand. pls help me correct the mistakes ive done. so i could easily understand. hope im not being rude. plsssssssssss :cry2:
Was This Post Helpful? 0
  • +
  • -

#9 jmanuelh  Icon User is offline

  • New D.I.C Head
  • member icon

Reputation: 2
  • View blog
  • Posts: 24
  • Joined: 18-November 06

Re: java applet program

Posted 26 July 2007 - 09:47 AM

Hi!

As penny said, to compare strings you need to use equals(), because string isn't a primitive variable like integer of char, so you have to use something like this:

if(pos.equals("manager"))


to compare 2 strings


To convert string to int you need to parse like this:

int converted = Integer.parseInt(ln); //where ln is, put the string variable you want to convert





J. Manuel

This post has been edited by jmanuelh: 26 July 2007 - 09:54 AM

Was This Post Helpful? 0
  • +
  • -

#10 zedenaka  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 32
  • Joined: 04-July 07

Re: java applet program

Posted 29 July 2007 - 07:00 PM

i hate this i cant still get it!!!!
sorry guys but im just a newbie in java.
or may i ask that this program is a liitle advance for me...
helpppppppppppppp
Was This Post Helpful? 0
  • +
  • -

#11 zedenaka  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 32
  • Joined: 04-July 07

Re: java applet program

Posted 04 August 2007 - 09:16 AM

thanks i already got this one
import java.awt.*;
import java.applet.*;
import java.awt.event.*;

public class mp1f extends Applet implements ActionListener,ItemListener

{

	 Label lnLbl=new Label("Last Name: ");
	 TextField lnTxt=new TextField(20);

	 Label fnLbl=new Label("First Name: ");
	 TextField fnTxt=new TextField(20);

	 Label miLbl=new Label("Middle Initial: ");
	 TextField miTxt=new TextField(20);

	 Label posLbl=new Label("Position: ");
	 TextField posTxt=new TextField(20);

	 Label hrsLbl=new Label("No. of Working Hours: ");
	 TextField hrsTxt=new TextField(20);

	 Button compButton=new Button("COMPUTE");

	 Button rstButton=new Button("RESET");

	 Label scLbl=new Label("Salary Computation:");

	 Label rateLbl=new Label("Rate: ");
	 TextField rateTxt=new TextField(20);

	 Label gpLbl=new Label("Gross Pay: ");
	 TextField gpTxt=new TextField(20);

	 Label dedLbl=new Label("Deductions:");

	 Label sssLbl=new Label("SSS: ");
	 TextField sssTxt=new TextField(20);

	 Label taxLbl=new Label("Tax: ");
	 TextField taxTxt=new TextField(20);

	 Label medLbl=new Label("Medicare: ");
	 TextField medTxt=new TextField(20);

	 Label tdLbl=new Label("Total Deductions: ");
	 TextField tdTxt=new TextField(20);

	 Label bonLbl=new Label("Bonus: ");
	 TextField bonTxt=new TextField(20);

	 Label npLbl=new Label("Net Pay of: ");
	 
	 
	 public void init()

	 {

		  add(lnLbl);
		  add(lnTxt);

		  add(fnLbl);
		  add(fnTxt);

		  add(miLbl);
		  add(miTxt);

		  add(posLbl);
		  add(posTxt);

		  add(hrsLbl);
		  add(hrsTxt);

		  add(compButton);
		  compButton.addActionListener(this);

		  add(rstButton);
		  rstButton.addActionListener(this);

		  add(scLbl);

		  add(rateLbl);
		  add(rateTxt);

		  add(gpLbl);
		  add(gpTxt);

		  add(dedLbl);
		
		  add(sssLbl);
		  add(sssTxt);

		  add(taxLbl);
		  add(taxTxt);

		  add(medLbl);
		  add(medTxt);

		  add(tdLbl);
		  add(tdTxt);

		  add(bonLbl);
		  add(bonTxt);

		  add(npLbl);

	 }

	 public void actionPerformed(ActionEvent e)

	 {

		  String arg,ln,fn,mi,pos;
		  int rate=0,med=100;
		  double gp,sss,tax,td,bon=0,np,hrs;				 
	  
	  hrs=Double.parseDouble(hrsTxt.getText());
	  fn=fnTxt.getText();
	  ln=lnTxt.getText();
	  mi=miTxt.getText();	  

	  pos=posTxt.getText();

	  arg=e.getActionCommand();	
					
		  if(pos.equals("manager"))
		  {
		  rate=800;
		  rateTxt.setText(""+rate); 
		  }

		  if(pos.equals("supervisor"))
		  {
		  rate=500;
		  rateTxt.setText(""+rate);
		  }

		  if(pos.equals("employee"))
		  {
		  rate=300;
		  rateTxt.setText(""+rate);		  
		  }
														  

		  if(arg=="COMPUTE") 
		  {
		  gp=rate*hrs;
		  gpTxt.setText(""+gp);
							   
		  sss=(gp)*(0.5);
		  sssTxt.setText(""+sss);

		  tax=(gp)*(0.10);
		  taxTxt.setText(""+tax);

		  medTxt.setText(""+med);

		  td=(sss+tax)+med;
		  tdTxt.setText(""+td);

		   if(bon>=20000)   
			{
			   bon=(gp)*(0.5);
			   bonTxt.setText(""+bon); 
			}
		   if(bon<20000)
			{
			   bon=(gp)*(0.3);
			   bonTxt.setText(""+bon);
			}

		  np=(gp-td)+bon;
		  npLbl.setText("Net Pay of  " +fn+ "  " +ln+ "  is  " +np);

		  }

		  if(arg=="RESET")

		  {

		  lnTxt.setText(" ");
		  fnTxt.setText(" ");
		  miTxt.setText(" ");
		  posTxt.setText(" ");
		  hrsTxt.setText(" ");
		  rateTxt.setText(" ");
		  gpTxt.setText(" ");
		  sssTxt.setText(" ");
		  taxTxt.setText(" ");
		  medTxt.setText(" ");
		  tdTxt.setText(" ");
		  bonTxt.setText(" ");
		  npLbl.setText("Net Pay of:");

		  }

	  }
}



thanks for your help!!!
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1