一个类的方法中的数据(变量)怎么传到另一个类中的方法中去
如A类中 button.addActionListener(new ActionListener(){//添加动作监听
public void actionPerformed(ActionEvent e){
command = e.getActionCommand();
}
});
放到B类中public void mouseReleased(java.awt.event.MouseEvent e){
x2 = e.getX();
y2 = e.getY();
if("line".equals(command)){
//选中的是直线
g.drawLine(x1,y1,x2,y2);
}else if("rect".equals(command)){
g.drawRect(Math.min(x1,x2),Math.min(y1, y2),Math.abs(x2-x1),Math.abs(y2-y1));
}else if("oval".equals(command)){
g.drawOval(x1,y1,Math.abs(x2-x1),Math.abs(y2-y1));
}
这个command怎么传过来??????
如A类中 button.addActionListener(new ActionListener(){//添加动作监听
public void actionPerformed(ActionEvent e){
command = e.getActionCommand();
}
});
放到B类中public void mouseReleased(java.awt.event.MouseEvent e){
x2 = e.getX();
y2 = e.getY();
if("line".equals(command)){
//选中的是直线
g.drawLine(x1,y1,x2,y2);
}else if("rect".equals(command)){
g.drawRect(Math.min(x1,x2),Math.min(y1, y2),Math.abs(x2-x1),Math.abs(y2-y1));
}else if("oval".equals(command)){
g.drawOval(x1,y1,Math.abs(x2-x1),Math.abs(y2-y1));
}
这个command怎么传过来??????