import java.awt.*;
import java.awt.event.*;
import java.math.*;
public class p212_12{
public static void main(String args[]){
new Frame12("移动");
}
}
class Frame12 extends Frame{
Button bt1=new Button("哈哈"),
bt2=new Button("我晕");
double x,y;
Frame12(String s){
super(s);
setLayout(null);
add(bt1);
add(bt2);
bt1.setBounds(100,100,50,20);
bt2.setBounds(100,120,50,20);
bt2.setEnabled(false);
bt1.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent e){
x=Math.random()*(double)(getWidth());
y=Math.random()*(double)(getHeight());
bt2.setBounds(
(int)x,
(int)y,
bt2.getWidth(),
bt2.getHeight()
);
}
});
setBounds(111,111,555,555);
setVisible(true);
validate();
}
}
java程序设计基础教程第二版: p212_12
最新推荐文章于 2024-04-17 07:14:47 发布