java鼠标点击生成图片上的某点后,以该点为中心放大边长为l的正方形区域
1个回答
2015-09-28
展开全部
我这里有标签随鼠标移动的代码,你复制下来看看:
import java.awt.*;
import java.awt.event.*;
public class LableTest extends Frame {
Label l;
Panel p;
int x=10,y=10;
public LableTest(){
super("标签走动的演示");
p=new Panel();
l=new Label("标签");
l.setBackground(Color.red);
l.setBounds(x,y,100,50);
p.add(l);
this.add("Center",p);
this.addWindowListener(new WindowAdapter(){
public void windowClosing(WindowEvent ex){
System.exit(0);
}});
p.addMouseListener(new MouseAdapter(){
public void mouseClicked(MouseEvent e){
x=e.getX();y=e.getY();
l.setLocation(x,y);
}});
this.setSize(400,400);
this.setVisible(true);
}
public static void main(String args[]){
new LableTest();
}
}
import java.awt.*;
import java.awt.event.*;
public class LableTest extends Frame {
Label l;
Panel p;
int x=10,y=10;
public LableTest(){
super("标签走动的演示");
p=new Panel();
l=new Label("标签");
l.setBackground(Color.red);
l.setBounds(x,y,100,50);
p.add(l);
this.add("Center",p);
this.addWindowListener(new WindowAdapter(){
public void windowClosing(WindowEvent ex){
System.exit(0);
}});
p.addMouseListener(new MouseAdapter(){
public void mouseClicked(MouseEvent e){
x=e.getX();y=e.getY();
l.setLocation(x,y);
}});
this.setSize(400,400);
this.setVisible(true);
}
public static void main(String args[]){
new LableTest();
}
}
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询