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

📄 frmtaxis.java

📁 小游戏--淘金者 主要用到了双缓冲平面作图
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
	   labPass.setBounds(25,78,100,25);
	   labPass.setForeground(Color.GREEN);
	   labPass.setFont(new Font(null,Font.BOLD,12));
	   add(labPass);
	   
	  
	   labPerish=new JLabel("蝙蝠数:"+" "+perish);
	   labPerish.setBounds(145,43,100,25);
	   labPerish.setForeground(Color.GREEN);
	   labPerish.setFont(new Font(null,Font.BOLD,12));
	   add(labPerish);
	   
	   
	   labLift=new JLabel("生命数:"+" "+lift);
	   labLift.setBounds(145,78,100,25);
	   labLift.setForeground(Color.GREEN);
	   labLift.setFont(new Font(null,Font.BOLD,12));
	   add(labLift);
	   
	  
	   labScore=new JLabel("积分:"+" "+score);
	   labScore.setBounds(255,78,100,25);
	   labScore.setForeground(Color.GREEN);
	   labScore.setFont(new Font(null,Font.BOLD,12));
	   add(labScore);
	   
}

}



class PlayerPanel extends JPanel{		
	private Image player;
//玩家信息面板
	
	public PlayerPanel()
	{
		try
		{
			player=ImageIO.read(new File("image\\player.BMP"));
		}
		catch(IOException exception)
		{
			exception.printStackTrace();
		}
	}
	public void paintComponent(Graphics g)
	{
		super.paintComponent(g);
		
		g.drawImage(player,0,0,null);
			
		
	}
	





}

//用来保存OrderPane面板的对话框,实现排行榜信息框的移动
class OrderPane extends JDialog implements Runnable
{  
	private Thread t;
	private int x;
	private int y;
	private int fy;
	private int fx;
	private int endx;
	private JLabel labCancel;
	private JLabel labName;
	private JLabel labScore;
	private JButton button;
	private EnterPanel enterPanel;
	private Enumeration enumeration;
	private Properties properties;
	private String []scoreCount;
	private String []name;
	private JLabel[] labNameValue;
	private JLabel[] labScoreValue;
	private Integer score;
		
	public OrderPane(final TaxisFrame frmTaxis, EnterPanel enterPanel)
	{  
	   super(frmTaxis, "", false);         
	   setSize(420,305);
	   this.setUndecorated(true);
		
	   this.enterPanel=enterPanel;
	   this.getContentPane().setBackground(Color.RED);
	   this.setLayout(null);
	   
	   this.createLabel(this);
	   OrderPanel panel = new OrderPanel();
	   panel.setBounds(0,0,420,305);
	   add(panel);
	   
	   this.readFile();
	   this.setLabValue();
		  fx=frmTaxis.getX ();
		  fy=frmTaxis.getY();
		  x=(fx+frmTaxis.getWidth());
		  y=(fy+frmTaxis.getHeight()-this.getHeight());
		  
		  endx = x-this.getWidth();		  
		  this.setLocation(x,y);
		  t=new Thread(this);
		  t.start();
		  
		  //labCancel鼠标事件,以后进行优化
		  button.addMouseListener(new 
				  MouseAdapter(){

					public void mouseClicked(MouseEvent e) {
					//	frmTaxis.setVisible(false);
					//	Head.showFrmFunction(true);
					System.exit(0);
					}

					public void mouseEntered(MouseEvent e) {
						 button.setForeground(Color.BLACK);
						    
						    button.setBackground(Color.GREEN);
						
					}

					public void mouseExited(MouseEvent e) {
						 button.setForeground(Color.GREEN);
						   button.setBackground(Color.BLACK);
						
					}
			  
		  });
	}
	
