⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 gameapplet.java

📁 一个java的游戏程序
💻 JAVA
字号:
import java.awt.*; import java.awt.event.*;import java.applet.*;public class GameApplet    extends Applet    implements ActionListener{    // data    private Games _games;    private RulesFrame _rulesWindow;     // menus    private PopupMenu _fileMenu;    private MenuItem _newItem;    private MenuItem _exitItem;    private PopupMenu _helpMenu;    private Menu _aboutMenu;    private MenuItem _rulesItem;    private MenuItem _ticRulesItem;    private PopupMenu _gameMenu;    private MenuItem _tictactoeItem;        private MenuItem _aboutItem;    // buttons        private Panel _buttonPanel;    private Button _fileButton;    private Button _helpButton;    // initialization    public void init() { 	setLayout(new BorderLayout());		// buttons	_buttonPanel = new Panel(new FlowLayout(FlowLayout.LEFT));	add(_buttonPanel, "North");	// File menu	_fileButton = new Button("File");	_fileButton.addActionListener(this);	_buttonPanel.add(_fileButton);	_fileMenu = new PopupMenu("File");	add(_fileMenu);	_newItem = new MenuItem("New");	_fileMenu.add(_newItem);	_exitItem = new MenuItem("Exit");	_fileMenu.add(_exitItem);	_fileMenu.addActionListener(this);	// Help menu	_helpButton = new Button("Help");	_helpButton.addActionListener(this);	_buttonPanel.add(_helpButton);	_helpMenu = new PopupMenu("Help");	_helpMenu.addActionListener(this);	add(_helpMenu);	_rulesItem = new MenuItem("Rules");	_helpMenu.add(_rulesItem);		_aboutMenu = new Menu("About");	_helpMenu.add(_aboutMenu);       	_aboutItem = new MenuItem("Created by Eelco Visser, 1999, 2000");	_aboutMenu.add(_aboutItem);	// game		_games = new Games();	play("TicTacToe");    }    // start a game    public void play(String name)    {	Game game;	if(!(_games.isCurrent(name)))	    {		game = _games.getCurrent();		if(game != null)		    remove(game);				game = _games.select(name);				if(game != null)		    {			Dimension d = game.getSize();			add(game, "Center");			resize(d.width,d.height + 70);		    }	    }    }    /**     * Sets up actions to be performed when mouseclicks are detected     * on the menuitems.     */    public void actionPerformed(ActionEvent e)    {	if(e.getActionCommand() == "File")	    {		_fileMenu.show(this, 5, 5);	    }	else if(e.getActionCommand() == "New")	    {		if(_games.getCurrent() != null)		    _games.getCurrent().newGame();	    }	else if(e.getActionCommand() == "Exit")	    {	    }	else if(e.getActionCommand() == "Help")	    {		_helpMenu.show(this, 45, 5);	    }	else if(e.getActionCommand() == "About")	    {	    }	else if(e.getActionCommand() == "Rules")	    {		_rulesWindow = new RulesFrame(_games);	    }	else 	    {		play(e.getActionCommand());	    }    }}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -