954,536 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

Need Help on calling classes

I'm practicing java language.. please help me out

I got this error saying..
cannot find symbol
symbol: constructor compAdd()
location: class compAdd

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));
    }
  }
}
knarffrank
Newbie Poster
12 posts since Aug 2008
Reputation Points: 10
Solved Threads: 0
 

you are calling this constructor, the default constructor:

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:

compAdd c1 = new compAdd("some String");
stultuske
Posting Sensei
3,137 posts since Jan 2007
Reputation Points: 1,114
Solved Threads: 433
 

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 . . .

javaAddict
Nearly a Senior Poster
Team Colleague
3,329 posts since Dec 2007
Reputation Points: 1,014
Solved Threads: 448
 
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.

stephen84s
Nearly a Posting Virtuoso
1,443 posts since Jul 2007
Reputation Points: 668
Solved Threads: 154
 

This article has been dead for over three months

Post: Markdown Syntax: Formatting Help
You