g.setColor(Color.blue);
g.fillRect(node.x, node.y, node.H, node.W);
}
}
class SnakeFrame extends JFrame {
private JLabel statusLabel;
private JLabel speedLabel;
private JLabel scoreLabel;
private JPanel snakePanel;
private Snake snake;
private JMenuBar bar;
JMenu gameMenu;
JMenu helpMenu;
JMenu speedMenu;
JMenuItem newItem;
JMenuItem pauseItem;
JMenuItem beginItem;
JMenuItem helpItem;
JMenuItem aboutItem;
JMenuItem slowItem;
JMenuItem midItem;
JMenuItem fastItem;
public SnakeFrame() {
init();
ActionListener l = new ActionListener() {
public void actionPerformed(ActionEvent e) {
if (e.getSource() == pauseItem)
snake.isRun = false;
if (e.getSource() == beginItem)
snake.isRun = true;
if (e.getSource() == newItem) {
newGame();
}
// ------------菜单控制运行速度
if (e.getSource() == slowItem) {
snake.speed = Snake.SLOW;
speedLabel.setText("Slow");
}
if (e.getSource() == midItem) {
snake.speed = Snake.MID;
speedLabel.setText("Mid");
}