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

📄 frmtaxis.java

📁 小游戏--淘金者 主要用到了双缓冲平面作图
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
package bin;

import javax.imageio.ImageIO;
import javax.swing.BorderFactory;
import javax.swing.JButton;
import javax.swing.JDialog;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JTextField;
import javax.swing.Timer;
import javax.swing.border.BevelBorder;
import javax.swing.border.Border;
import java.awt.Color;
import java.awt.Container;
import java.awt.Dimension;
import java.awt.Font;
import java.awt.Graphics;
import java.awt.Image;
import java.awt.Toolkit;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
import java.awt.event.MouseMotionAdapter;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.util.Collections;
import java.util.Enumeration;
import java.util.Iterator;
import java.util.Properties;
import java.util.SortedMap;
import java.util.TreeMap;

class TaxisFrame extends JFrame {

	
	public static final int DEFAULT_WIDTH=800;
	public static final int DEFAULT_HEIGHT=600;
	
	public TaxisFrame(){
		
		setTitle("排行榜");
		setSize(DEFAULT_WIDTH,DEFAULT_HEIGHT);				  
		
		Toolkit kit = Toolkit.getDefaultToolkit();
		Dimension screenSize = kit.getScreenSize();
		int screenHeight = screenSize.height;
		int screenWidth = screenSize.width;
		setLocation((screenWidth-DEFAULT_WIDTH ) /2, (screenHeight -DEFAULT_HEIGHT)/ 2);
		this.setUndecorated(true); 
		
		
		
		Container contentPane=this.getContentPane();
		contentPane.setBackground(Color.BLACK);
		contentPane.setLayout(null);
	
		MainPanel panel=new MainPanel(this);
		panel.setBounds(0,0,this.getWidth(),this.getHeight());
		
		
		contentPane.add(panel);
	
		
		new FrameMove().install(this);
	}
	
		public static void start() {
	
		   TaxisFrame frame=new TaxisFrame();
		   frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
		   frame.setVisible(true);
		   Play.taxisOpen();
		   
	}
}

class MainPanel extends JPanel{										//底层主面板
	
   	private int x1;
  	private int y1;
  	private int y;
  	private int frmHeight;
  	private int frmWidth;
  	private JLabel labxy;
  	private Image image1;
	public MainPanel(TaxisFrame frmTaxis)
	{	
		  
		  this.setBackground(Color.BLACK);
		  this.setLayout(null);
		  
		  EnterPanel taxis=new EnterPanel(frmTaxis);
		  taxis.setBounds(550,100,200,100);
		  this.add(taxis);
		     
		  labxy=new JLabel();											//显示鼠标移动的标签
		  labxy.setForeground(Color.GREEN);
		  this.add(labxy);
		  
		  y=0;
		  frmHeight=frmTaxis.getHeight();
		  frmWidth=frmTaxis.getWidth();
		  
		  try
			{
				 image1 = ImageIO.read(new File("image\\1.jpg"));
			}
			catch(IOException exception)
			{
				exception.printStackTrace();
			}
			
		  this.addMouseMotionListener(new 
	    		  MouseMotionAdapter(){
					
					public void mouseMoved(MouseEvent e) {
						
						x1=e.getX();							
						y1=e.getY();
						
						labxy.setBounds(x1+30,y1,100,25);
						labxy.setText(x1+","+y1);
						
						repaint();
					}
					
		  });
  

}
	
	
	public void paintComponent(Graphics g)
	{
		super.paintComponent(g);
				
			g.drawImage(image1,0,0,null);
			
			g.setColor(Color.GREEN);									//鼠标移动线条的绘制
			g.drawLine(x1,y,x1,frmHeight);
			g.drawLine(0,y1,frmWidth,y1);
		
	}
	
		
}


