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

📄 mainui.java

📁 一个用java-swing编写的连连看游戏例子
💻 JAVA
字号:
/*
 * 创建日期 2004-11-22
 *
 * TODO 要更改此生成的文件的模板,请转至
 * 窗口 - 首选项 - Java - 代码样式 - 代码模板
 */
package game;

import java.awt.*;
import java.net.URL;
import javax.swing.*;
/**
 * @author Jerry703 
 *
 * TODO 要更改此生成的类型注释的模板,请转至
 * 窗口 - 首选项 - Java - 代码样式 - 代码模板
 */
public class MainUI extends JFrame implements Runnable{
	public GroupButton mainpanel;
	public MenuPanel menupanel;
	public BorderLayout layout;
	public MenuListener listener;
	JPanel pan1=new JPanel();
	JPanel pan2=new JPanel();
	
	
	
	public MainUI(String title){
		super(title);
		
		GridLayout flow=new GridLayout(1,1);
		pan1.setLayout(flow);
		URL url=MainUI.class.getResource("image/main.gif");
		JLabel la1=new JLabel(new ImageIcon(url));
		pan1.add(la1);
		
		float color[]=new float[3];
		Color.RGBtoHSB(0,128,192,color);
		pan1.setBackground(Color.getHSBColor(color[0],color[1],color[2]));
		CardLayout card=new CardLayout();
		
		this.getContentPane().setLayout(card);
		layout = new BorderLayout();
		pan2.setLayout(layout);
		mainpanel = new GroupButton(10,10);
		menupanel = new MenuPanel();
		pan2.add(mainpanel,BorderLayout.CENTER);
		pan2.add(menupanel,BorderLayout.SOUTH);
		listener = new MenuListener(this);
		for (int i=1;i<mainpanel.getComponentCount();++i){
			SingleButton temp = (SingleButton)(mainpanel.getComponent(i));
			temp.addActionListener(listener);
		}
		menupanel.reset.addActionListener(listener);
		menupanel.quit.addActionListener(listener);
		
		this.getContentPane().setLayout(card);
		this.getContentPane().add("p1",pan1);
		this.getContentPane().add("p2",pan2);
		this.setDefaultCloseOperation(EXIT_ON_CLOSE);
		this.pack();
		this.setResizable(false);
		this.setVisible(true);
		//this.getContentPane().add(pan1);
		//this.getContentPane().add(pan2);
		
		card.show(this.getContentPane(),"p1");
		long x=System.currentTimeMillis();
	
		while(System.currentTimeMillis()-x<3000){
			
		}
		card.show(this.getContentPane(),"p2");
		//this.setVisible(false);
	}

	public static void main(String[] args) {
		MainUI game = new MainUI("爪子的连连看 beta1.0   欢迎提出宝贵意见");
		
		Thread check = new Thread(game);
		long time=System.currentTimeMillis();
		long timeleft;
		while(true){
			timeleft=90-(int)(System.currentTimeMillis()-time)/1000;
			game.menupanel.lblshow.setText("目前剩余时间为" + timeleft + "秒");
			try {
				check.sleep(1000);
			} catch (InterruptedException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
			if(timeleft==0)
				System.exit(0);
		}
		
		
	}

	/* (non-Javadoc)
	 * @see java.lang.Runnable#run()
	 */
	public void run() {
		long time=System.currentTimeMillis();
		// TODO Auto-generated method stub
		
	}
}

⌨️ 快捷键说明

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