2

I have this 1st clas:

 private class proceedAL implements ActionListener
{
public void actionPerformed(ActionEvent z)
    {
        String x = (String)mouseB.getActionCommand();
        String y = (String)monitorB.getActionCommand();
        ComputerSimulator me = new connect(x,y);
    }

}

and another class:

public class ComputerSimulator extends JFrame
{
public void connect(String x, String y)
{
   String i, j;
   c2.setText(x);
   c3.setText(y);
}

This error appears: cannot find symbol - class connect

What am I missing? I'm just a starter in Programming, need some help guys

4

4 回答 4

2

实例化类的对象并调用其方法的正确方法是:

ComputerSimulator e = new ComputerSimulator();
e.connect(x, y);
于 2012-11-14T13:14:58.367 回答
2

connect确实不是类。它是类中的一种方法ComputerSimulator

您应该首先创建对象:

ComputerSimulator me = new ComputerSimulator()

现在您可以调用方法connectme.connect(x, y);

于 2012-11-14T13:16:04.220 回答
0

connect不是一个类,它是类上的一个方法ComputerSimulator。您正在调用该connect方法,就好像它是构造函数一样,您需要这样做

ComputerSimulator computerSimulator = new ComputerSimulator();
computerSimulator.connect();
于 2012-11-14T13:15:06.603 回答
0

你错了,你只能new上课(比如ComputerSimulator)。

一旦你有了那个类的实例,你就可以使用它的公共方法(比如connect)->me.connect(x, y);

顺便说一下,throws仅指异常处理。

于 2012-11-14T13:16:12.280 回答