class EnterPanel extends JPanel{	
																		//输入玩家姓名面板
	private JLabel labName;
	private JTextField txtName;
	private JLabel labOK;
	private boolean Visibleable;
	private String txtNameValue;
	private TaxisFrame frmTaxis;
	public EnterPanel(final TaxisFrame frmTaxis)
	{	
		  this.frmTaxis=frmTaxis;
		  this.setSize(200,100);
		  this.setBackground(Color.BLACK);
		  		  
		  Border etched = BorderFactory.createEtchedBorder(BevelBorder.LOWERED,Color.black,Color.RED);
	      //Border titled = BorderFactory.createTitledBorder(etched, "Border types");
	      this.setBorder(etched);
	      this.setLayout(null);
	      
	      labName=new JLabel("请输入昵称:");
	      txtName=new JTextField();
	      labOK=new JLabel("OK");
	      
	      
	      labName.setBounds(10,25,100,20);
	      labName.setForeground(Color.GREEN);
	      txtName.setBounds(60,55,100,20);
	      txtName.setForeground(Color.GREEN);
	      txtName.setFont(new Font(null,Font.BOLD,15)) ;
	      
	      
	      labOK.setBounds(165,44,50,50);
	      labOK.setFont(new Font(null,Font.BOLD,15)) ;
	      labOK.setForeground(Color.GREEN);
	      labOK.setToolTipText("单击确认");
	     
	      
	      this.add(labName);
	      this.add(txtName);
	      this.add(labOK);
	      
	      this.setVisible(true);
		  Visibleable=true;
		  
		  this.createTimer();
	     labOK.addMouseListener(new MouseAdapter()
	    		 {

					public void mouseClicked(MouseEvent e) {
						validateTxtName();
						
						
					}
				
					public void mouseEntered(MouseEvent e) {
						 labOK.setFont(new Font(null,Font.BOLD,25)) ;
						
					}

					public void mouseExited(MouseEvent e) {
						
						 labOK.setFont(new Font(null,Font.BOLD,15)) ;
						
					}
	    	 
	    	 
	    		 });
	}
	public void validateTxtName()
	{
		txtNameValue=txtName.getText();
		if(txtNameValue.equals(""))
		{
			//System.out.println(1);
			//	如果是空不做任何处理.
		}
		else 
		{
			Play.taxisOk();															//创建可移动的用户信息窗格,与排行榜信息窗格
			PlayerPane player=new PlayerPane(frmTaxis,this);	
			player.setVisible(true);
			
		    OrderPane order=new OrderPane(frmTaxis,this);	
		    order.setVisible(true);	
		   	   
		}

		
	}
	public String getTxtName()										//返回用户输入的昵称
	{
		return txtNameValue;
	}
	public void createTimer()
	{
		 ActionListener listener = new TimePrinter(EnterPanel.this);
	     Timer t = new Timer(200, listener);
	     t.start();
	     															//t没有处理;
	      
	}

	
	public void paintComponent(Graphics g)
	{
		super.paintComponent(g);
		
	}
	
	public void setVisibleable(boolean bool)
	{
		 Visibleable=bool;
	}
	public boolean getVisibleable()
	{
		return Visibleable;
	}


}
class TimePrinter implements ActionListener						//控制输入面板闪烁的事件
{  
	private EnterPanel aEnterPanel;
	public static int count=0;
	public boolean flag=false;
	
	public TimePrinter(EnterPanel pane)
	{
		aEnterPanel=pane;
	}
   public void actionPerformed(ActionEvent event)
   {
	  
	   if (aEnterPanel.getVisibleable()&& flag==false)				//判断面板是否可以显示
	   {
		   aEnterPanel.setVisible(false);
		   aEnterPanel.setVisibleable(false);
	   }
	   else 
	   {
		   aEnterPanel.setVisible(true);
		   aEnterPanel.setVisibleable(true);
	   }
	   
	   count++;
	   if(count ==10)
	   {
		   flag=true;
	   }
   }
   
  

}
//用来保存PlayerPanel面板的对话框,实现玩家信息框的移动
class PlayerPane extends JDialog implements Runnable
{  
	
	private JLabel labName;
	private JLabel labPass;
	private JLabel labPerish;
	private JLabel labLift;
	private JLabel labScore;
	private String name;											//记录用户昵称
	private String pass;											//记录关数
	private String perish;											//记录消灭蝙蝠数
	private String lift;											//记录生命数
	private String score;											//记录积分
	private EnterPanel enterPanel;
	private Thread t;
	private int x;													//要设置的x,y
	private int y;
	private int fy;												//主窗体的x,y
	private int fx;
	private JLabel labMessage;

	public PlayerPane(TaxisFrame frmTaxis, EnterPanel enterPanel)
	{  
		
	   super(frmTaxis, "", false); 
	   setSize(380,110);
	   this.setUndecorated(true);
		
		this.enterPanel=enterPanel;
		
		this.getContentPane().setBackground(Color.RED);
		this.setLayout(null);
		
		this.setLocation(x,y);
		t=new Thread(this);
		
		fx=frmTaxis.getX ();
		fy=frmTaxis.getY();
		x=(fx-this.getWidth());
		y=(fy+frmTaxis.getHeight()-this.getHeight());
		
		
		t.start();
		
		pass=StatePanel.getPassValue()+"";				//记录关数
		perish=StatePanel.getOgreValue()+"";			//记录消灭蝙蝠数
		lift=StatePanel.getGameBOyValue()+"";			//记录生命数
		score=StatePanel.getScoreValue()+"";			//记录积分
		
		this.createMessage();
		
		   
		PlayerPanel panel = new PlayerPanel();
		panel.setBounds(0,0,380,110);
		add(panel);
	}
	public void run(){
		
		for(int i=x;i<=fx;i=i+10)
		  {
			  this.setLocation(i,y);
			  
			  try {
					t.sleep(0);
							
					} catch (InterruptedException e1) {
					// TODO 自动生成 catch 块
					e1.printStackTrace();
				}
					  
		  }
		
	}
public void createMessage()
{
	   
	   labMessage=new JLabel("玩家信息");
	   labMessage.setBounds(25,13,100,25);
	   labMessage.setForeground(Color.GREEN);
	   labMessage.setFont(new Font(null,Font.BOLD,12));
	   add(labMessage);
	   
	   name=enterPanel.getTxtName();									//得到玩家昵称
	   labName=new JLabel("昵称:"+" "+name);
	   labName.setBounds(25,43,100,25);
	   labName.setForeground(Color.GREEN);
	   labName.setFont(new Font(null,Font.BOLD,12));
	   add(labName);
	   
	   
	   labPass=new JLabel("关数:"+" "+pass);

⌨️ 快捷键说明

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