📄 example14_2.java
字号:
import java.awt.*;import java.awt.event.*;
public class Example14_2 extends java.applet.Applet implements ActionListener
{ Button button;
Label label;
public void init()
{ button=new Button("横向走动"); button.setBackground(Color.red);
button.addActionListener(this);
label=new Label("我可以被碰掉",Label.CENTER);
label.setBackground(Color.yellow);
add(button); add(label);
}
public void actionPerformed(ActionEvent e)
{ Rectangle rect=button.getBounds();
if(rect.intersects(label.getBounds()))
{ label.setVisible(false);
}
if(label.isVisible())
{ button.setLocation(rect.x+3,rect.y);
}
else
{ button.setLocation(rect.x,rect.y+3);
button.setLabel("纵向走动");
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -