Need Help on calling classes

Reply

Join Date: Aug 2008
Posts: 12
Reputation: knarffrank is an unknown quantity at this point 
Solved Threads: 0
knarffrank knarffrank is offline Offline
Newbie Poster

Need Help on calling classes

 
0
  #1
Sep 16th, 2008
I'm practicing java language.. please help me out

I got this error saying..
cannot find symbol
symbol: constructor compAdd()
location: class compAdd
  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
Reply With Quote Quick reply to this message  
Join Date: Jan 2007
Posts: 706
Reputation: stultuske is a jewel in the rough stultuske is a jewel in the rough stultuske is a jewel in the rough 
Solved Threads: 84
stultuske's Avatar
stultuske stultuske is offline Offline
Master Poster

Re: Need Help on calling classes

 
1
  #2
Sep 16th, 2008
you are calling this constructor, the default constructor:

  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:

  1. compAdd c1 = new compAdd("some String");
Reply With Quote Quick reply to this message  
Join Date: Dec 2007
Posts: 1,650
Reputation: javaAddict is a name known to all javaAddict is a name known to all javaAddict is a name known to all javaAddict is a name known to all javaAddict is a name known to all javaAddict is a name known to all 
Solved Threads: 223
Featured Poster
javaAddict's Avatar
javaAddict javaAddict is offline Offline
Posting Virtuoso

Re: Need Help on calling classes

 
1
  #3
Sep 16th, 2008
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 . . .
Check out my New Bike at my Public Profile at the "About Me" tab
Reply With Quote Quick reply to this message  
Join Date: Jul 2007
Posts: 1,175
Reputation: stephen84s is a glorious beacon of light stephen84s is a glorious beacon of light stephen84s is a glorious beacon of light stephen84s is a glorious beacon of light stephen84s is a glorious beacon of light stephen84s is a glorious beacon of light 
Solved Threads: 125
Featured Poster
stephen84s's Avatar
stephen84s stephen84s is offline Offline
Veteran Poster

Re: Need Help on calling classes

 
0
  #4
Sep 16th, 2008
Originally Posted by javaAddict View Post
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.
"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 ?"
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:


Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC