Java 将字符串从一个类传递到另一个类
我有一节课:Java 将字符串从一个类传递到另一个类,java,class,Java,Class,我有一节课: private class proceedAL implements ActionListener { public void actionPerformed(ActionEvent z) { String x = (String)mouseB.getActionCommand(); String y = (String)monitorB.getActionCommand(); ComputerSimulator me =
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);
}
}
另一类:
public class ComputerSimulator extends JFrame
{
public void connect(String x, String y)
{
String i, j;
c2.setText(x);
c3.setText(y);
}
出现此错误:找不到符号-类连接
我错过了什么?我只是一个编程新手,需要一些帮助实例化类的对象并调用其方法的正确方法是:
ComputerSimulator e = new ComputerSimulator();
e.connect(x, y);
实例化类的对象并调用其方法的正确方法如下:
ComputerSimulator e = new ComputerSimulator();
e.connect(x, y);
connect
不是类,它是类计算机模拟器上的方法。您正在调用connect
方法,就好像它是构造函数一样,您需要这样做
ComputerSimulator computerSimulator = new ComputerSimulator();
computerSimulator.connect();
connect
不是类,它是类计算机模拟器上的方法。您正在调用connect
方法,就好像它是构造函数一样,您需要这样做
ComputerSimulator computerSimulator = new ComputerSimulator();
computerSimulator.connect();
connect
确实不是类。它是类计算机模拟器
中的一种方法
您应该首先创建对象:
ComputerSimulator me=新的ComputerSimulator()
现在您可以调用方法connect
:me.connect(x,y)代码>连接
确实不是类。它是类计算机模拟器
中的一种方法
您应该首先创建对象:
ComputerSimulator me=新的ComputerSimulator()
现在您可以调用方法connect
:me.connect(x,y)代码>如果您的代码有误,则只能对类进行新建(如ComputerSimulator
)
一旦有了该类的实例,就可以使用它的公共方法(如connect
)->me.connect(x,y)代码>
顺便说一句,抛出
仅指异常处理。如果它有错误,您只能对类进行新建(如ComputerSimulator
)
一旦有了该类的实例,就可以使用它的公共方法(如connect
)->me.connect(x,y)代码>
顺便说一下,抛出
仅指异常处理。不要抛出字符串,传递它!它更善良=)不要扔绳子,传过去!它更亲切=)