java - JFrame 很小

标签 java swing jframe size

我按照教程制作了一个 JFrame,但它非常小。我在这个网站上搜索过这个问题,但没有任何帮助。有人知道这个问题吗?我完全按照教程做的,对他很有用!我也会张贴它的照片。

代码如下:

    package net.trails.std;
import java.applet.Applet;
import java.awt.Dimension;
import java.awt.Image;

import javax.swing.JFrame;

public class Core extends Applet implements Runnable {

    private static final long serialVersionUID = 1L;
    private static JFrame frame;

    public static double dY = 0, dX = 0;
    public static final int res = 1;
    public static int dir = 0;

    public static boolean moving = false;
    public static boolean run = false;

    private Image screen;

    public static Dimension screenSize = new Dimension(700, 560);
    public static Dimension pixel = new Dimension(screenSize.width, screenSize.height);
    public static Dimension size;

    public static String name = "Trails";

    public Core(){



    }

    public static void main(String[] args) {

        Core core = new Core();
        frame = new JFrame();
        frame.add(core);
        size = new Dimension(frame.getWidth(), frame.getHeight());
        frame.setSize(700, 560);
        frame.setTitle(name);
        frame.setResizable(false);
        frame.setLocationRelativeTo(null);
        frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        frame.pack();
        frame.setVisible(true);
        core.start();

    }


    public void run() {



    }

}

enter image description here

最佳答案

摆脱 frame.pack() 的行。

这样可以将框架包装得尽可能小,同时仍能容纳其中的所有东西。你里面什么都没有(因为核心什么都不是)。

关于java - JFrame 很小,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19694515/

相关文章:

java - 制作基于文本的 RPG 时遇到麻烦(与文本区域/字段相关)

java - 使用 JFormattedTextField(NumberFormat.getIntegerInstance()) 时出错;

java - 窗口不弹出

java - Spring:使用 REST 服务发布新对象时出现类型定义错误

java - Hadoop 与 MongoDB 概念

java - 聚合或组合

java - 单击jFileChooser中的打开按钮后如何打开文件?

Java串行通信-IllegalStateException-端口已关闭

java - JFrame如何自行刷新?

java - 覆盖 JFrame 的最小化