| | |
Need Help on calling classes
![]() |
•
•
Join Date: Aug 2008
Posts: 12
Reputation:
Solved Threads: 0
I'm practicing java language.. please help me out
I got this error saying..
cannot find symbol
symbol: constructor compAdd()
location: class compAdd
I got this error saying..
cannot find symbol
symbol: constructor compAdd()
location: class compAdd
java Syntax (Toggle Plain Text)
compAdd c1 = new compAdd(); ///////////////compAdd.java import javax.swing.*; import java.awt.event.*; import java.awt.*; public class compAdd extends JFrame { public JButton button = new JButton("Add"); public JTextField txt1, txt2, txt3; public compAdd(String title) { super(title); txt1 = new JTextField(5); txt2 = new JTextField(5); txt3 = new JTextField(5); this.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE); JPanel cen = new JPanel(); cen.add(txt1); cen.add(txt2); cen.add(txt3); cen.add(button); Container contentPane = this.getContentPane(); contentPane.add(cen, BorderLayout.CENTER); addMe am = new addMe(this); button.addActionListener(am); } public static void main(String [] args) { JFrame f = new compAdd("Addtion"); f.setSize(400,400); f.setVisible(true); } } //////////////addMe.java import javax.swing.*; import java.awt.event.*; import java.awt.*; public class addMe implements ActionListener { private Container container; public addMe(JFrame c) { container = c.getContentPane(); } public void actionPerformed(ActionEvent ae) { String label = ae.getActionCommand(); if (label == "Add") { int txt1,txt2,txt3; compAdd c1 = new compAdd(); txt1 = Integer.parseInt(c1.txt1.getText()); txt2 = Integer.parseInt(c1.txt2.getText()); txt3 = txt1 + txt2; c1.txt3.setText(String.valueOf(txt3)); } } }
Last edited by cscgal; Sep 16th, 2008 at 11:22 am. Reason: Added code tags
you are calling this constructor, the default constructor:
but you have only provided a constructor which takes an argument (a String object)
the compiler will create a default constructor for you, so you don't have to write it, but only if it doesn't find any constructors in your code.
so, either you add a default constructor to your compAdd class, or you change the call to the constructor to something like this:
Java Syntax (Toggle Plain Text)
compAdd c1 = new compAdd();
but you have only provided a constructor which takes an argument (a String object)
the compiler will create a default constructor for you, so you don't have to write it, but only if it doesn't find any constructors in your code.
so, either you add a default constructor to your compAdd class, or you change the call to the constructor to something like this:
Java Syntax (Toggle Plain Text)
compAdd c1 = new compAdd("some String");
If you don't know java why are you starting with gui when you don't know even the basics of the language?
Start by writing simple console programs and learn how to use classes, extending them . . .
Start by writing simple console programs and learn how to use classes, extending them . . .
Check out my New Bike at my Public Profile at the "About Me" tab
Exactly when you are learning to Swim, you just don't directly jump into the middle of the ocean, you start in the baby pool first.
"Any fool can write code that a computer can understand. Good programmers write code that humans can understand."
"How to ask questions the smart way ?"
"How to ask questions the smart way ?"
![]() |
Similar Threads
- Tutorial: Understanding ASP classes (ASP)
- calling a method from another class (Java)
- Classes (C++)
- passing arrays to classes? (Java)
- Classes Problem (C++)
- Newbi can anyone help with methods and classes (Java)
- Using map<> with classes (C++)
- Help! using separate classes for JFrames (Java)
- Need help with Const, Ref and Classes. (C)
Other Threads in the Java Forum
- Previous Thread: Variation of the Monte Carlo form of finding Pi... I'm having a bit of trouble
- Next Thread: Include Base64 encoded data into XML
| Thread Tools | Search this Thread |
addball android api applet application apps array arrays automation awt binary bluetooth businessintelligence busy_handler(null) button card chat class client code collision component constructor crashcourse css database draw eclipse ee error eventlistener exception fractal free game gis givemetehcodez graphics gui html ide image integer integration j2me java javadoc javafx javamicroeditionuseofmotionsensor javaprojects jni jpanel jtree julia jvm linux list loan machine map method methods migrate mobile netbeans newbie oracle output phone physics plazmic problem program programming project radio recursion scanner server service set sharepoint smart sms socket software sort sortedmaps sql string swing textfield threads transfer tree trolltech unlimited utility webservices windows