	public void run(){
		
		for(int i=x;i>endx;i=i-11)
		  {
			  this.setLocation(i,y);
			  
			  try {
				t.sleep(0);

			} catch (InterruptedException e1) {
				// TODO 自动生成 catch 块
				e1.printStackTrace();
			}
					  
		  }
		
	}
	public void createLabel(OrderPane pane)
	{
		   labCancel=new JLabel("排行");
		   labCancel.setBounds(100,34,90,15);
		   labCancel.setForeground(Color.GREEN);
		   labCancel.setBackground(Color.WHITE);
		   labCancel.setFont(new Font(null,Font.BOLD,12));
		   pane.add(labCancel);
		   
		   labName=new JLabel("昵称");
		   labName.setBounds(200,34,90,15);
		   labName.setForeground(Color.GREEN);
		   labName.setBackground(Color.WHITE);
		   labName.setFont(new Font(null,Font.BOLD,12));
		   pane.add(labName);
		   
		   labScore=new JLabel("积分");
		   labScore.setBounds(300,34,90,15);
		   labScore.setForeground(Color.GREEN);
		   labScore.setBackground(Color.WHITE);
		   labScore.setFont(new Font(null,Font.BOLD,12));
		   pane.add(labScore);
		  
		   labNameValue=new JLabel[10];
		   labNameValue[0]=new JLabel("1");   
		   labNameValue[0].setBounds(200,50,100,20);
		   labNameValue[0].setForeground(Color.GREEN);
		   labNameValue[0].setBackground(Color.WHITE);
		   labNameValue[0].setFont(new Font(null,Font.BOLD,12));
		   pane.add(labNameValue[0]);
		   
		   for(int i=1;i<10;i++)									//新建用于存放排行榜姓名的标签数组
		  {	  
			   int yy=labNameValue[i-1].getY()+20;
			   
			   labNameValue[i]=new JLabel(i+1+"");   
			   labNameValue[i].setBounds(200,yy,100,20);
			   labNameValue[i].setForeground(Color.GREEN);
			   labNameValue[i].setBackground(Color.WHITE);
			   labNameValue[i].setFont(new Font(null,Font.BOLD,12));
			   pane.add(labNameValue[i]);
			  			   
		   }
		   
		   labScoreValue=new JLabel[10];							//新建用于存放排行榜积分的标签数组
		   labScoreValue[0]=new JLabel("1");   
		   labScoreValue[0].setBounds(300,50,100,20);
		   labScoreValue[0].setForeground(Color.GREEN);
		   labScoreValue[0].setBackground(Color.WHITE);
		   labScoreValue[0].setFont(new Font(null,Font.BOLD,12));
		   pane.add(labScoreValue[0]);
		   
		   for(int i=1;i<10;i++)
		  {	  
			   int yy=labNameValue[i-1].getY()+20;
			   
			   labScoreValue[i]=new JLabel(i+1+"");   
			   labScoreValue[i].setBounds(300,yy,100,20);
			   labScoreValue[i].setForeground(Color.GREEN);
			   labScoreValue[i].setBackground(Color.WHITE);
			   labScoreValue[i].setFont(new Font(null,Font.BOLD,12));
			   pane.add(labScoreValue[i]);
			   
			   
		   }
		   
		   
		   JLabel [] labNum=new JLabel[10];								//显示1-10个数字的标签
		   
		   labNum[0]=new JLabel("1");   
		   labNum[0].setBounds(100,50,90,20);
		   labNum[0].setForeground(Color.GREEN);
		   labNum[0].setBackground(Color.WHITE);
		   labNum[0].setFont(new Font(null,Font.BOLD,12));
		   pane.add(labNum[0]);
		   
		   for(int i=1;i<10;i++)
		  {	  
			   int yy=labNum[i-1].getY()+20;
			   
			   labNum[i]=new JLabel(i+1+"");   
			   labNum[i].setBounds(100,yy,90,20);
			   labNum[i].setForeground(Color.GREEN);
			   labNum[i].setBackground(Color.WHITE);
			   labNum[i].setFont(new Font(null,Font.BOLD,12));
			   pane.add(labNum[i]);
			   
			   
		   }
			
		    button=new JButton("退出");
		    button.setFont(new Font("",Font.BOLD,12));
		    button.setForeground(Color.GREEN);
		    button.setBackground(Color.BLACK);
		    button.setBounds(220,267,145,20);
		    pane.add(button);
		    
		    
		   
	}
		
	public void readFile()											//读取数据文件
	{
		  properties=new Properties();	
			
		
			try {
				properties.load(new FileInputStream("database/taxis.properties"));
			} 
			catch (FileNotFoundException e1) {
				
				e1.printStackTrace();
			} 
			catch (IOException e1) {
				
				e1.printStackTrace();
			}
						
			score=OrderPane.setScore();//保存游戏的积分,由游戏窗体传过来的参数
									
			properties.setProperty(score+"",enterPanel.getTxtName());
			
			try {
		        properties.store(new FileOutputStream("database//taxis.properties"), null);
		    } catch (IOException e) {
		    }
			
			enumeration=properties.propertyNames();			         	// 返回属性列表中所有键的枚举
			
			SortedMap sort=new TreeMap(Collections.reverseOrder());	 	//反序排列
			
			
			name = new String[10];										//实例化两个数组
			scoreCount = new String[10];
			for(int i=0;i<10;i++)
			{
				name[i]=new String("暂无");
				scoreCount[i]=new String("暂无");
			}
			
			int i=0;Integer aScore;String aname;Integer scoreInt = null;String nameStr;
			
			while(enumeration.hasMoreElements())			       		//如果还有元素返回true;
			{
			
				 scoreInt=new Integer(Integer.parseInt(enumeration.nextElement().toString()));	//得到属性与文件键相对应的值
				 nameStr=properties.getProperty(scoreInt+"");
				 sort.put(scoreInt,nameStr);
				
				 									
			}
			
			Iterator it = sort.keySet().iterator();
		    while (it.hasNext()&&i<=10) {
		        Object key = it.next();
		        aScore=(Integer) key;
		        aname =(String) sort.get(aScore);
			    //System.out.println(aname);
		        
				switch(i)												
				{
					
					
					case 0:											//用于保存取出的键值对
						{scoreCount[i]=aScore.toString();name[i]=aname;}
						break;
					case 1:
						{scoreCount[i]=aScore.toString();name[i]=aname;}
						break;
					case 2:
						{scoreCount[i]=aScore.toString();name[i]=aname;}
						break;
					case 3:
					{scoreCount[i]=aScore.toString();name[i]=aname;}
						break;
					case 4:
						{scoreCount[i]=aScore.toString();name[i]=aname;}
						break;
					case 5:
						{scoreCount[i]=aScore.toString();name[i]=aname;}
						break;
					case 6:
						{scoreCount[i]=aScore.toString();name[i]=aname;}
						break;
					case 7:
						{scoreCount[i]=aScore.toString();name[i]=aname;}
						break;
					case 8:
						{scoreCount[i]=aScore.toString();name[i]=aname;}
						break;
					case 9:
						{scoreCount[i]=aScore.toString();name[i]=aname;}
						break;
					
				}
				i++;
		    }

			
		
	}
	
 
	public void setLabValue()
	{
		for(int i=0;i<10;i++)									//设置排行榜标签上的值
		{
			
			labNameValue[i].setText(name[i]);//System.out.println(scoreCount[i]);
			labScoreValue[i].setText(scoreCount[i]);
		}
	}
	public static Integer setScore()
	{
		return new Integer(Gameboy.goal);	
	}
	
}
class OrderPanel extends JPanel{								//排行榜面板
	
	private Image order;
	
	public OrderPanel()
	{
		try
		{
			order=ImageIO.read(new File("image\\order1.BMP"));
		}
		catch(IOException exception)
		{
			exception.printStackTrace();
		}
	}
	public void paintComponent(Graphics g)
	{
		super.paintComponent(g);
		
		g.drawImage(order,0,0,null);	 
	}



}

⌨️ 快捷键说明

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