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

📄 jcgamewindow.java

📁 非常好的java collapse游戏代码
💻 JAVA
📖 第 1 页 / 共 3 页
字号:
        //m_TextAreaNotes.setBorder( new TitledBorder( new SoftBevelBorder( SoftBevelBorder.LOWERED ), "Notes" ) );        m_TextAreaNotes.setFont( m_NormalFont );        m_TextAreaNotes.setEditable( false );        m_TextAreaNotes.setOpaque( false );        m_TextAreaNotes.setFocusable( false );        m_TextAreaNotes.setContentType( "text/html" );        m_TextAreaNotes.setText( "<center>" +        						 "<font color=white size=2><b><br>"+ APPLICATION_NAME + "</b><br>" +        						 JCModel.getVersion() + "/" + APPLICATION_VERSION + "<br>"+        						 "Build in " + APPLICATION_DATE + "<br>" +        						 "<i><u>By 蓃ico GR</u></i></center></font>" );                //NewGame    	//----------------------------------------------------------------------------------------------------------------------------------------------------------------------        m_ButtonNewGame = new JCButton( "New" );        m_ButtonNewGame.setMnemonic( 'N' );        m_ButtonNewGame.setPreferredSize( new Dimension( 100, 25 ) );        m_ButtonNewGame.addActionListener( new ActionListener() {        	public void actionPerformed( ActionEvent actionEvent ) {        		if( confirmEndGame() ) {        			//new game        			m_SoundControl.doEvent( "gameover", SoundEvent.STOP );        			m_SoundControl.doEvent( "intro", SoundEvent.STOP );        			m_SoundControl.doEvent( "music01", SoundEvent.PLAY );       				m_GameControl.reset();       				m_JCComponent.loadLevel( m_LevelList.getLevel( 0 ) );       				m_JCComponent.start();        		}        	}        });                //ButtonPause    	//----------------------------------------------------------------------------------------------------------------------------------------------------------------------        m_ButtonPause = new JCButton( "Pause" );        m_ButtonPause.setEnabled( false );        m_ButtonPause.setMnemonic( 'P' );        m_ButtonPause.setPreferredSize( new Dimension( 100, 25 ) );        m_ButtonPause.addActionListener( new ActionListener() {        	public void actionPerformed( ActionEvent actionEvent ) {        		if( m_JCComponent.isRunning() )	        		m_JCComponent.setPause( !m_JCComponent.isPaused() );        	}        });                //ButtonOptions    	//----------------------------------------------------------------------------------------------------------------------------------------------------------------------        m_ButtonOptions = new JCButton( "Options" );        m_ButtonOptions.setMnemonic( 'O' );        m_ButtonOptions.setPreferredSize( new Dimension( 100, 25 ) );        m_ButtonOptions.addActionListener( new ActionListener() {        	public void actionPerformed( ActionEvent actionEvent ) {        		if( m_OptionsWindow == null )        			m_OptionsWindow = new OptionsWindow( m_SoundControl );        		        		if( !isApplet() )        			m_OptionsWindow.setAlwaysOnTop( true );        		        		m_OptionsWindow.setVisible( true );        	}        });                //ButtonQuit    	//----------------------------------------------------------------------------------------------------------------------------------------------------------------------        m_ButtonQuit = new JCButton( "Quit" );        m_ButtonQuit.setMnemonic( 'Q' );        m_ButtonQuit.setPreferredSize( new Dimension( 100, 25 ) );        m_ButtonQuit.addActionListener( new ActionListener() {        	public void actionPerformed( ActionEvent actionEvent ) {        		if( confirmEndGame() )        			exitGame();        	}        });        if( isApplet() )        	m_ButtonQuit.setVisible( false );                //StatusPanel        //----------------------------------------------------------------------------------------------------------------------------------------------------------------------        m_StatusPanel = new JCPanel( statusLayout, Color.WHITE, Color.BLACK );        m_StatusPanel.setPreferredSize( new Dimension( 100, 0 ) );        addComponent( m_LabelLevelName, m_StatusPanel, statusLayout, constraints,    		  GridBagConstraints.HORIZONTAL, 0, 0, 2, 1, 100, 1, 2, 2, 2, 2 );        addComponent( m_SeparatorGameStatus, m_StatusPanel, statusLayout, constraints,      		  GridBagConstraints.BOTH, 1, 0, 2, 1, 100, 1, 2, 2, 2, 2 );                addComponent( m_LabelScore, m_StatusPanel, statusLayout, constraints,  			  GridBagConstraints.NONE, 2, 0, 1, 1, 1, 1, 2, 2, 2, 2 );        addComponent( m_LabelScorePoints, m_StatusPanel, statusLayout, constraints,  			  GridBagConstraints.HORIZONTAL, 2, 1, 1, 1, 100, 1, 2, 2, 2, 2 );        addComponent( m_LabelLevel, m_StatusPanel, statusLayout, constraints,   			  GridBagConstraints.NONE, 3, 0, 1, 1, 1, 1, 2, 2, 2, 2 );        addComponent( m_LabelLevelCount, m_StatusPanel, statusLayout, constraints,   			  GridBagConstraints.HORIZONTAL, 3, 1, 1, 1, 100, 1, 2, 2, 2, 2 );        addComponent( m_LabelLines, m_StatusPanel, statusLayout, constraints,			  GridBagConstraints.NONE, 4, 0, 1, 1, 1, 1, 2, 2, 2, 2 );        addComponent( m_LabelLinesRemains, m_StatusPanel, statusLayout, constraints,			  GridBagConstraints.HORIZONTAL, 4, 1, 1, 1, 100, 1, 2, 2, 2, 2 );        addComponent( m_LabelRecord, m_StatusPanel, statusLayout, constraints,      		  GridBagConstraints.BOTH, 5, 0, 2, 1, 1, 1, 2, 2, 2, 2 );        addComponent( m_SeparatorRecord, m_StatusPanel, statusLayout, constraints,      		  GridBagConstraints.BOTH, 6, 0, 2, 1, 1, 1, 2, 2, 2, 2 );        addComponent( m_LabelHighScore, m_StatusPanel, statusLayout, constraints,      		  GridBagConstraints.NONE, 7, 0, 1, 1, 1, 1, 2, 2, 2, 2 );        addComponent( m_LabelHighScorePoints, m_StatusPanel, statusLayout, constraints,      		  GridBagConstraints.HORIZONTAL, 7, 1, 1, 1, 100, 1, 2, 2, 2, 2 );        addComponent( m_LabelHighLevel, m_StatusPanel, statusLayout, constraints,			  GridBagConstraints.NONE, 8, 0, 1, 1, 1, 1, 2, 2, 2, 2 );		addComponent( m_LabelHighLevelCount, m_StatusPanel, statusLayout, constraints,			  GridBagConstraints.HORIZONTAL, 8, 1, 1, 1, 100, 1, 2, 2, 2, 2 );        addComponent( m_TextAreaNotes, m_StatusPanel, statusLayout, constraints,        	  GridBagConstraints.BOTH, 9, 0, 2, 1, 100, 100, 1, 1, 1, 1 );                //MainPanel        //----------------------------------------------------------------------------------------------------------------------------------------------------------------------        m_MainPanel = new JCPanel( mainLayout, Color.BLACK, Color.WHITE );        addComponent( m_JCComponent, m_MainPanel, mainLayout, constraints,        		  GridBagConstraints.BOTH, 0, 0, 1, 6, 100, 100, 15, 0, 5, 5 );        addComponent( m_LabelGameStatus, m_MainPanel, mainLayout, constraints,        		  GridBagConstraints.NONE, 0, 1, 1, 1, 1, 1, 15, 5, 5, 5 );        addComponent( m_StatusPanel, m_MainPanel, mainLayout, constraints,    			  GridBagConstraints.BOTH, 1, 1, 1, 1, 1, 100, 15, 5, 5, 5 );        addComponent( m_ButtonNewGame, m_MainPanel, mainLayout, constraints,        		  GridBagConstraints.HORIZONTAL, 2, 1, 1, 1, 1, 1, 15, 5, 0, 0 );        addComponent( m_ButtonPause, m_MainPanel, mainLayout, constraints,  			  	  GridBagConstraints.HORIZONTAL, 3, 1, 1, 1, 1, 1, 15, 5, 0, 0 );        addComponent( m_ButtonOptions, m_MainPanel, mainLayout, constraints,    			  GridBagConstraints.HORIZONTAL, 4, 1, 1, 1, 1, 1, 15, 5, 0, 0 );                addComponent( m_ButtonQuit, m_MainPanel, mainLayout, constraints,    			  GridBagConstraints.HORIZONTAL, 5, 1, 1, 1, 1, 1, 15, 5, 0, 5 );                //this    	//----------------------------------------------------------------------------------------------------------------------------------------------------------------------        getContentPane().add( m_MainPanel, BorderLayout.CENTER );    	//Window        //----------------------------------------------------------------------------------------------------------------------------------------------------------------------    	if( m_JFrame != null ) {    		m_JFrame.getContentPane().add( this );    		m_JFrame.setTitle( APPLICATION_NAME + " ::: " + APPLICATION_VERSION );    		m_JFrame.setDefaultCloseOperation( WindowConstants.DO_NOTHING_ON_CLOSE );    		m_JFrame.pack();    		m_JFrame.setLocationRelativeTo( null );    		m_JFrame.addWindowListener( new WindowAdapter() {	        	public void windowClosing( WindowEvent e ) {	        		if( confirmEndGame() ) {	        			exitGame();	        			m_JFrame.dispose();	        		}	        	}	        });    		m_JFrame.setVisible( true );    		m_JFrame.validate();    	}    	    	//Effects        //----------------------------------------------------------------------------------------------------------------------------------------------------------------------    	m_IntroEffect = new FadeImageEffect( DLHelper.getInstance().getImage( "/sourceforge/net/projects/jcollapse/game/resources/images/main-background.jpg" ), Fade.IN, true );    	m_LevelStartedEffect = new TextEffect( 1500, false );    	m_PauseEffect = new TextEffect( "Paused", 0, true );    	m_GameOverEffect = new TextEffect( "Game Over", 15000, true );    	    	//means that components are initiazed    	m_IsComponentsInitialized = true;    }        private void addComponent( Component component, JPanel panel,    					       GridBagLayout layout, GridBagConstraints constraints,    					       int fill, int row, int col, int width, int height,    					       int weightX, int weightY,    					       int insetLeft, int insetRight, int insetTop, int insetButton )     {    	constraints.insets = new Insets( insetTop, insetLeft, insetButton, insetRight );    	constraints.gridx = col;    	constraints.gridy = row;    	constraints.gridwidth = width;    	constraints.gridheight = height;    	constraints.weightx = weightX;    	constraints.weighty = weightY;    	constraints.fill = fill;    	    	layout.setConstraints( component, constraints );    	    	panel.add( component );    }        /**     * Draw a wait message while interface is loaded     *    private void drawLoadUIWaitMessage() {    	final String WAIT_MESSAGE = "Loading, please wait...";    	java.awt.Graphics g = getGraphics();        g.setColor( Color.BLACK );        g.fillRect( 0, 0, getWidth(), getHeight() );        g.setFont( new java.awt.Font( "SansSerif", java.awt.Font.BOLD, 20 ) );        g.setColor( Color.WHITE );        g.drawString( WAIT_MESSAGE ,        		(int)( getWidth() / 2 - ( g.getFontMetrics().getStringBounds( WAIT_MESSAGE, g ).getWidth() / 2 ) ),        		getInsets().top + ( getWidth() / 2 ) );        repaint();    }*/        public void exitGame() {    	//terminate sound controler    	m_SoundControl.terminate();		    	//terminate main view for game    	m_JCComponent.reset();				//dispose option window		if( m_OptionsWindow != null )			m_OptionsWindow.dispose();				//dispose window (if is not an applet)		if( m_JFrame != null )			m_JFrame.dispose();    }        private String checkForCommandLineParameter( String param ) {    	if( m_CommandLineParameters == null || param == null )    		return null;    	    	for( String s : m_CommandLineParameters )    		if( param.equalsIgnoreCase( s ) )    			return s;    	    	return null;    }        private boolean confirmEndGame() {		//if game is running, confirm game exit with user		if( m_JCComponent.isRunning() &&			JOptionPane.showConfirmDialog( JCGameWindow.this, "Game in progress. End current game?", "Question", JOptionPane.YES_NO_CANCEL_OPTION, JOptionPane.QUESTION_MESSAGE ) != JOptionPane.YES_OPTION )		{			return false;		}		return true;    }        private boolean isApplet() {    	return ( m_JFrame == null );    }}

⌨️ 快捷键说明

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