日期:2014-05-20 浏览次数:20767 次
import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.Dimension;
import java.awt.Graphics;
import java.awt.Rectangle;
import java.util.Vector;
import javax.swing.GroupLayout;
import javax.swing.JComboBox;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JList;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
import javax.swing.JTextArea;
import javax.swing.JTextField;
import javax.swing.SwingConstants;
public class GameFrame extends JFrame {
public final int GAMEWIDTH = 800;
public final int GAMEHEIGHT = 800;
public GameFrame() {
this.init();
this.setBounds(new Rectangle(GAMEWIDTH, GAMEHEIGHT));
this.setTitle("围棋天地");
this.setDefaultCloseOperation(EXIT_ON_CLOSE);
this.pack();
this.setVisible(true);
}
public void init() {
// 创建各个组件
PlayerPane player1 = new PlayerPane(new Player());
PlayerPane player2 = new PlayerPane(new Player());
Chatroom chat = new Chatroom();
QiPang qipang = new QiPang();
// 布置各个组件
GroupLayout layout = new GroupLayout(this.getContentPane());
this.setLayout(layout);
layout.setAutoCreateGaps(true);
layout.setAutoCreateContainerGaps(true);
// 水平布置
GroupLayout.SequentialGroup sga = layout.createSequentialGroup()
.addComponent(player1)
.addComponent(player2);
GroupLayout.ParallelGroup hp1 = layout.createParallelGroup(GroupLayout.Alignment.LEADING)
.addGroup(sga)
.addComponent(chat);
GroupLayout.SequentialGroup hGroup = layout.createSequentialGroup()
.addComponent(qipang)
.addGroup(hp1);
layout.setHorizontalGroup(hGroup);
// 垂直布置
GroupLayout.ParallelGroup vpa = layout.createParallelGroup()
.addComponent(player1)
.addComponent(player2);
GroupLayout.SequentialGroup sgb = layout.createSequentialGroup()
.addGroup(vpa)
.addComponent(chat);
GroupLayout.ParallelGroup vp1 = layout.createParallelGroup(GroupLayout.Alignment.LEADING)
.addComponent(qipang)
.addGap(5)
.addGroup(sgb);
layout.setVerticalGroup(vp1);
}
public class QiPang extends JPanel {
public static final int SPACE = 26;
public static final int QIPANGSPACE = 20;
public static final int QIPANGWIDTH = SPACE * 18 + QIPANGSPACE * 2;
public static final int QIPANGHEIGHT = SPACE * 18 + QIPANGSPACE * 2;
public static final int MOUSESPACE = 10;
public static final int POINTCOUNT = 19 * 19;
public QiPang() {
super();
this.setBounds(new Rectangle(QIPANGWIDTH, QIPANGHEIGHT));