943,694 Members | Top Members by Rank

Ad:
  • Java Discussion Thread
  • Unsolved
  • Views: 556
  • Java RSS
Sep 16th, 2008
0

Need Help on calling classes

Expand Post »
I'm practicing java language.. please help me out

I got this error saying..
cannot find symbol
symbol: constructor compAdd()
location: class compAdd
java Syntax (Toggle Plain Text)
  1. compAdd c1 = new compAdd();
  2. ///////////////compAdd.java
  3. import javax.swing.*;
  4. import java.awt.event.*;
  5. import java.awt.*;
  6.  
  7. public class compAdd extends JFrame
  8. {
  9. public JButton button = new JButton("Add");
  10. public JTextField txt1, txt2, txt3;
  11. public compAdd(String title)
  12. {
  13. super(title);
  14. txt1 = new JTextField(5);
  15. txt2 = new JTextField(5);
  16. txt3 = new JTextField(5);
  17. this.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
  18. JPanel cen = new JPanel();
  19. cen.add(txt1);
  20. cen.add(txt2);
  21. cen.add(txt3);
  22. cen.add(button);
  23. Container contentPane = this.getContentPane();
  24. contentPane.add(cen, BorderLayout.CENTER);
  25. addMe am = new addMe(this);
  26. button.addActionListener(am);
  27. }
  28.  
  29. public static void main(String [] args)
  30. {
  31. JFrame f = new compAdd("Addtion");
  32. f.setSize(400,400);
  33. f.setVisible(true);
  34. }
  35. }
  36.  
  37. //////////////addMe.java
  38. import javax.swing.*;
  39. import java.awt.event.*;
  40. import java.awt.*;
  41.  
  42. public class addMe implements ActionListener
  43. {
  44. private Container container;
  45. public addMe(JFrame c)
  46. {
  47. container = c.getContentPane();
  48. }
  49. public void actionPerformed(ActionEvent ae)
  50. {
  51.  
  52. String label = ae.getActionCommand();
  53. if (label == "Add")
  54. {
  55. int txt1,txt2,txt3;
  56. compAdd c1 = new compAdd();
  57. txt1 = Integer.parseInt(c1.txt1.getText());
  58. txt2 = Integer.parseInt(c1.txt2.getText());
  59. txt3 = txt1 + txt2;
  60. c1.txt3.setText(String.valueOf(txt3));
  61. }
  62. }
  63. }
Last edited by cscgal; Sep 16th, 2008 at 11:22 am. Reason: Added code tags
Similar Threads
Reputation Points: 10
Solved Threads: 0
Newbie Poster
knarffrank is offline Offline
12 posts
since Aug 2008
Sep 16th, 2008
0

Re: Need Help on calling classes

you are calling this constructor, the default constructor:

Java Syntax (Toggle Plain Text)
  1. 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)
  1. compAdd c1 = new compAdd("some String");
Reputation Points: 919
Solved Threads: 354
Nearly a Posting Maven
stultuske is offline Offline
2,487 posts
since Jan 2007
Sep 16th, 2008
1

Re: Need Help on calling classes

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 . . .
Sponsor
Featured Poster
Reputation Points: 1014
Solved Threads: 446
Nearly a Senior Poster
javaAddict is offline Offline
3,258 posts
since Dec 2007
Sep 16th, 2008
0

Re: Need Help on calling classes

Click to Expand / Collapse  Quote originally posted by javaAddict ...
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 . . .
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.
Featured Poster
Reputation Points: 653
Solved Threads: 151
Nearly a Posting Virtuoso
stephen84s is offline Offline
1,316 posts
since Jul 2007

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in Java Forum Timeline: Variation of the Monte Carlo form of finding Pi... I'm having a bit of trouble
Next Thread in Java Forum Timeline: Include Base64 encoded data into XML





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC