

-----------------------------------

aDevildog

Wed Jan 16, 2008 4:57 pm


&quot;Calculator&quot; Issues

-----------------------------------

Hi there. I've unfortunately got a terrible computer teacher (I doubt he knows anything besides outputting to the screen). Everything we've "learned"  is from tutorials from the internet. Its been a troublesome semester to go from having my Turring Teacher an actuall user of it outside of school, and knew what she was doing, to this guy.

For my culminating project, I decided to throw together a Calculator (Similar to the one that comes with Windows). So using my notes, I get started. I've got this so far, however when I run it the following lines give me some errors.


mainFrame.getContentPane ().setLayout (new BorderLayout ());
mainFrame.getContentPane ().add (numbersPanel, BorderLayout.NORTH);


Just wondering if anyone can point me in the correct direction? I had a simpler version of this running that just added a 1. I edited it, took out most of the stuff, and this error started to happen, and I have not a clue why 

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

public class Calculator extends JFrame //implements ActionListener
{
    JPanel numbersPanel;                                            //For the Number Buttons (1-9)
    JPanel operationPanel;                                          //For the operations (+-/*=)
    JPanel resultPanel;                                         //For the result text Box
    JPanel mainFrame;

    JTextField resultTextField;                                     //For the Results to be displayed
    JButton One, Two, Three, Four, Five, Six, Seven, Eight, Nine;   //For the numbers Buttons
    JButton Multiply, Divide, Add, Subtract, equils;                 //For the Operation Buttons

    public Calculator ()
    {
        setTitle ("Calculator");
        setDefaultCloseOperation (EXIT_ON_CLOSE);

        //----- Number Panel Group -----//

        One = new JButton ("1");
        Two = new JButton ("2");
        Three = new JButton ("3");
        Four = new JButton ("4");
        Five = new JButton ("5");
        Six = new JButton ("6");
        Seven = new JButton ("7");
        Eight = new JButton ("8");
        Nine = new JButton ("9");

        numbersPanel = new JPanel ();
        numbersPanel.setLayout (new BorderLayout ());
        numbersPanel.add (One);
        numbersPanel.setVisible (true);

        mainFrame.getContentPane ().setLayout (new BorderLayout ());
        mainFrame.getContentPane ().add (numbersPanel, BorderLayout.NORTH);
        mainFrame.setVisible (true);

    } //Calculator Method


    public static void main (String[] args)
    {
        new Calculator ();
    } //Main Method
} //Calculator Class


-----------------------------------

OneOffDriveByPoster

Wed Jan 16, 2008 5:57 pm


Re: &quot;Calculator&quot; Issues

-----------------------------------

Might help if your mainFrame was a JFrame.


-----------------------------------

aDevildog

Wed Jan 16, 2008 6:37 pm


Re: &quot;Calculator&quot; Issues

-----------------------------------

Might help if your mainFrame was a JFrame.

Haha, I've got it working now :) Thanks though

