java吃豆豆游戏-1控制按钮编写
2013-05-25 21:28
483 查看
个人习惯,先写按钮
import javax.swing.*; import java.awt.*; import java.awt.event.*; import javax.swing.border.*; public class GameController extends JPanel implements ActionListener { private JButton exitButton = new JButton("Exit"); private JButton settingsButton = new JButton ("Settings"); private JButton aboutButton = new JButton ("About"); private JButton keysButton = new JButton ("Keys"); private JLabel label = new JLabel (" 0 "); private Background bg; public GameController (Background bg){ super(new FlowLayout(FlowLayout.CENTER)); this.bg = bg; setOpaque(false);//设置组件透明 exitButton.addActionListener(this); settingsButton.addActionListener(this); aboutButton.addActionListener(this); keysButton.addActionListener(this); //setBorder() 是使用Border 边框 ,Border 是特殊的Swing组件,为Swing组件提供不同的边框修饰 label.setBorder(BorderFactory.createEtchedBorder(EtchedBorder.RAISED)); add(label); add(exitButton); add(aboutButton); add(settingsButton); add(keysButton); } public JLabel getLabel(){ return label; } public void actionPerformed (ActionEvent e){ if (e.getSource()==exitButton){ System.exit(0); } else if (e.getSource()==settingsButton){ } else if (e.getSource()==aboutButton){ JOptionPane.showMessageDialog(getParent(), "Eater Version 1.1" + "\nProgrammed by K.I.K"); } else if (e.getSource()==keysButton){ JOptionPane.showMessageDialog(getParent(), "Use arrow keys to move the eater"); } else return; } }
相关文章推荐
- java贪吃蛇游戏编写代码
- Java编写飞行游戏
- 用java编写的一个小财富游戏
- Java 小例子:编写石头剪刀布游戏
- java编写的简陋的三子棋游戏
- Java 风扇:编写程序,显示3个风扇,用控制按钮开动和停止风扇。可以同时开动和停止3个风扇,也可以分别开动和停止每一个风扇
- 用Java编写的一个抽奖游戏
- 利用java编写的精灵吃豆的游戏
- Java编写的24点纸牌游戏
- java编写简单五子棋游戏感悟
- MyGame--java语言编写的打飞机游戏(附源码下载)
- java编写游戏的几本参考书
- java编写的简单图片匹配游戏
- Java 游戏 连连看 语言编写 多媒体
- java编写的猜数字游戏
- 使用java编写计算24点游戏程序
- Java编写网络打字游戏
- Java编写的五子棋游戏
- Java编写掷骰子游戏
- 用Java编写扫雷游戏--算法思考