Programming C, C++, Java, PHP, Ruby, Turing, VB
Computer Science Canada 
Programming C, C++, Java, PHP, Ruby, Turing, VB  

Username:   Password: 
 RegisterRegister   
 PhoneBook Record
Index -> Programming, Java -> Java Help
View previous topic Printable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic
Author Message
Nezura




PostPosted: Fri Jan 14, 2005 11:49 pm   Post subject: PhoneBook Record

Hi guys, this is a phonebook record i've created, the first menu runs, but when the button "enter data" is clicked it gives a NullPointerException, i've tried moving all the variables so it's global but it doesn't seem to be working either, can someone help me out?

code:

//Created by na
//Computer Science ISP
//Last modified: January 13, 2005

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

public class phonebook extends JApplet implements ActionListener
{
    //JButton[] buttons = new JButton [5];
    int numbercounter = 2; //counts the number of entries the user will make
    Container panel = new Container ();
    JButton EnterData = new JButton ("Enter Data"); //Button to enter Data
    JFrame FirstFrame = new JFrame ("PhoneBook Storage"); //main frame with the 3 starting options
    JButton ShowChart = new JButton ("Show Table"); //Button display chart of data
    JButton Exit = new JButton ("Close"); //button to exit program
    JButton[] buttons = new JButton [numbercounter];

    JFrame TypeWindowFrame = new JFrame ("Enter Your Data"); //Frame that you can enter your data into
    Container TypeWindow = new Container ();

    public void init ()
    {


        panel.setLayout (new GridBagLayout ());
        GridBagConstraints c = new GridBagConstraints ();

        JLabel PhoneBook = new JLabel ("  Personal PhoneBook"); //Stores the title PhoneBook
        c.ipadx = 5;
        c.ipady = 1;
        c.fill = GridBagConstraints.BOTH;
        c.weightx = 1.0;
        c.weighty = 1.0;
        c.gridx = 0;
        c.gridy = 0;
        panel.add (PhoneBook, c);

        c.gridx = 0;
        c.gridy = 1;
        panel.add (EnterData, c);

        c.gridx = 0;
        c.gridy = 2;
        panel.add (ShowChart, c);

        c.gridx = 0;
        c.gridy = 3;
        panel.add (Exit, c);

        EnterData.addActionListener (this);
        ShowChart.addActionListener (this);
        Exit.addActionListener (this);

        PhoneBook.setForeground (Color.red);
        PhoneBook.setBackground (Color.black);
        PhoneBook.setOpaque (true);


        EnterData.setForeground (Color.black);
        EnterData.setBackground (Color.yellow);
        EnterData.setOpaque (true);

        ShowChart.setForeground (Color.black);
        ShowChart.setBackground (Color.yellow);
        ShowChart.setOpaque (true);

        Exit.setForeground (Color.black);
        Exit.setBackground (Color.yellow);
        Exit.setOpaque (true);

        FirstFrame.setSize (140, 250);
        FirstFrame.getContentPane ().add (panel);
        FirstFrame.setVisible (true);
    }




    public void actionPerformed (ActionEvent e)
    {



        //------------------------------------Enter Data Frame-----------------------------------------


        TypeWindow.setLayout (new GridBagLayout ());
        GridBagConstraints d = new GridBagConstraints ();

        JLabel PleaseEnter = new JLabel ("  Enter data in the fields below"); //Stores the title instructions
        d.ipadx = 5;
        d.ipady = 1;
        d.fill = GridBagConstraints.BOTH;
        d.weightx = 1.0;
        d.weighty = 1.0;
        d.gridx = 0;
        d.gridy = 0;
        TypeWindow.add (PleaseEnter, d);

        for (int x = 0 ; x < numbercounter ; x++)
        {
            d.gridx = x;
            d.gridy = 1;
            TypeWindow.add (buttons [x], d);
        }


        TypeWindowFrame.setSize (500, 500);
        TypeWindowFrame.getContentPane ().add (TypeWindow); //adds the container to the new frame
        TypeWindowFrame.setVisible (false); //sets the frame invisible





        //-----------------------------------Show Chart Frame------------------------------------------




        //-----------------------------------Exit -----------------------------------------------------




        if (e.getSource () == EnterData)
        {
            FirstFrame.setVisible (false);
            TypeWindowFrame.setVisible (true); //sets the Enter data  frame visible after the person clicks
        }


        else if (e.getSource () == ShowChart)
        {
            FirstFrame.setVisible (false);
            TypeWindowFrame.setVisible (true); //sets the showchart frame visible after the person clicks
        }


        else if (e.getSource () == Exit)
        {
            FirstFrame.setVisible (false);
            TypeWindowFrame.setVisible (true); //sets the exit frame visible after the person clicks
        }
 }
}
Sponsor
Sponsor
Sponsor
sponsor
wtd




PostPosted: Fri Jan 14, 2005 11:55 pm   Post subject: (No subject)

A note: in Java, do not begin the names of variables with capital letters.

Names like "PhoneBook" should only be used for classes. More approriate would be, "phoneBook".

In the same vein, "phonebook" is a bad name for a class. Instead use "PhoneBook".
Nezura




PostPosted: Sat Jan 15, 2005 12:06 am   Post subject: (No subject)

thx, but that doesn't solve my problem,

err would it be the number counter causing the problem?
rizzix




PostPosted: Sat Jan 15, 2005 8:18 am   Post subject: (No subject)

u haven't explained ur problem.
Hikaru79




PostPosted: Tue Jan 18, 2005 11:20 pm   Post subject: (No subject)

rizzix wrote:
u haven't explained ur problem.


He has, just not well.

Nezura, you say you get a NullPointerException, but that's not descriptive enough. Give us the entire error output that you recieve (a "stack trace") as that will tell us at what line the exception was thrown, and where inside the Java code it failed. Just recreate the error and put everything between [ code ] tags.
Nezura




PostPosted: Thu Jan 20, 2005 12:46 am   Post subject: (No subject)

Hey guys, i figuired out the problem...hehe thx for the input
Display posts from previous:   
   Index -> Programming, Java -> Java Help
View previous topic Tell A FriendPrintable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic

Page 1 of 1  [ 6 Posts ]
Jump to:   


Style:  
Search: