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

📄 gameframe.java

📁 “连连看”源程序 “连连看”源程序 “连连看”源程序
💻 JAVA
字号:
/**
 * 
 *@FileName GameFrame.java 05/10/20
 * 
 *@Copyright (c) 2005 Tender, Inc. All Rights Reserved.
 * 
 *@changeTime
 *
 *@version V1.0
 *
 */

import java.awt.*;
import java.awt.event.*;
import javax.swing.*;

public class GameFrame extends JFrame implements ActionListener
{
	
	private GamePanel gamePanel;
	
	private JMenuBar 	mainMenuBar;
	
	private JMenu 		gameMenu,  helpMenu;
	
	private JMenuItem	beginMenu, tsMenu, reRangMenu, exitMenu, helpMenuI, aboutMenu;
		
	private Timer time;
	
	private JProgressBar proBar;
	
	private int count = 0, timeCount = 0;
	
	private JDialog gameStateDia; 
		
	public GameFrame(){
		
		super("连连看V1.0");
		
		//use initFrame() inition panel
		initFrame();
		
		initDialog();
				
	}
	
	private void initFrame(){
					
		proBar = new JProgressBar( 0, 100 );
		
		time = new Timer( 3000, this );
		
		time.start();
			
		gamePanel = new GamePanel();

		initMenuBar();
		
		this.setJMenuBar(mainMenuBar);
		
		this.setSize( 600, 600);//gamePanel.getPanelWidth(), gamePanel.getPanelHeight());
		
		this.setResizable(false);
		
		/*
			Dimension src = Toolkit.getDefaultToolkit().getScreenSize();	
			int x = ( src.width - this.getWidth() ) / 2;	
			int y = ( src.height - this.getHeight() ) / 2;	
			this.setLocation( x, y );
			
			the Frame display center 
		*/
		
		Dimension src = Toolkit.getDefaultToolkit().getScreenSize();
		
		int x = ( src.width - this.getWidth() ) / 2;
		
		int y = ( src.height - this.getHeight() ) / 2;
		
		this.setLocation( x, y );
		
		Container con = this.getContentPane();
		
		con.setLayout( new BorderLayout() );
						
		con.add( gamePanel, BorderLayout.CENTER );
				
		con.add( proBar, BorderLayout.SOUTH );
	}
	
	private void initMenuBar(){
		
		mainMenuBar = new JMenuBar();
		
		gameMenu = new JMenu("游戏选项");
				
		helpMenu = new JMenu("帮助选项");
		
		mainMenuBar.add(gameMenu);	
	
		mainMenuBar.add(helpMenu);
		
		beginMenu 	= new JMenuItem("开始游戏");
		tsMenu 		= new JMenuItem("游戏提示");
		reRangMenu 	= new JMenuItem("重列");
		exitMenu 	= new JMenuItem("退出游戏");
		helpMenuI 	= new JMenuItem("游戏帮助");
		aboutMenu 	= new JMenuItem("关于游戏");
		
		beginMenu.addActionListener(this);
		tsMenu.addActionListener(this);
		reRangMenu.addActionListener(this);
		exitMenu.addActionListener(this);
		helpMenu.addActionListener(this);
		aboutMenu.addActionListener(this);
		
		gameMenu.add(beginMenu);
		gameMenu.add(tsMenu);
		gameMenu.add(reRangMenu);
		gameMenu.addSeparator();
		gameMenu.add(exitMenu);
		
		helpMenu.add(helpMenuI);
		helpMenu.addSeparator();
		helpMenu.add(aboutMenu);
		
				
	}
	
	private void initDialog()
	{
		gameStateDia = new JDialog(this, "开始新游戏?");
		
	}
	
	public void actionPerformed( ActionEvent e ){
		
		if( e.getSource() == beginMenu ){
				
			//gamePanel.begin();
			
			//gamePanel.reRange();
			
			//timeCount = 0;
				
					
		}else if( e.getSource() == reRangMenu){
			
			gamePanel.reRange();
			
		}
		else if( e.getSource() == exitMenu){
			
			System.exit(0);
			
		}
		else if( e.getSource() == tsMenu ){
			
			gamePanel.tiShi();
			
		}
		else if( e.getSource() == time ){
			
			if( timeCount < 100){
				
				timeCount++;
				
				proBar.setValue(timeCount);
			
			}else{
				
				
				
			}
			
		}
		
	}
	
}

⌨️ 快捷键说明

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