?? game.java
字號:
import java.awt.*;
import java.awt.event.*;
class Mywin extends Frame implements ActionListener {
Button button;
Label label;
Mywin() {
setLayout(null);
Cursor c = Cursor.getPredefinedCursor(Cursor.HAND_CURSOR);
setCursor(c);
button = new Button("橫向走動");
button.setBackground(Color.pink);
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);
setVisible(true);
setBounds(100,120,300,300);
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(x,y);
}
else {
y = y + 3;
button.setLocation(x,y);
button.setLabel("縱向走動");
}
}
}
public class Game {
public static void main(String[] args) {
new Mywin();
}
}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -