Chat LIVE With Programming Experts! There Are 23 Online Right Now...

Welcome to Dream.In.Code
Become a Java Expert!

Join 244,264 Java Programmers for FREE! Get instant access to thousands of Java experts, tutorials, code snippets, and more! There are 1,251 people online right now. Registration is fast and FREE... Join Now!




java applet program

 
Closed TopicStart new topic

java applet program

Rating  3
zedenaka
26 Jul, 2007 - 05:23 AM
Post #1

New D.I.C Head
*

Joined: 4 Jul, 2007
Posts: 32


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

here is the .java code:
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

CODE

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


User is offlineProfile CardPM
+Quote Post


Amadeus
RE: Java Applet Program
26 Jul, 2007 - 05:31 AM
Post #2

g++ -o drink whiskey.cpp
Group Icon

Joined: 12 Jul, 2002
Posts: 12,977



Thanked: 116 times
Dream Kudos: 25
My Contributions
Great! Can you elaborate as to the problem? Are you getting errors? Undesired behaviuor?
User is online!Profile CardPM
+Quote Post

zedenaka
RE: Java Applet Program
26 Jul, 2007 - 05:40 AM
Post #3

New D.I.C Head
*

Joined: 4 Jul, 2007
Posts: 32


My Contributions
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.

CODE

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:");

          }

      }
}

User is offlineProfile CardPM
+Quote Post

zedenaka
RE: Java Applet Program
26 Jul, 2007 - 05:50 AM
Post #4

New D.I.C Head
*

Joined: 4 Jul, 2007
Posts: 32


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




Attached thumbnail(s)
Attached Image
User is offlineProfile CardPM
+Quote Post

PennyBoki
RE: Java Applet Program
26 Jul, 2007 - 05:52 AM
Post #5

system("revolution");
Group Icon

Joined: 11 Dec, 2006
Posts: 2,075



Thanked: 12 times
Dream Kudos: 500
Expert In: Java,C++,C

My Contributions
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.
User is offlineProfile CardPM
+Quote Post

zedenaka
RE: Java Applet Program
26 Jul, 2007 - 06:08 AM
Post #6

New D.I.C Head
*

Joined: 4 Jul, 2007
Posts: 32


My Contributions
QUOTE(PennyBoki @ 26 Jul, 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.



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 sad.gif
User is offlineProfile CardPM
+Quote Post

PennyBoki
RE: Java Applet Program
26 Jul, 2007 - 06:14 AM
Post #7

system("revolution");
Group Icon

Joined: 11 Dec, 2006
Posts: 2,075



Thanked: 12 times
Dream Kudos: 500
Expert In: Java,C++,C

My Contributions
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
CODE
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());

User is offlineProfile CardPM
+Quote Post

zedenaka
RE: Java Applet Program
26 Jul, 2007 - 07:51 AM
Post #8

New D.I.C Head
*

Joined: 4 Jul, 2007
Posts: 32


My Contributions
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.gif
User is offlineProfile CardPM
+Quote Post

jmanuelh
RE: Java Applet Program
26 Jul, 2007 - 08:47 AM
Post #9

New D.I.C Head
Group Icon

Joined: 18 Nov, 2006
Posts: 23



Thanked: 2 times
My Contributions
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:

CODE
if(pos.equals("manager"))


to compare 2 strings


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

CODE
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 Jul, 2007 - 08:54 AM
User is offlineProfile CardPM
+Quote Post

zedenaka
RE: Java Applet Program
29 Jul, 2007 - 06:00 PM
Post #10

New D.I.C Head
*

Joined: 4 Jul, 2007
Posts: 32


My Contributions
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

User is offlineProfile CardPM
+Quote Post

zedenaka
RE: Java Applet Program
4 Aug, 2007 - 08:16 AM
Post #11

New D.I.C Head
*

Joined: 4 Jul, 2007
Posts: 32


My Contributions
thanks i already got this one
CODE

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!!!
User is offlineProfile CardPM
+Quote Post

Closed TopicStart new topic

Time is now: 7/4/09 12:11PM

Live Java Help!

Be Social

Dream.In.Code RSS Feed Dream.In.Code LinkedIn Group Follow Us On Twitter Fan Us On Facebook

Java Tutorials

Reference Sheets

Java Snippets

DIC Chatroom

Bye Bye Ads

Monthly Drawing

Thumb Drive

Top Contributors

Top 10 Kudos This Month