📄 initplayerframe.java
字号:
package com.xmu.typot.ui;import java.awt.BorderLayout;import java.awt.GridBagConstraints;import java.awt.GridBagLayout;import java.awt.GridLayout;import java.awt.Insets;import java.awt.event.ActionEvent;import java.awt.event.ActionListener;import java.util.ArrayList;import javax.swing.BorderFactory;import javax.swing.ImageIcon;import javax.swing.JButton;import javax.swing.JLabel;import javax.swing.JOptionPane;import javax.swing.JPanel;import javax.swing.WindowConstants;import javax.swing.border.LineBorder;import com.xmu.typot.domain.MonopolyGame;/*** This code was edited or generated using CloudGarden's Jigloo* SWT/Swing GUI Builder, which is free for non-commercial* use. If Jigloo is being used commercially (ie, by a corporation,* company or business for any purpose whatever) then you* should purchase a license for each developer using Jigloo.* Please visit www.cloudgarden.com for details.* Use of Jigloo implies acceptance of these licensing terms.* A COMMERCIAL LICENSE HAS NOT BEEN PURCHASED FOR* THIS MACHINE, SO JIGLOO OR THIS CODE CANNOT BE USED* LEGALLY FOR ANY CORPORATE OR COMMERCIAL PURPOSE.*/public class InitPlayerFrame extends javax.swing.JFrame { { //Set Look & Feel try { javax.swing.UIManager.setLookAndFeel("com.sun.java.swing.plaf.windows.WindowsLookAndFeel"); } catch(Exception e) { e.printStackTrace(); } } private JPanel pictualPanel; private JButton button1; private JLabel label4; private JLabel label3; private JLabel label2; private JLabel label1; private JLabel showLabel; private JPanel showPanel; private JButton button10; private JButton okButton; private JPanel controlPanel; private JButton button9; private JButton button8; private JButton button7; private JButton button6; private JButton jButton1; private JButton button4; private JButton button3; private JButton button2; private ArrayList<Integer> playerIndex; private JLabel[] labels = new JLabel[4]; private int number = 0; private MonopolyGame game; /** * Auto-generated main method to display this JFrame */ public static void main(String[] args) { InitPlayerFrame inst = new InitPlayerFrame(); inst.setVisible(true); } public InitPlayerFrame() { super(); playerIndex = new ArrayList<Integer>(); initGUI(); } public InitPlayerFrame(MonopolyGame game) { super(); this.game = game; playerIndex = new ArrayList<Integer>(); initGUI(); } private void initGUI() { try { BorderLayout thisLayout = new BorderLayout(); getContentPane().setLayout(thisLayout); setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE); { pictualPanel = new JPanel(); GridBagLayout pictualPanelLayout = new GridBagLayout(); pictualPanelLayout.rowWeights = new double[] {0.1, 0.1}; pictualPanelLayout.rowHeights = new int[] {7, 7}; pictualPanelLayout.columnWeights = new double[] {0.1, 0.1, 0.1, 0.1, 0.1}; pictualPanelLayout.columnWidths = new int[] {7, 7, 20, 7, 7}; pictualPanel.setLayout(pictualPanelLayout); getContentPane().add(pictualPanel, BorderLayout.NORTH); pictualPanel.setPreferredSize(new java.awt.Dimension(342, 140)); { button1 = new JButton(); pictualPanel.add(button1, new GridBagConstraints( 0, 0, 1, 1, 0.0, 0.0, GridBagConstraints.CENTER, GridBagConstraints.NONE, new Insets(0, 0, 0, 0), 0, 0)); button1.setIcon(new ImageIcon(getClass().getClassLoader() .getResource("image/1player.gif"))); button1.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent arg0) { // TODO Auto-generated method stub add(button1,1); } }); } { button2 = new JButton(); pictualPanel.add(button2, new GridBagConstraints( 1, 0, 1, 1, 0.0, 0.0, GridBagConstraints.CENTER, GridBagConstraints.NONE, new Insets(0, 0, 0, 0), 0, 0)); button2.setIcon(new ImageIcon(getClass().getClassLoader() .getResource("image/2player.gif"))); button2.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent arg0) { // TODO Auto-generated method stub add(button2,2); } }); } { button3 = new JButton(); pictualPanel.add(button3, new GridBagConstraints( 2, 0, 1, 1, 0.0, 0.0, GridBagConstraints.CENTER, GridBagConstraints.NONE, new Insets(0, 0, 0, 0), 0, 0)); button3.setIcon(new ImageIcon(getClass().getClassLoader().getResource("image/3player.gif"))); button3.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent arg0) { // TODO Auto-generated method stub add(button3,3); } }); } { button4 = new JButton(); pictualPanel.add(button4, new GridBagConstraints( 3, 0, 1, 1, 0.0, 0.0, GridBagConstraints.CENTER, GridBagConstraints.NONE, new Insets(0, 0, 0, 0), 0, 0)); button4.setIcon(new ImageIcon(getClass().getClassLoader().getResource("image/4player.gif"))); button4.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent arg0) { // TODO Auto-generated method stub add(button4,4); } }); } { jButton1 = new JButton(); pictualPanel.add(jButton1, new GridBagConstraints( 4, 0, 1, 1, 0.0, 0.0, GridBagConstraints.CENTER, GridBagConstraints.NONE, new Insets(0, 0, 0, 0), 0, 0)); jButton1.setIcon(new ImageIcon(getClass().getClassLoader().getResource("image/5player.gif"))); jButton1.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent arg0) { // TODO Auto-generated method stub add(jButton1,5); } }); } { button6 = new JButton(); pictualPanel.add(button6, new GridBagConstraints( 0, 1, 1, 1, 0.0, 0.0, GridBagConstraints.CENTER, GridBagConstraints.NONE, new Insets(0, 0, 0, 0), 0, 0)); button6.setIcon(new ImageIcon(getClass().getClassLoader().getResource("image/6player.gif"))); button6.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent arg0) { // TODO Auto-generated method stub add(button6,6); } }); } { button7 = new JButton(); pictualPanel.add(button7, new GridBagConstraints( 1, 1, 1, 1, 0.0, 0.0, GridBagConstraints.CENTER, GridBagConstraints.NONE, new Insets(0, 0, 0, 0), 0, 0)); button7.setIcon(new ImageIcon(getClass().getClassLoader().getResource("image/7player.gif"))); button7.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent arg0) { // TODO Auto-generated method stub add(button7,7); } }); } { button8 = new JButton(); pictualPanel.add(button8, new GridBagConstraints( 2, 1, 1, 1, 0.0, 0.0, GridBagConstraints.CENTER, GridBagConstraints.NONE, new Insets(0, 0, 0, 0), 0, 0)); button8.setIcon(new ImageIcon(getClass().getClassLoader().getResource("image/8player.gif"))); button8.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent arg0) { // TODO Auto-generated method stub add(button8,8); } }); } { button9 = new JButton(); pictualPanel.add(button9, new GridBagConstraints( 3, 1, 1, 1, 0.0, 0.0, GridBagConstraints.CENTER, GridBagConstraints.NONE, new Insets(0, 0, 0, 0), 0, 0)); button9.setIcon(new ImageIcon(getClass().getClassLoader().getResource("image/9player.gif"))); button9.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent arg0) { // TODO Auto-generated method stub add(button9,9); } }); } { button10 = new JButton(); pictualPanel.add(button10, new GridBagConstraints( 4, 1, 1, 1, 0.0, 0.0, GridBagConstraints.CENTER, GridBagConstraints.NONE, new Insets(0, 0, 0, 0), 0, 0)); button10.setIcon(new ImageIcon(getClass().getClassLoader().getResource("image/10player.gif"))); button10.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent arg0) { // TODO Auto-generated method stub add(button10,10); } }); } } { controlPanel = new JPanel(); getContentPane().add(controlPanel, BorderLayout.SOUTH); controlPanel.setPreferredSize(new java.awt.Dimension(342, 32)); { okButton = new JButton(); controlPanel.add(okButton); okButton.setText("\u786e\u5b9a"); okButton.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent arg0) { // TODO Auto-generated method stub initPlayer(); } } ); } } { showPanel = new JPanel(); GridBagLayout showPanelLayout = new GridBagLayout(); showPanelLayout.rowWeights = new double[] {0.1}; showPanelLayout.rowHeights = new int[] {7}; showPanelLayout.columnWeights = new double[] {0.0, 0.0, 0.1, 0.1, 0.1}; showPanelLayout.columnWidths = new int[] {85, 7, 7, 7, 7}; showPanel.setLayout(showPanelLayout); getContentPane().add(showPanel, BorderLayout.CENTER); showPanel.setBorder(new LineBorder(new java.awt.Color(0,0,0), 1, false)); { showLabel = new JLabel(); showPanel.add(showLabel, new GridBagConstraints( 0, 0, 1, 1, 0.0, 0.0, GridBagConstraints.CENTER, GridBagConstraints.NONE, new Insets(0, 0, 0, 0), 0, 0)); showLabel .setText("\u4f60\u9009\u4e2d\u7684\u73a9\u5bb6(\u81f3\u591a4\u4e2a):"); } { label1 = new JLabel(); showPanel.add(label1, new GridBagConstraints(1, 0, 1, 1, 0.0, 0.0, GridBagConstraints.CENTER, GridBagConstraints.NONE, new Insets(0, 0, 0, 0), 0, 0));// label1.setIcon(new ImageIcon(getClass().getClassLoader()// .getResource("image/1.gif"))); labels[0] = label1; } { label2 = new JLabel(); showPanel.add(label2, new GridBagConstraints(2, 0, 1, 1, 0.0, 0.0, GridBagConstraints.CENTER, GridBagConstraints.NONE, new Insets(0, 0, 0, 0), 0, 0));// label2.setIcon(new ImageIcon(getClass().getClassLoader()// .getResource("image/1p.gif"))); labels[1] = label2; } { label3 = new JLabel(); showPanel.add(label3, new GridBagConstraints( 3, 0, 1, 1, 0.0, 0.0, GridBagConstraints.CENTER, GridBagConstraints.NONE, new Insets(0, 0, 0, 0), 0, 0));// label3.setIcon(new ImageIcon(getClass().getClassLoader()// .getResource("image/2.gif"))); labels[2] = label3; } { label4 = new JLabel(); showPanel.add(label4, new GridBagConstraints( 4, 0, 1, 1, 0.0, 0.0, GridBagConstraints.CENTER, GridBagConstraints.NONE, new Insets(0, 0, 0, 0), 0, 0));// label4.setIcon(new ImageIcon(getClass().getClassLoader()// .getResource("image/3player.gif"))); labels[3] = label4; } } pack(); this.setSize(350, 300); } catch (Exception e) { e.printStackTrace(); } } private void add(JButton button,int i) { if(number < 4) { playerIndex.add(i); button.setEnabled(false); labels[number].setIcon(new ImageIcon(getClass().getClassLoader() .getResource("image/"+i+"player.gif"))); number ++; } else { JOptionPane.showMessageDialog(null, "玩家个数超过4个,不能在添加"); return ; } } private void initPlayer() { if(playerIndex.size() < 2) { JOptionPane.showMessageDialog(null, "你至少选择2个玩家"); return ; } game.play(playerIndex); }}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -