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

📄 hanoactionevent.java

📁 一个游戏。是用java基础写的一个游戏。供给java初学者下载
💻 JAVA
字号:
package com.Luoweixun;

import java.awt.CardLayout;
import java.awt.Color;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.io.IOException;

import javax.swing.JButton;
import javax.swing.JOptionPane;
import javax.swing.JPanel;


public class HanoActionEvent implements ActionListener{
	/**
	 * 事件监听,按钮监听
	 */
	HanoPanel hf=null;
	JPanel fatherPanel=null;
	CardLayout cardLayout=null;
//	三个参数构造方法
	public HanoActionEvent(HanoPanel hf,JPanel fatherPanle,CardLayout cardLyout){

		this.hf=hf;
		this.fatherPanel=fatherPanle;
		this.cardLayout=cardLyout;	
	}
	public void actionPerformed(ActionEvent e) {
		Object s=e.getSource();
		if(s==hf.exits){
			exits();
		}
		else if(s==hf.config){
			config();
		}
		else{
			reset();
		}
			
	}
//	返回导航面板
	public void exits(){		
		cardLayout.show(fatherPanel,"navigate");
	}
//	重置参数和容器
	public void reset(){
		for(int i=0;i<30;i++){
			if(i%10!=0){
				hf.hanoPane[i].updateUI();
			}
		}
		for(int i=0;i<9;i++){
			hf.dish[i].setBackground(Color.blue);
		}
		hf.addDishes(hf.Level);
		
	}
//	配置参数,任意设置盘子个数]
	public void config(){
		try {		
		String str=(String) JOptionPane.showInputDialog(null,"请输入1-9的等级","3");	
		int t=Integer.parseInt(str);
		hf.addDishes(t);
		for(int i=0;i<30;i++){
			if(i%10!=0){
				hf.hanoPane[i].updateUI();
			}
		}
		}
			catch (Exception e) {
				JOptionPane.showMessageDialog(null, "请输入1-9的等级!");				
			}
			JOptionPane.showMessageDialog(null, "设置成功!");
			hf.sum=0;
			hf.text.setText("步数: "+hf.sum	);
			hf.text1.setText("等级:"+hf.Level);
	}
}

	
	


⌨️ 快捷键说明

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