📄 mainfrm.java
字号:
package com.catking.GUI;
import org.eclipse.swt.*;
import org.eclipse.swt.graphics.*;
import org.eclipse.swt.widgets.*;
import com.catking.GUI.chatBar.ChatBar;
import com.catking.GUI.chessBoard.ChessBoard;
import com.catking.GUI.chessBookBoard.ChessBookBoard;
import com.catking.GUI.leftToolBar.LeftToolBar;
import com.catking.GUI.tipBoard.TipBoard;
import com.catking.Manager.*;
import com.catking.chess.*;
import com.catking.GUI.*;
public class MainFrm {
private Shell shell;
public MainFrm(){
final Display display = new Display();
shell = new Shell(display, SWT.NO_TRIM | SWT.NO_BACKGROUND);
ResourceManager.loadResource();
createComponents();
//初始化棋盘数据 红棋在下方
ChessPane.init(true);
ChessPane.canvas = GUIObjects.chessBoard;
ChessPane.paint();
//开始游戏咯
BoardStateManager.startGame();
//计时开始
//GUIObjects.playerDown.startPuttingChess();
while(! shell.isDisposed()) {
if(! display.readAndDispatch()) {
display.sleep();
}
}
ResourceManager.releaseResource();
display.dispose();
}
private void createComponents(){
shell.setSize(600, 600);
shell.setText("猫猫象棋1.0版");
shell.setImage(ResourceManager.headImage);
buildGUI();
//创建菜单栏
MenuManager.makeMenuBar(shell);
//美化界面
BeautyManager.beautify(shell);
///////////////
//主窗口居中显示
shell.pack();
stayCenter();
shell.open();
///////////////////////////
}
//主窗口添加内容
private void buildGUI(){
GUIObjects.toolBar = new LeftToolBar(shell, SWT.NO);
GUIObjects.chessBoard = new ChessBoard(shell, SWT.None);
GUIObjects.bookBoard = new ChessBookBoard(shell, SWT.NO);
GUIObjects.tipBoard = new TipBoard(shell, SWT.NO);
GUIObjects.chatBar = new ChatBar(shell, SWT.NO);
GUIObjects.toolBar.setLocation(0, 0);
GUIObjects.chessBoard.setLocation(64, 0);
GUIObjects.bookBoard.setLocation(664, 0);
GUIObjects.tipBoard.setLocation(664, 350);
GUIObjects.chatBar.setLocation(664, 680);
}
//主窗口居中显示
private void stayCenter(){
Monitor primary = shell.getMonitor();
Rectangle bounds = primary.getBounds ();
Rectangle rect = shell.getBounds ();
int x = bounds.x + (bounds.width - rect.width) / 2;
int y = bounds.y + (bounds.height - rect.height) / 2;
if (x < 0)
x = 0;
if (y < 0)
y = 0;
shell.setLocation (x, y);
}
public static void main(String[] args) {
//红棋在下面
new MainFrm();
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -