是啊,但是如果你用了这些不标准的类的话,就要自己排错了
我如果把你的代码放到我的电脑上,连编译都通过不了的
因为我没有那些包,所以你帖上来的代码帖了和没帖是一样的,因为我们不能测试
可惜不是你,陪我到最后
import java.awt.Canvas;
import java.awt.Color;
import java.awt.Button;
import java.awt.Cursor;
import java.awt.FlowLayout;
import java.awt.Frame;
import java.awt.Label;
import java.awt.Panel;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.MouseListener;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;
public class aa implements ActionListener{
Frame fr;
Button bt1,bt2,bt3,bt4;
Panel pn;
Label label;
Canvas canvas;
String attr,tool;
private static final long serialVersionUID = 884142590900760515L;
public aa() {
fr=new Frame("陕西地图");
FlowLayout layout=new FlowLayout(FlowLayout.LEFT);//组件左对齐;
bt1=new Button("复位");
bt1.setCursor(new Cursor(Cursor.HAND_CURSOR));
bt1.addActionListener(this);
bt2=new Button("放大");
bt2.setCursor(new Cursor(Cursor.HAND_CURSOR));
bt2.addActionListener(this);
bt3=new Button("缩小");
bt3.setCursor(new Cursor(Cursor.HAND_CURSOR));
bt3.addActionListener(this);
bt4=new Button("漫游");
bt4.setCursor(new Cursor(Cursor.HAND_CURSOR));
bt4.addActionListener(this);
pn=new Panel();
pn.setLayout(layout);//设置布局管理器;
pn.add(bt1);pn.add(bt2);pn.add(bt3);pn.add(bt4);
pn.setBackground(Color.white.darker());
label=new Label();
label.setBackground(Color.white.darker());
canvas=new Canvas();
fr.add(pn,"North");
fr.add(canvas,"Center");
fr.add(label,"South");
fr.setBounds(50,50,800,680);
fr.setVisible(true);
fr.addWindowListener(new WindowAdapter(){
public void windowClosing(WindowEvent e){
System.exit(0);
}
});
}
public void actionPerformed(ActionEvent e)
{
if(e.getSource()==bt4)
{
tool="pan";
canvas.addMouseListener((MouseListener) this);
}
if(e.getSource()==bt1)
{
tool="reset";
canvas.removeMouseListener((MouseListener) this);
}
if(e.getSource()==bt2)
{
tool="big";
canvas.addMouseListener((MouseListener) this);
}
if(e.getSource()==bt3)
{
tool="small";
canvas.addMouseListener((MouseListener) this);
}
}
public void mouseClicked(ActionEvent event) {
if(tool=="reset")
{
label.setText(tool);
}
if(tool=="big")
{
label.setText(tool);
}
if(tool=="small")
{
label.setText(tool);
}
if(tool=="pan")
{
label.setText(tool);
}
}
public static void main(String[] args) {
new aa();
}
}
我把程序简化了,要做的事情类似于这样的,看看应该怎么改?谢谢!