📄 example7_23.java.bak
字号:
import java.awt.*;import java.awt.event.*;
class MyWin extends Frame implements ActionListener
{ Button button;
Label label;
MyWin()
{
setLayout(null);
button=new Button("横向走动"); button.setBackground(Color.red);
button.addActionListener(this);
label=new Label("我可以被碰掉",Label.CENTER);
label.setBackground(Color.yellow);
button.setCursor(Cursor.getPredefinedCursor(Cursor.MOVE_CURSOR));
add(button); add(label);
button.setBounds(20,80,80,20);
label.setBounds(150,80,80,20);
setBounds(120,120,300,300);
setVisible(true);
validate();
}
public void actionPerformed(ActionEvent e)
{ Rectangle rect=button.getBounds();
int x=(int)rect.getX();
int y=(int)rect.getY();
if(rect.intersects(label.getBounds()))
{ label.setVisible(false);
}
if(label.isVisible())
{
x=x+2;
button.setLocation(rect.x+3,rect.y);
}
else
{ button.setLocation(rect.x,rect.y+3);
button.setLabel("纵向走动");
}
}
}
public class Example7_23
{
public static void main(String args[])
{
new WindowList();
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -