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

📄 pane2.java

📁 JAVA 写的五子棋
💻 JAVA
字号:
import java.awt.*;
import java.awt.event.*;
import java.util.Calendar;
import java.util.Date;
import javax.swing.*;

//import tuoxiang.MyActionListener;

import java.awt.geom.*;

public class Pane2 extends JPanel {
	public Graphics g;

	public static JLabel j1;

	public static JLabel j2;

	public static JLabel j3;

	public static JLabel j4;

	static int count = 0;
	
	int mtime=Integer.parseInt(Option.settime);
	
	public static Timer timer;
	Icon bug=new ImageIcon("4.jpg");
	public JLabel text1=new JLabel("选择头像");
	public JMenuBar bar=new JMenuBar();
	private JMenu option1=new JMenu("1.jpg");
	private JMenu option2=new JMenu("1.jpg");
	private JMenuItem[] m=new JMenuItem[8];
	private JLabel pic1=new JLabel("",bug,0);
	private JLabel pic2=new JLabel("",bug,0);

	public Pane2() {
		this.setLayout(null);

		
		pic1.setSize(110,110);
		pic1.setLocation(10,10);
		text1.setSize(60,20);
		text1.setLocation(10,130);
		
		bar.setSize(40,20);
		bar.setLocation(80,130);
		bar.add(option1);
		
		
		j1 = new JLabel();
		j1.setText("限时:"+mtime+"分钟");
		j1.setLocation(120, 10);
		j1.setSize(150, 30);
		this.add(j1);

		j2 = new JLabel("倒计时:"+formattime(mtime)+":"+"00");
		j2.setLocation(120, 50);
		j2.setSize(150, 30);
		this.add(j2);

		j3 = new JLabel("步数:0");
		j3.setLocation(120, 90);
		j3.setSize(150, 30);
		this.add(j3);
		
		add(pic1);
		add(text1);
	    add(bar);
		
		for(int i=0;i<8;i++){
			m[i]=new JMenuItem((i+1)+".jpg");
			m[i].addActionListener(new MyActionListener((i+1),1) );
		}
		for(int i=0;i<8;i++){
			option1.add(m[i]);
		}
	
		
		ActionListener listener = new ActionListener() {
		
			public void actionPerformed(ActionEvent e) {
				count++;
				
				
				if(Caidan.Ctime[0]!=0){
					mtime=Caidan.Ctime[0];
				}
				
				
				int nt=mtime*60*1000-count*100;
				int minute=(int)(nt/60000);
				int second=(nt-minute*60000)/1000;
				
				j2.setText("倒计时:"+formattime(minute)+":"+formattime(second));
			if(second<0){
				JOptionPane.showMessageDialog(ChessBoard.getJF(),"白棋输了");
				timer.stop();
				nt=0;
				ChessBoard.a.removeMouseListener(ButtonPanel.mt[0]);
				Caidan.time.enable(true);
				
			}
				
			}
		};
		timer = new Timer(100, listener);
		//timer.start();
	}
	
	public static Timer getTimer(){
		return timer;
	}
	
	public static JLabel getj3(){
		return j3;
	}
	
	public static JLabel getj2(){
		return j2;
	}
	
	public String formattime(int t){
		if(t<10&&t>-1){
			return ("0"+Integer.toString(t));
		}
		if(t>9){
			return (Integer.toString(t));
		}
		else{
			return ("00");
		}
	}

	private class MyActionListener implements ActionListener {

		private int option_ID;
		
		private int label_ID;
		
		MyActionListener(int i,int j) {
			option_ID = i;
			label_ID = j;
		}
		
		public void actionPerformed(ActionEvent e) {
			JLabel pic;
			JMenu option;
			
			if(label_ID == 1) {
				pic = pic1;
				option = option1;
			} else {
				pic = pic2;
				option =option2;
			}
			pic.setIcon(new ImageIcon(option_ID+".jpg"));
			option.setText(option_ID+".jpg");
		
		}
		
	}

}
















⌨️ 快捷键说明

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