Commit 46c8c880 authored by 刘家荣's avatar 刘家荣 💬
Browse files

开始界面改了一丢丢,整理框架

parent 47d24f49
Loading
Loading
Loading
Loading
+1 −1
Original line number Diff line number Diff line
@@ -34,7 +34,7 @@
      <property name="JTree.lineStyle" class="java.lang.String" />
    </properties>
  </component>
  <component name="ProjectRootManager" version="2" languageLevel="JDK_17" project-jdk-name="corretto-17" project-jdk-type="JavaSDK">
  <component name="ProjectRootManager" version="2" languageLevel="JDK_17" project-jdk-name="17" project-jdk-type="JavaSDK">
    <output url="file://$PROJECT_DIR$/out" />
  </component>
</project>
 No newline at end of file
+5 −8
Original line number Diff line number Diff line
import view.SwingUtil;
import view.MySwingUtils;

import java.net.URL;
import java.awt.Point;
import java.awt.Image;
import java.awt.Graphics;
import java.awt.Dimension;
import javax.swing.ImageIcon;

import javax.swing.JLabel;
@@ -17,12 +14,12 @@ import javax.swing.WindowConstants;
import javax.swing.border.LineBorder;
import java.net.MalformedURLException;

/**Title: Demo.java
/**Title: ScalingTest.java
 * 示例代码
 * 
 * @author Run
 * @date  2019-08-20 */
public class Demo{
public class ScalingTest {

    public static void main(String args[]){
        SwingUtilities.invokeLater( () ->{
@@ -48,13 +45,13 @@ public class Demo{
        }
        //等比例JLabel
        JLabel ratioLabel = new JLabel();
        ratioLabel.setIcon(SwingUtil.createAutoAdjustIcon(image, true));
        ratioLabel.setIcon(MySwingUtils.createAutoAdjustIcon(image, true));
        ratioLabel.setBorder(new LineBorder(Color.RED));
        ratioLabel.setAlignmentX(0.5F);
        ratioLabel.setAlignmentY(0.5F);
        //不等比例JLabel
        JLabel filledLabel = new JLabel();
        filledLabel.setIcon(SwingUtil.createAutoAdjustIcon(image, false));
        filledLabel.setIcon(MySwingUtils.createAutoAdjustIcon(image, false));
        filledLabel.setBorder(new LineBorder(Color.ORANGE));
        //常规样式JLabel
        JLabel normalLabel = new JLabel();
+3 −3
Original line number Diff line number Diff line
package view.start;
import view.StartForm;

import javax.swing.*;

public class Main2 {
public class Test {
    public static void main(String[] args) {
        JFrame frame = new JFrame("StartForm");
        frame.setContentPane(new StartForm().RootPanel);
        frame.setContentPane(new StartForm().rootPanel);
        frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        frame.pack();
        frame.setVisible(true);
+14 −16
Original line number Diff line number Diff line
@@ -6,8 +6,9 @@ import com.alibaba.fastjson2.JSONObject;
import model.History;
import model.game.Game;
import view.AppFrame;
import view.ChessGameFrame;
import view.GameStartFrame;
import view.GameForm;
import view.RoomsForm;
import view.StartForm;

import javax.swing.*;
import java.io.IOException;
@@ -58,6 +59,7 @@ public class AppController {
     * @param useSave 如果是进入游戏,那么是否调用存档
     */
    public void switchStatus(AppStatus status1, boolean useSave) {
        boolean success = true; //切换过程没有遇到任何问题阻止,哪里有问题就把它改成false
        switch (this.status) {
            case START:
                switch (status1) {
@@ -73,12 +75,6 @@ public class AppController {
                            Game.instance = new Game(true);
                            History.instance = new History(Game.instance.clone());
                        }
                        this.status = AppStatus.GAME;
                        SwingUtilities.invokeLater(() -> {
                            GameStartFrame.instance.setVisible(false);
                            ChessGameFrame.instance = new ChessGameFrame(620, 895);
                            ChessGameFrame.instance.setVisible(true);
                        });
                        break;
                }
                break;
@@ -99,12 +95,6 @@ public class AppController {
                            savedGame = null;
                            savedHistory = null;
                        }
                        this.status = AppStatus.START;
                        SwingUtilities.invokeLater(() -> {
                            ChessGameFrame.instance.setVisible(false);
                            GameStartFrame.instance = new GameStartFrame();
                            GameStartFrame.instance.setVisible(true);
                        });
                        break;
                    case ROOM:
                        break;
@@ -113,6 +103,14 @@ public class AppController {
                }
                break;
        }
        AppFrame.instance.setContentPane(switch (status1){
            case START -> new StartForm().rootPanel;
            case ROOM -> new RoomsForm().rootPanel;
            case GAME -> new GameForm().rootPanel;
        });
        if (success) {
            this.status = status1;
        }
    }
    public void switchStatus(AppStatus status1) {
        this.switchStatus(status1, false);
+1 −2
Original line number Diff line number Diff line
package view;
import controller.AppController;
import controller.AppStatus;
import view.start.StartForm;

import javax.swing.*;
import java.awt.*;
@@ -12,7 +11,7 @@ public class AppFrame extends JFrame {

    public AppFrame() {
        this.setLocation(400,0);
        this.setContentPane(new StartForm().RootPanel);
        this.setContentPane(new StartForm().rootPanel);
        this.setDefaultCloseOperation(EXIT_ON_CLOSE);
        this.pack();
        this.setVisible(true);
Loading