class framePackage.DrawMapTile$1 对比 class framePackage.DrawMapTile
class framePackage.DrawMapTile$1 vs class framePackage.DrawMapTile
所以我现在开始学习 Java 并且正在从事一个我有命令处理程序的项目(没什么特别的,只是一个 .sendCommand(String command, Object source))
现在我从 JPanel 调用这个 sendCommand:
public String sendCommand(String command, Object source) {
String result = "";
System.out.println(source);
System.out.println(source.getClass() + " vs "+ DrawMapTile.class);
System.out.println(source.getClass().isInstance(DrawMapTile.class));
System.out.println(source.equals(DrawMapTile.class));
if(source.getClass().equals(DrawMapTile.class)) {
result = drawMapTileCommands(command,(DrawMapTile) source);
}
return result;
}
输出为:
framePackage.DrawMapTile@2179ea42
class framePackage.DrawMapTile vs class framePackage.DrawMapTile
false
false
1 美元有什么用,为什么?
请求编辑:
public DrawMapTile(ObjectMap objectMap,int xOfTile, int yOfTile, MainJFrame mainJFrame, DrawMap drawMap) {
this.mainJFrame = mainJFrame;
this.objectMap = objectMap;
this.map = objectMap.getMap();
this.drawMap = drawMap;
this.mapTile = map[xOfTile][yOfTile];
this.color = mapTile.getMapTileType().getColor();
listener = new ArrayList<ActionListener>();
drawMapTileActionListener = new ActionListener() {
@Override
public void actionPerformed(ActionEvent evt) {
String result = mainJFrame.getCommandHandler().sendCommand(evt.getActionCommand(),this);
System.out.println(result);
};
};
this.addActionListener(getDrawMapTileActionListener());
}
private ActionListener getDrawMapTileActionListener() {
return drawMapTileActionListener;
}
编辑 2:我明白你的意思了,这就是我现在解决它的方法:
public String sendCommand(String command, DrawMapTile source) {
String result = drawMapTileCommands(command, source);
return result;
}
public String sendCommand(String command, Object source)
String result = "";
return result;
}
它现在调用我想要的。
表示匿名内部 class。如果您向我们展示完整的代码,包括调用您的方法的部分,那将有助于进一步解释它。
看你叫它"from a JPanel",那个匿名内部class可能是一个ActionListener
所以我现在开始学习 Java 并且正在从事一个我有命令处理程序的项目(没什么特别的,只是一个 .sendCommand(String command, Object source))
现在我从 JPanel 调用这个 sendCommand:
public String sendCommand(String command, Object source) {
String result = "";
System.out.println(source);
System.out.println(source.getClass() + " vs "+ DrawMapTile.class);
System.out.println(source.getClass().isInstance(DrawMapTile.class));
System.out.println(source.equals(DrawMapTile.class));
if(source.getClass().equals(DrawMapTile.class)) {
result = drawMapTileCommands(command,(DrawMapTile) source);
}
return result;
}
输出为:
framePackage.DrawMapTile@2179ea42
class framePackage.DrawMapTile vs class framePackage.DrawMapTile
false
false
1 美元有什么用,为什么?
请求编辑:
public DrawMapTile(ObjectMap objectMap,int xOfTile, int yOfTile, MainJFrame mainJFrame, DrawMap drawMap) {
this.mainJFrame = mainJFrame;
this.objectMap = objectMap;
this.map = objectMap.getMap();
this.drawMap = drawMap;
this.mapTile = map[xOfTile][yOfTile];
this.color = mapTile.getMapTileType().getColor();
listener = new ArrayList<ActionListener>();
drawMapTileActionListener = new ActionListener() {
@Override
public void actionPerformed(ActionEvent evt) {
String result = mainJFrame.getCommandHandler().sendCommand(evt.getActionCommand(),this);
System.out.println(result);
};
};
this.addActionListener(getDrawMapTileActionListener());
}
private ActionListener getDrawMapTileActionListener() {
return drawMapTileActionListener;
}
编辑 2:我明白你的意思了,这就是我现在解决它的方法:
public String sendCommand(String command, DrawMapTile source) {
String result = drawMapTileCommands(command, source);
return result;
}
public String sendCommand(String command, Object source)
String result = "";
return result;
}
它现在调用我想要的。
表示匿名内部 class。如果您向我们展示完整的代码,包括调用您的方法的部分,那将有助于进一步解释它。
看你叫它"from a JPanel",那个匿名内部class可能是一个ActionListener