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

📄 testframe.java

📁 自己写的monopoly 游戏代码
💻 JAVA
字号:
package com.xmu.typot.ui;import java.awt.BorderLayout;import javax.swing.BoxLayout;import javax.swing.JPanel;import javax.swing.JScrollPane;import javax.swing.JTextArea;import javax.swing.Timer;import javax.swing.WindowConstants;import javax.swing.border.LineBorder;import com.xmu.typot.domain.MonopolyGame;import com.xmu.typot.test.TestListener;import java.awt.event.ActionEvent;import java.awt.event.ActionListener;import java.awt.event.WindowAdapter;import java.awt.event.WindowEvent;import java.awt.event.WindowStateListener;import java.text.SimpleDateFormat;import java.util.Date;public class TestFrame extends javax.swing.JFrame {	private JPanel statusPanel;	private ViewPanel showPanel;	private JPanel controlPanel;	private TestDice dicePanel;	private JTextArea histroyText;	private MonopolyGame control;	private Timer timer;	private int playerRun;	{		//Set Look & Feel		try {			javax.swing.UIManager.setLookAndFeel("com.sun.java.swing.plaf.windows.WindowsLookAndFeel");		} catch(Exception e) {			e.printStackTrace();		}	}	/**	* Auto-generated main method to display this JFrame	*/		public TestFrame(MonopolyGame control) {		super();		this.control = control;		initGUI();		playerRun = 0;		this.addWindowListener(new WindowAdapter()		{			public void windowClosing(WindowEvent e)			{				System.exit(0);			}		});	}			private void initGUI() {		try {			BorderLayout thisLayout = new BorderLayout();			getContentPane().setLayout(thisLayout);			setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE);			{				statusPanel = new JPanel();				BorderLayout statusPanelLayout = new BorderLayout();				statusPanel.setLayout(statusPanelLayout);				getContentPane().add(statusPanel, BorderLayout.EAST);				statusPanel.setPreferredSize(new java.awt.Dimension(145, 500));				statusPanel.setBorder(new LineBorder(new java.awt.Color(0,0,0), 1, false));								dicePanel = new TestDice(this);				statusPanel.add(dicePanel,BorderLayout.NORTH);								histroyText = new JTextArea();//				BoxLayout histroyTextLayout = new BoxLayout(//					histroyText,//					javax.swing.BoxLayout.X_AXIS);//				histroyText.setLayout(histroyTextLayout);				statusPanel.add(new JScrollPane(histroyText),BorderLayout.CENTER);				histroyText.setEditable(false);				histroyText.setLineWrap(true);			}			{				controlPanel = new JPanel();				getContentPane().add(controlPanel, BorderLayout.SOUTH);				controlPanel.setPreferredSize(new java.awt.Dimension(750, 70));				controlPanel.setBorder(new LineBorder(new java.awt.Color(0,0,0), 1, false));			}			{				showPanel = new ViewPanel(control);				getContentPane().add(showPanel, BorderLayout.CENTER);				showPanel.setPreferredSize(new java.awt.Dimension(600, 500));				showPanel.setBorder(new LineBorder(new java.awt.Color(0,0,0), 1, false));			}			pack();			this.setSize(750, 600);		} catch (Exception e) {			e.printStackTrace();		}	}		public ViewPanel getViewPanel()	{		return (ViewPanel) showPanel;	}		public void run(int dice)	{		control.run(dice);	}		public void stop()	{		timer.stop();	}		public void playerRun(int dice)	{		RunListener listener = new RunListener(this,dice,playerRun);		timer = new Timer(300,listener);		timer.start();	}	private class RunListener implements ActionListener	{		private TestFrame panel;		private int i;		private int dice;		private int playerRun;		public RunListener(TestFrame frame,int dice,int playerRun)		{			this.panel = frame;			this.dice = dice;			i = 0;			this.playerRun = playerRun;		}				public void actionPerformed(ActionEvent arg0) {			// TODO Auto-generated method stub			control.run();	//		panel.repaint();			i ++;			if(i >= dice)			{				panel.stop();				dicePanel.run();				control.doWith();			}					}			}		public void writeHistroy(String s)	{		Date time = new Date();		SimpleDateFormat formatter = new SimpleDateFormat("hh:mm:ss");			histroyText.append(formatter.format(time)+"  "+s+"\n");	}	public void dice(int dice)	{		dicePanel.dice(dice);	}}

⌨️ 快捷键说明

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