im making a project right now.. a employee will input some personal information in a jframe then when the user click the button another window will popout and it will display the information of the employee.. im using setter and getter methods.. i think there is the problem because when i get the informations it returns null.. what should i do.? help me pls..

Pass the information from one frame to the other before you call the "show" method.
Remember you can have the TextFields of the second frame public or with set methods in order to set their values from the first frame

Use the "getters and setters" properly?

If you show your code (and use code tags), we could probably give a better answer.

package mpeyt;


import java.awt.*;
import java.awt.event.*;
import javax.swing.*;


public class Implementation extends JApplet implements ActionListener{
    Container Panel;
    LayoutManager Layout;
    JLabel Name,Address,SSS,Gender,Cstat;
    JTextField InNa, InAdd,InS,InGen,InStat;
    JButton Submit;
    JLabel Ge,Ss,Cs;
    Employee p1=new Employee();
    ContractualEmployee p3=new ContractualEmployee();

    public void NewWindow(){
        JFrame frame=new FinalOutput();
        frame.setVisible(true);

         }
    public Implementation() throws Exception{


        Name=new JLabel("Name:",JLabel.LEFT);
        Address=new JLabel("Address:",JLabel.LEFT);
        SSS=new JLabel("SSS:",JLabel.LEFT);
        Gender=new JLabel("Gender:",JLabel.LEFT);
        Cstat=new JLabel("Civil Status:",JLabel.LEFT);
        InNa=new JTextField(15);
        InAdd=new JTextField(15);
        InS=new JTextField(5);
        InGen=new JTextField(5);
        InStat=new JTextField(5);
        Ge=new JLabel();
        Ss=new JLabel();
        Cs=new JLabel();
        Submit=new JButton("Submit");
        Layout=new FlowLayout();
        Panel= getContentPane();


        InNa.addActionListener(this);
        InAdd.addActionListener(this);
        InS.addActionListener(this);
        InGen.addActionListener(this);
        InStat.addActionListener(this);

        Panel.setLayout(Layout);
        Panel.setBackground(Color.yellow);      
        Panel.add(Name);
        Panel.add(InNa);
        Panel.add(Address);
        Panel.add(InAdd);
        Panel.add(SSS);
        Panel.add(Ss);
        Panel.add(InS);
        Panel.add(Gender);
        Panel.add(Ge);
        Panel.add(InGen);
        Panel.add(Cstat);
        Panel.add(Cs);
        Panel.add(InStat);
        Panel.add(Submit);


        Submit.setActionCommand("next");
        Submit.addActionListener(this);


            Submit.setEnabled(true);
    }
    public void actionPerformed (ActionEvent e){

        String ans,n,a,s,g,c;
        String[] gen={"m","f","F","M"};
        String[] cstat={"s","m","w"};
        int ctr1=0;
        ans=e.getActionCommand();
        if(ans.equals("next")){


            n=InNa.getText();
            p1.setName(n);
            a=InAdd.getText();
            p1.setAddress(a);
            try{
            s=InS.getText();
            int sssx= Integer.parseInt(s);
            if((sssx>=1)&&(sssx<=999)&&(s.length()==3)){
                p1.setSss(s);
            }

            else{
                ++ctr1;
                throw new InvalidSssException(s);

            }
            }
            catch(NullPointerException ex){
                Ss.setForeground(Color.red);
                Ss.setText("Invalid ID");
            }
            catch(Exception ex){
                Ss.setForeground(Color.red);
                Ss.setText("Invalid ID");
            }
            try{
            g=InGen.getText();
            if(g.equals(gen[0])){
                p1.setGender(g);}
                else if(g.equals(gen[1])){
                p1.setGender(g);
                }
                else if(g.equals(gen[2])){
                    p1.setGender(g);
                    }
                else if(g.equals(gen[3])){
                    p1.setGender(g);
                    }
                else{
                    ++ctr1;
                    throw new InvalidGenderException(g);
                }
            }
            catch(NullPointerException ex){
                Ge.setForeground(Color.red);
                Ge.setText("Invalid Gender");
            }
            catch(Exception ex){
                Ge.setForeground(Color.red);
                Ge.setText("Invalid Gender");
                }
            try{
            c=InStat.getText();
            if(c.equals(cstat[0])){
                p1.setCivilstat(c);
            }
            else if(c.equals(cstat[1])){
                p1.setCivilstat(c);
            }
            else if(c.equals(cstat[2])){
                p1.setCivilstat(c);
            }
            else{
                ++ctr1;
                throw new InvalidStatusException(c);
            }

            }
            catch(NullPointerException ex){
                Cs.setForeground(Color.red);
                Cs.setText("Invalid Status");
            }
            catch(Exception ex){
                Cs.setForeground(Color.red);
                Cs.setText("Invalid Status");
            }

        if(ctr1==0){
            NewWindow();

        }

        }




    }
    class FinalOutput extends JFrame implements ActionListener {
            JLabel jn,ja,js,jg,jc;
            JButton close;
            LayoutManager Layout;
            Employee p1=new Employee();
            ContractualEmployee p3=new ContractualEmployee();

            public FinalOutput(){

            Container Pane;
            setTitle("Employee Information:");
            setSize(130,200);
            Layout=new FlowLayout();
            Pane = getContentPane();
            jn=new JLabel("Name:  " + p1.getName());
            ja=new JLabel("Address:  " + p1.getAddress());
            js=new JLabel("SSS:  " + p1.getSss());
            jg=new JLabel("Gender:  " + p1.getGender());
            jc=new JLabel("Civil Status:  " + p1.getCivilstat());
            close = new JButton("Close Window");

            Pane.setLayout(Layout);
            Pane.setBackground(Color.yellow);
            Pane.add(jn);
            Pane.add(ja);
            Pane.add(js);
            Pane.add(jg);
            Pane.add(jc);
            Pane.add(close);

            close.setActionCommand("close");
            close.addActionListener(this);
        }
         public void actionPerformed (ActionEvent e){
            String answ=e.getActionCommand();
            if(answ.equals("close")){ 
            setVisible(false);
                dispose();
            }
        }
    }


}

this is the main class..

Edited 3 Years Ago by Dani: Formatting fixed

package mpeyt;

public class Employee{

    String name;
    String address;
    String sss;
    String gender;
    String civilstat;
    String[] gen={"m","f","F","M"};
    String[] stat={"s","m","w"}; 
public void setName(String n){
    name=n;
    }
public String getName(){
    return name;
    }
public void setAddress(String a){
    address=a;
    }
public String getAddress(){
    return address;
    }
public void setSss(String s){
    sss=s;
    }
public String getSss(){
    return sss;
    }
public void setGender(String g){
    if(g.equals(gen[0])||g.equals(gen[3])){
        gender="male";
        }
    else if(g.equals(gen[1])||g.equals(gen[2])){
        gender="female";
        }
    }
public String getGender(){
    return gender;
    }
public void setCivilstat(String c){
    if(c.equals(stat[0])){
        civilstat="single";
        }
    else if(c.equals(stat[1])){
        civilstat="married";
        }
    else if(c.equals(stat[2])){
        civilstat="widow";
        }
    }
public String getCivilstat(){
    return civilstat;
    }

}

this is the setters and getters.. sorry its too long.. just a beginner..

Edited 3 Years Ago by Dani: Formatting fixed

This article has been dead for over six months. Start a new discussion instead.