Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsWhite Papers
Discussion GroupsFirst AidDatabasesJavaBeansGUIJava 3DVirtual MachineCORBASecurityToolsGeneral
Java DirectoryOpen Source ProjectsSample Book ChaptersUser GroupsWeb Resources
Related Topics
Databases.NETMore Topics ...

Java Forum / General / December 2006

Tip: Looking for answers? Try searching our database.

how to soulution this program

Thread view: 
naw84az@yahoo.com - 25 Dec 2006 08:34 GMT
the programe is basic Calculator , i add new Class extends the
Calculator class add Override method inside method i use
Super.createPanel then i want add text Filed in this Method return in
runtime NotllPointer Wxception
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;

public class CCalculator1 extends JFrame {
    // to use in sub class
    private Container con = new Container ();
    //
    private JPanel tpanel = new JPanel ();
    private JPanel bpanel = new JPanel();
    private JPanel npanel = new JPanel ();
    private JPanel pluspanel = new JPanel ();
    private JPanel equalpanel = new JPanel ();
    private JPanel clearpanel = new JPanel ();
    private JPanel advpanel = new JPanel ();
    protected JTextField text = new JTextField();
    private String label [] =
    { "7","8","9","4","5","6","1","2" ,"3 ","0","."," -/+ ","/","*","-",
        "+","C","="};
    private String advlabel [] =
    {"PI","E","sqr","Sin","Cos",
        "Tan","Log","Log10","a^2"};
    private JButton advbutton [] = new JButton [advlabel.length];
    private JButton button [] = new JButton [label.length];
    private String str1 = new String ("0");
    private String str2 = new String ("");
    private String str3 = new String ("");
    private String pi = new String ("");
    private float var1  =0;
    private float var2 =0;

    CCalculator1 (){
        try {
            this.jbinit ();
        }
        catch (Exception e ){
            e.printStackTrace();
        }
    }

    protected void jbinit () throws Exception{

        // Set Content
        this.con = getContentPane ();
        this.con.setLayout(null);

        // Panel
        this.createPanel ();

        // Frame
        this.setTitle("Calcultor");
        this.setSize(new Dimension (400,400));
        this.setLocation(new Point (300,400));
        this.setVisible(true);
        this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

    }

