import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
public class UsedPane extends JFrame implements MouseListener,MouseMotionListener{
int toolFlag = 1;
int count = 0;
boolean isAddTool = false;
boolean isMove = false;
JToolBar tools = new JToolBar("工具");
JButton tool;
JButton addTool = new JButton("add");
JButton removeTool = new JButton("remove");
public UsedPane(){
setLayout(new BorderLayout());
tools.add(addTool);
tools.add(removeTool);
add(tools,BorderLayout.CENTER);
addTool.addMouseMotionListener(this);
addTool.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent et){
tool = new JButton(new ImageIcon("Image/"+count+".gif"));
isMove = true;
tools.add(tool);
}
});
removeTool.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent et){
tools.removeAll();
tools.add(addTool);
tools.add(removeTool);
}
});
}
public void mouseClicked(MouseEvent e){}
public void mousePressed(MouseEvent e){}
public void mouseReleased(MouseEvent e){}
public void mouseEntered(MouseEvent e){
}
public void mouseExited(MouseEvent e){
}
public void mouseDragged(MouseEvent e){
}
public void mouseMoved(MouseEvent e){
if(isMove){
tool.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent et){
toolFlag = count;
});
isMove = false;
}
}
public static void main(String[] args){
UsedPane a = new UsedPane();
a.setSize(200,200);
a.setVisible(true);
}
}
为什么我添加的按钮执行事件都为当前cout值,而不是从第一个开始为从1到count的值?????
----------------解决方案--------------------------------------------------------
你要问的是什么
----------------解决方案--------------------------------------------------------
问题解决了,谢谢~~~~
----------------解决方案--------------------------------------------------------