how to soulution this program

N

naw84az

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 = new JButton ();
button.setText(label);
bpanel.add(button);
}
this.con.add(bpanel);

//Add Componant - , * ,/
for ( int i = 12 ; i < 15 ; i++){
button = new JButton ();
button.setText(label);
npanel.add(button);
}
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 = new JButton ();
advbutton.setText(advlabel);
advpanel.add(advbutton);
}
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
 
A

Alex Hunsley

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
 
F

Flo 'Irian' Schaetz

And thus spoke (e-mail address removed)...
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.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,773
Messages
2,569,594
Members
45,125
Latest member
VinayKumar Nevatia_
Top