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

📄 jtetris2007.java

📁 一个java的俄罗斯方块实现
💻 JAVA
字号:
package cs111.tetris.gui;import java.applet.Applet;import java.awt.BorderLayout;import java.awt.Container;import javax.swing.JComponent;import javax.swing.JFrame;import javax.swing.WindowConstants;import cs111.tetris.data.Game;/** * This class contains is the "main" driver code for the Tetris game. * It can be run either as an applet in web-browser window or as * a regular standalone Java application. *  * @author kdvolder */public class JTetris2007 extends Applet {		/**	 * Create the Game state datastructure (Model) and assembles     * it with the GUI components that represent the View and Controller.     * Place these components into the provided UI container.     * <p>     * The main application check for a command-line argument "-test"     * and enables testMode if it is set.     *      * @param container - The container where to the GUI components are added     *                    The container is either the content pane of an     *                    Applet (created by your webbrowser) or the content pane      *                    of a JFrame created by the Standalone application.	 */	public static void setUpUI(Container container, boolean testMode) {		container.setLayout(new BorderLayout());				// Create the data structure that represents that Game state (the "Model").		Game game = new Game(); // No parameters -> use standard tetris dimensions				if (testMode)			game.enableTestMode();               		// Create the JBoard UI component that displays the tetris board graphically.		JBoard tetris = new JBoard(game);		container.add(tetris, BorderLayout.WEST);		// Create the control panel (with start, stop buttons etc.) that		// sits right next to the gameboard in the window.		JControlPanel panel = new JControlPanel(game);		container.add(panel, BorderLayout.CENTER);	}		/**	 * This overrides the init method from the Applet class. This will be	 * called by your webbrowser when JTetrisMain is run as an Applet.	 */	public void init() {		setUpUI(this, getParameter("test")!=null);	}	/**	 * This is main method which is used when you run JTetris2007 as a	 * regular Java application. Unlike the applet version the application	 * is responsible for creating its own Frame (window) and showing it	 * on the screen.	 */	public static void main(String[] args) {		boolean testing = false;		JFrame frame = new JFrame("Tetris 2000");		Container container = (JComponent)frame.getContentPane();				if (args.length>0 && args[0].equals("-test")) {			testing = true;		}		setUpUI(container, testing); // Add UI components to the container.				// This is pretty "standard" code to show the window on the screen:		frame.pack();		frame.setVisible(true);				//System.out.println("W:"+container.getWidth()+" H:"+container.getHeight());		// Quit on window close:		frame.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);	}	}

⌨️ 快捷键说明

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