Mary Ismael
Posts: 3
Nickname: maryam
Registered: Apr, 2003
|
|
Re: JFrames
|
Posted: Apr 16, 2003 1:24 AM
|
|
i think you are working in two instances of JFrame the first one is that which you got from your super class JFrame for beeing as subclass to it and the other instance is the one that you make as a data member in your class so you have to : i think you have to choose between two things : you have to extends Object not JFrame or you have not to use a JFrame as data member and you make all of your coding to the instance that you have from your super class(JFrame) like that:
import javax.swing.*; import java.awt.*; import java.awt.event.*; import java.text.DecimalFormat; public class Calculator extends JFrame{ JMenuBar MyMenuBar; JTextField Number1, Number2; JLabel label1, label2, label3, AnsLabel; public Calculator() { super("Calculator"); MyMenuBar = new JMenuBar(); setJMenuBar(MyMenuBar); // Add a Menu To The Menu Bar JMenu Calc = new JMenu("Calculate"); MyMenuBar.add(Calc); // Add Menu Items To The menu Calc.add(new JMenuItem("Add")); Calc.add(new JMenuItem("Subtract")); Calc.add(new JMenuItem("Multiply")); Calc.add(new JMenuItem("Divide")); // Add A Separator Calc.addSeparator(); Calc.add(new JMenuItem("Exit")); Number1 = new JTextField(6); Number2 = new JTextField(6); label1 = new JLabel("Number 1"); label2 = new JLabel("Number 2"); label3 = new JLabel("Solution"); AnsLabel = new JLabel(); Container c = getContentPane(); c.setLayout(new GridLayout(3,2)); c.add(label1); c.add(Number1); c.add(label2); c.add(Number2); c.add(label3); c.add(AnsLabel); setSize(300,300); setVisible(true); show(); } public static void main(String args[]) { Calculator MyCalc = new Calculator(); MyCalc.addWindowListener( new WindowAdapter(){ public void windowClosing(WindowEvent e) { System.exit(0); } } ); }}
|
|