    protected void createPanel () {

        // Set Panel
        tpanel.setLayout(new BorderLayout ());
        tpanel.setSize(new Dimension (270,30));
        tpanel.setLocation(new Point (10,10));
        tpanel.setOpaque(true);
        tpanel.setBorder(BorderFactory.createLineBorder(Color.BLACK));

        // Set Panel
        bpanel.setLayout(new GridLayout (4,3));
        bpanel.setSize(new Dimension (270,100));
        bpanel.setLocation(new Point (10,50));
        bpanel.setOpaque(true);
        bpanel.setBorder(BorderFactory.createLineBorder(Color.BLACK));

        // Set Panel *,,/,-
        npanel.setLayout(new GridLayout (1,3));
        npanel.setSize(new Dimension (270,30));
        npanel.setLocation(new Point (10,155));
        npanel.setOpaque(true);
        npanel.setBorder(BorderFactory.createLineBorder(Color.BLACK));

        // Set Panel
        pluspanel.setLayout(new GridLayout (1,1));
        pluspanel.setSize(new Dimension (60,100));
        pluspanel.setLocation(new Point (290,50));
        pluspanel.setOpaque(true);
        pluspanel.setBorder(BorderFactory.createLineBorder(Color.BLACK));

        // Set Panel
        equalpanel.setLayout(new GridLayout (1,1));
        equalpanel.setSize(new Dimension (60,30));
        equalpanel.setLocation(new Point (290,155));
        equalpanel.setOpaque(true);
        equalpanel.setBorder(BorderFactory.createLineBorder(Color.BLACK));

        // Set Panel
        clearpanel.setLayout(new GridLayout (1,1));
        clearpanel.setSize(new Dimension (60,30));
        clearpanel.setLocation(new Point (290,10));
        clearpanel.setOpaque(true);
        clearpanel.setBorder(BorderFactory.createLineBorder(Color.BLACK));

        // Set Panel
        advpanel.setLayout(new GridLayout (3,3));
        advpanel.setSize(new Dimension (270,100));
        advpanel.setLocation(new Point (10,200));
        advpanel.setOpaque(true);
        advpanel.setBorder(BorderFactory.createLineBorder(Color.BLACK));

        // Text Field
        text.setText(str1);
        text.setColumns(20);
        text.setEditable(true);
        text.setHorizontalAlignment(JTextField.CENTER);

        //Add Componant
        tpanel.add(text);
        this.con.add(tpanel);

        //Add Componant Button Number
        for ( int i = 0 ; i < 12 ; i++){
            button [i] = new JButton ();
            button[i].setText(label[i]);
            bpanel.add(button[i]);
        }
        this.con.add(bpanel);

        //Add Componant - , * ,/
        for ( int i = 12 ; i < 15 ; i++){
            button [i] = new JButton ();
            button[i].setText(label[i]);
            npanel.add(button[i]);
        }
        this.con.add(npanel);

        //Add Componant  +
        button [15] = new JButton ();
        button[15].setText(label[15]);
        pluspanel.add(button[15]);
        this.con.add(pluspanel);

        //Add Componant  =
        button [17] = new JButton ();
        button[17].setText(label[17]);
        equalpanel.add(button[17]);
        this.con.add(equalpanel);

        //Add Componant  C
        button [16] = new JButton ();
        button[16].setText(label[16]);
        clearpanel.add(button[16]);
        this.con.add(clearpanel);

        //Add Advance Componant
        for ( int i = 0 ; i < advbutton.length ; i++){
            advbutton [i] = new JButton ();
            advbutton[i].setText(advlabel[i]);
            advpanel.add(advbutton[i]);
        }
        this.con.add(advpanel);
    }
}

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

public class AdvCCalculator extends CCalculator1 {

    public AdvCCalculator () {
    //    JOptionPane.showMessageDialog(null,"test"+con);

    }

    protected void createPanel () {
        super.createPanel();
        // set Panel
    }

    private void ceateAdvPanel (){
    }
    public static void main (String arg [] ) {
        AdvCCalculator c = new AdvCCalculator ();
    }
}

how to add Text Field in Panel Display in Frame
Alex Hunsley - 25 Dec 2006 11:02 GMT
> the programe is basic Calculator , i add new Class extends the
> Calculator class add Override method inside method i use
> Super.createPanel then i want add text Filed in this Method return in
> runtime NotllPointer Wxception

I know it's Christmas day and all that but I believe the best way to
help you is to point out that this looks like homework, and even if it's
not, that you should actually think about the problem and learn
something about Swing etc. rather than drop into comp.lang.java.helpdesk
and expect to get the answer on a plate. What have you already done to
attempt this? What was the problem? Have you looked at the Java API
docs? Try looking up the Java API doc for JFrame, and reading some
general intros to Swing. Sun has lots of tutorials at their site.

Btw, you apparently can't even be bothered to read back what you've
written and/or correct simple typos like "NotllPointer Wxception". Do
you think this motivates anyone reading to want to help you? Do you
mumble at people in real life? If you want help, you have more chance of
success if you don't "mumble".

> how to add Text Field in Panel Display in Frame

Hint: look at the Java docs for the JPanel.add method. You may also be
interested in the JPanel.setLayout method.

lex
Flo 'Irian' Schaetz - 25 Dec 2006 11:45 GMT
And thus spoke naw84az@yahoo.com...

> the programe is basic Calculator , i add new Class extends the
> Calculator class add Override method inside method i use
> Super.createPanel then i want add text Filed in this Method return in

That's because your createPanel depends on the fact that the Constructor
was called first. But as you never call the constructor of your
Calculator1 in your AdvCCalculator class, it doesn't work.


Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.