📄 controlwindow.java
字号:
import javax.swing.*;import java.awt.*;import java.awt.event.*;public class ControlWindow extends JFrame implements ActionListener { private JButton turnBtn, moveBtn; private Robot theRobot; /** post: this window is created * and getX() == 13*72+10 and getY()==20 * and getWidth() == 200 and getHeight() == 120 * and theRobot == r * and turnBtn is created and placed on this * and moveBtn is created and placed on this */ public ControlWindow(Robot r) { super("Control Buttons"); setBounds(13*72+30, 20, 200, 120); getContentPane().setLayout(null); setVisible(true); theRobot = r; turnBtn = new JButton("Turn"); turnBtn.setBounds(60, 10, 80, 30); turnBtn.addActionListener(this); getContentPane().add(turnBtn, 0); moveBtn = new JButton("Step"); moveBtn.setBounds(60, 50, 80, 30); moveBtn.addActionListener(this); getContentPane().add(moveBtn, 0); repaint(); } /** This is an event hanlder for both buttons. * post: e.getSource()==turnBtn implies postcondition of theRobot.rotateClockwise() * and e.getCourse==moveBtn implies postcondition of theRobot.moveByOneStep() */ public void actionPerformed(ActionEvent e) { if (e.getSource() == turnBtn) theRobot.rotateClockwise(); else if (e.getSource() == moveBtn) theRobot.moveByOneStep(); }}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -