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

Join 150,129 Java Programmers for FREE! Get instant access to thousands of Java experts, tutorials, code snippets, and more! There are 2,088 people online right now. Registration is fast and FREE... Join Now!




pay roll system

 
Reply to this topicStart new topic

pay roll system, needs debuging but i can't seem to see the error

wasua
26 Jun, 2008 - 04:40 AM
Post #1

New D.I.C Head
*

Joined: 19 Jun, 2008
Posts: 2

// JavaScript Document
<html>
<head>
</head>
<body>
<javascript="text/javascript">

import java.io.*;
import java.awt.*;
import java.awt.Color.*;
import java.awt.event.*;
import java.applet.*;


/*<applet code=train2.class height=300 width=600></applet>*/


public class train2 extends Applet implements
ActionListener,ItemListener

{
Label name,amount,seats,number;
TextField na,am,sts,nr;
TextArea t;
Choice css;

Checkbox si,sr;
CheckboxGroup g;

Button b,cancel;
int s,c,d;
int n1=400;
int n2=250;
int n3=100;

public void init()
{
setBackground(Color.yellow);
setForeground(Color.red);
setLayout(new FlowLayout());

na=new TextField(20);
am=new TextField(20);
sts=new TextField(20);
nr=new TextField(20);


name=new Label("NAME");
amount=new Label("AMOUNT");
seats=new Label("SEATS");
number=new Label("REQUIRED NO OF SEATS");

css=new Choice();
css.add("A.C SLEEPER");
css.add("FIRST CLASS");
css.add("SECOND CLASS");

t=new TextArea(40,45);

g=new CheckboxGroup();
si=new Checkbox("SATAPTI",g,false);
sr=new Checkbox("SABARI",g,false);

b=new Button("SUBMIT");
cancel=new Button("CANCEL");

add(name);
add(na);

add(seats);
add(sts);

add(number);
add(nr);


add(si);
add(sr);

add(css);

add(cool.gif;

add(amount);
add(am);

add(t);
add(cancel);

css.addItemListener(this);
b.addActionListener(this);
si.addItemListener (this);
sr.addItemListener (this);


}
public void actionPerformed(ActionEvent ae)
{

if(b.getActionCommand().equals("SUBMIT"))
{
d=Integer.parseInt(nr.getText());
s=(Integer.parseInt(sts.getText()))-d;

if(css.getSelectedItem().equals("A.C SLEEPER"))
{
am.setText("400");
}
else if(css.getSelectedItem().equals("FIRST CLASS"))
{
am.setText("250");
}
else
{
am.setText("100");
}

}


c=((Integer.parseInt(am.getText()))*(Integer.parseInt(nr.getText())));
t.setText("NAME:"+na.getText()+"
"+"After reservation total no.of
seats are:"
+s+"
"+"Train name
:"+g.getSelectedCheckbox().getLabel()+"
"+"Class:"+
css.getSelectedItem()+ "Total number of Rs :"+c);

if(cancel.getActionCommand().equals("CANCEL"))
{
repaint();
}

}

public void itemStateChanged(ItemEvent ie)
{

}

}

import java.io.*;
import java.awt.*;
import java.awt.Color.*;
import java.awt.event.*;
import java.applet.*;


/*<applet code=train2.class height=300 width=600></applet>*/


public class train2 extends Applet implements
ActionListener,ItemListener

{
Label name,amount,seats,number;
TextField na,am,sts,nr;
TextArea t;
Choice css;

Checkbox si,sr;
CheckboxGroup g;

Button b,cancel;
int s,c,d;
int n1=400;
int n2=250;
int n3=100;

public void init()
{
setBackground(Color.yellow);
setForeground(Color.red);
setLayout(new FlowLayout());

na=new TextField(20);
am=new TextField(20);
sts=new TextField(20);
nr=new TextField(20);


name=new Label("NAME");
amount=new Label("AMOUNT");
seats=new Label("SEATS");
number=new Label("REQUIRED NO OF SEATS");

css=new Choice();
css.add("A.C SLEEPER");
css.add("FIRST CLASS");
css.add("SECOND CLASS");

t=new TextArea(40,45);

g=new CheckboxGroup();
si=new Checkbox("SATAPTI",g,false);
sr=new Checkbox("SABARI",g,false);

b=new Button("SUBMIT");
cancel=new Button("CANCEL");

add(name);
add(na);

add(seats);
add(sts);

add(number);
add(nr);


add(si);
add(sr);

add(css);

add(cool.gif;

add(amount);
add(am);

add(t);
add(cancel);

css.addItemListener(this);
b.addActionListener(this);
si.addItemListener (this);
sr.addItemListener (this);


}
public void actionPerformed(ActionEvent ae)
{

if(b.getActionCommand().equals("SUBMIT"))
{
d=Integer.parseInt(nr.getText());
s=(Integer.parseInt(sts.getText()))-d;

if(css.getSelectedItem().equals("A.C SLEEPER"))
{
am.setText("400");
}
else if(css.getSelectedItem().equals("FIRST CLASS"))
{
am.setText("250");
}
else
{
am.setText("100");
}

}


c=((Integer.parseInt(am.getText()))*(Integer.parseInt(nr.getText())));
t.setText("NAME:"+na.getText()+"
"+"After reservation total no.of
seats are:"
+s+"
"+"Train name
:"+g.getSelectedCheckbox().getLabel()+"
"+"Class:"+
css.getSelectedItem()+ "Total number of Rs :"+c);

if(cancel.getActionCommand().equals("CANCEL"))
{
repaint();
}

}

public void itemStateChanged(ItemEvent ie)
{

}

}
</script>
</body>
</html>
User is offlineProfile CardPM
+Quote Post

pbl
RE: Pay Roll System
26 Jun, 2008 - 03:30 PM
Post #2

D.I.C Lover
Group Icon

Joined: 6 Mar, 2008
Posts: 3,587



Thanked: 233 times
Dream Kudos: 75
My Contributions
Didn't even know you can put Java code into an HTML file....
You sure you are not mixing Java and JavaScript ?

As far as Java is concerned your code won't even compile


CODE


t.setText("NAME:"+na.getText()+"
"+"After reservation total no.of
seats are:"
+s+"
"+"Train name
:"+g.getSelectedCheckbox().getLabel()+"
"+"Class:"+
css.getSelectedItem()+ "Total number of Rs :"+c);


The + should not be between ""

May be should look like this

CODE

        t.setText("NAME:"+na.getText() +
                "After reservation total no.of seats are:"
                    +s+
                    g.getSelectedCheckbox().getLabel()
                        + "Class:" +
                            css.getSelectedItem()+ "Total number of Rs :"+c);


Please post your code like this
code.gif

And you put twice your class train2 in your message

This post has been edited by pbl: 26 Jun, 2008 - 03:33 PM
User is offlineProfile CardPM
+Quote Post

RoboAlex
RE: Pay Roll System
26 Jun, 2008 - 09:17 PM
Post #3

New D.I.C Head
*

Joined: 26 Jun, 2008
Posts: 39



Thanked: 3 times
My Contributions
Ok, well, I'll start with posting the code, formatted properly (as well as changing class names to capitalization as it should be)

CODE
import java.awt.*;
import java.awt.event.*;
import java.applet.*;


/* <applet code=train2.class height=300 width=600></applet> */


public class Train extends Applet implements ActionListener, ItemListener

{
    Label name, amount, seats, number;
    TextField na, am, sts, nr;
    TextArea t;
    Choice css;

    Checkbox si, sr;
    CheckboxGroup g;

    Button b, cancel;
    int s, c, d;
    int n1= 400;
    int n2= 250;
    int n3= 100;

    public void init()
    {
        setBackground(Color.yellow);
        setForeground(Color.red);
        setLayout(new FlowLayout());

        na= new TextField(20);
        am= new TextField(20);
        sts= new TextField(20);
        nr= new TextField(20);


        name= new Label("NAME");
        amount= new Label("AMOUNT");
        seats= new Label("SEATS");
        number= new Label("REQUIRED NO OF SEATS");

        css= new Choice();
        css.add("A.C SLEEPER");
        css.add("FIRST CLASS");
        css.add("SECOND CLASS");

        t= new TextArea(40, 45);

        g= new CheckboxGroup();
        si= new Checkbox("SATAPTI", g, false);
        sr= new Checkbox("SABARI", g, false);

        b= new Button("SUBMIT");
        cancel= new Button("CANCEL");

        add(name);
        add(na);

        add(seats);
        add(sts);

        add(number);
        add(nr);


        add(si);
        add(sr);

        add(css);

        add(cool.gif);

        add(amount);
        add(am);

        add(t);
        add(cancel);

        css.addItemListener(this);
        b.addActionListener(this);
        si.addItemListener(this);
        sr.addItemListener(this);


    }

    public void actionPerformed(ActionEvent ae)
    {

        if(b.getActionCommand().equals("SUBMIT"))
        {
            d= Integer.parseInt(nr.getText());
            s= (Integer.parseInt(sts.getText())) - d;

            if(css.getSelectedItem().equals("A.C SLEEPER"))
            {
                am.setText("400");
            }
            else if(css.getSelectedItem().equals("FIRST CLASS"))
            {
                am.setText("250");
            }
            else
            {
                am.setText("100");
            }

        }


        c= ((Integer.parseInt(am.getText())) * (Integer.parseInt(nr.getText())));
        t.setText("NAME:" + na.getText() + "After reservation total no.of seats are:" + s + "Train name:" + g.getSelectedCheckbox().getLabel() + ""
                + "Class:" + css.getSelectedItem() + "Total number of Rs :" + c);

        if(cancel.getActionCommand().equals("CANCEL"))
        {
            repaint();
        }

    }

    public void itemStateChanged(ItemEvent ie)
    {

    }

}


and

CODE
import java.awt.*;
import java.awt.event.*;
import java.applet.*;

public class Train2 extends Applet implements ActionListener, ItemListener
{
    Label name, amount, seats, number;
    TextField na, am, sts, nr;
    TextArea t;
    Choice css;


    Checkbox si, sr;
    CheckboxGroup g;

    Button b, cancel;
    int s, c, d;
    int n1= 400;
    int n2= 250;
    int n3= 100;

    public void init()
    {
        setBackground(Color.yellow);
        setForeground(Color.red);
        setLayout(new FlowLayout());

        na= new TextField(20);
        am= new TextField(20);
        sts= new TextField(20);
        nr= new TextField(20);


        name= new Label("NAME");
        amount= new Label("AMOUNT");
        seats= new Label("SEATS");
        number= new Label("REQUIRED NO OF SEATS");

        css= new Choice();
        css.add("A.C SLEEPER");
        css.add("FIRST CLASS");
        css.add("SECOND CLASS");

        t= new TextArea(40, 45);

        g= new CheckboxGroup();
        si= new Checkbox("SATAPTI", g, false);
        sr= new Checkbox("SABARI", g, false);

        b= new Button("SUBMIT");
        cancel= new Button("CANCEL");

        add(name);
        add(na);

        add(seats);
        add(sts);

        add(number);
        add(nr);


        add(si);
        add(sr);

        add(css);

        add(cool.gif);

        add(amount);
        add(am);

        add(t);
        add(cancel);

        css.addItemListener(this);
        b.addActionListener(this);
        si.addItemListener(this);
        sr.addItemListener(this);
    }

    public void actionPerformed(ActionEvent ae)
    {

        if(b.getActionCommand().equals("SUBMIT"))
        {
            d= Integer.parseInt(nr.getText());
            s= (Integer.parseInt(sts.getText())) - d;

            if(css.getSelectedItem().equals("A.C SLEEPER"))
            {
                am.setText("400");
            }
            else if(css.getSelectedItem().equals("FIRST CLASS"))
            {
                am.setText("250");
            }
            else
            {
                am.setText("100");
            }

        }


        c= ((Integer.parseInt(am.getText())) * (Integer.parseInt(nr.getText())));
        t.setText("NAME:" + na.getText() + "" + "After reservation total no.ofseats are:" + s + "    " + "Train name"
                + g.getSelectedCheckbox().getLabel() + "" + "Class:" + css.getSelectedItem() + "Total number of Rs :" + c);

        if(cancel.getActionCommand().equals("CANCEL"))
        {
            repaint();
        }

    }

    @Override
    public void itemStateChanged(ItemEvent e)
    {
        // TODO Auto-generated method stub

    }

}


Now, the person above noticed that you posting your code wrong absolutely butchered the huge string concatenation, but I think that was just from poor formatting. The real problem is the line of code in the init() method:

add(cool.gif;

for starters there is no closing parentheses (I added it in the code I posted above). Second, what you are doing requesting the Object "gif" that belongs to the Object "cool". If what you are trying to do is add the image what you need to do is create some sort of object, and load the image into it. I don't know much about applets, but here's what I would replace add(cool.gif; with:

CODE

        ImageIcon cool = null;
        if(this.getClass().getResource("cool.gif")!=null)
            cool = new ImageIcon(this.getClass().getResource("cool.gif"));
        JLabel imageLabel = new JLabel(cool);
        add(imageLabel);


what this does is create an ImageIcon and assigns it to null.
Then it uses getClass().getResource(string path) to find the URL to the image (this looks in the directory you are executing from) and if that URL is not null (it found something at that path) it will load it using the ImageIcon constructor.
Then it creates a JLabel (I hate to get swing involved in this, but I don't know much of java GUI beyond swing) and loads the icon into it (even if it's null JLabel handles it)
then it adds that label. Hope that solves your problem.

User is offlineProfile CardPM
+Quote Post

pbl
RE: Pay Roll System
26 Jun, 2008 - 09:31 PM
Post #4

D.I.C Lover
Group Icon

Joined: 6 Mar, 2008
Posts: 3,587



Thanked: 233 times
Dream Kudos: 75
My Contributions
CODE

       add(cool.gif);


what is the object "cool" ?
what is its instance variable .gif ?
User is offlineProfile CardPM
+Quote Post

Fast ReplyReply to this topicStart new topic
Time is now: 1/9/09 01:42AM

Be Social

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

Live Java Help!

Java Tutorials

Reference Sheets

Java Snippets

DIC Chatroom

Bye Bye Ads

Monthly Drawing

Thumb Drive

Top Contributors

Top 10 Kudos This Month