如何使用contentpane()将内容添加到已经存在的JFrame中?

因此,最后一个错误是一个错字,但是如果您查看下面的代码,您会发现我设置了一个内容窗格,但是如何添加它,更不用说添加JButton了,因为我需要JButton(s) 我的项目。 提前致谢! :D

import java.awt.*;
import javax.swing.*;
import java.net.*;
import java.io.*;

class FPS {
    static double FPS = 0;
    public static void handle() {
        FPS = 60;
    }
    public static void crunch() {
        FPS = FPS / 2.38482984839483829384928392;
    }
}
class Clock {
    static int ticks = 0;
    public static int tick(int args) {
        ticks += args;
        return ticks;
    }
}

class Assets {
    public static String RP = "";
    public static String getResourcepack(int ID) {
        if(ID == 0) {
            RP = "default";
        }
        else {
            RP = "custom";
        }
        return RP;
    }
}
public class Frame {
    public static String resource = Assets.getResourcepack(0); 
    public static int Loop = 1;
    public static void main(String[] args) {
        while(Loop == 1) {
            try {
                double VersionNumber = 0.01;
                Dimension size = new Dimension(800,600);
                String widget1 = "resourcepacks\\"+resource+"\\assets\\textures\\widgets\\button.png";
                String titleBG = "resourcepacks\\"+resource+"\\assets\\textures\\title\\sky.png";
                String Sun = "resourcepacks\\"+resource+"\\assets\\textures\\misc\\sun1.png";
                JFrame Window = new JFrame();
                Clock time = new Clock();
                FPS Frames = new FPS();
                int TOD;
                int IT = time.tick(1);
                Window.setPreferredSize(size);
                Window.setMinimumSize(size);
                Window.setResizable(false);
                Window.setContentPane(new JLabel(new ImageIcon(titleBG)));
                Window.pack();
                Window.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
                Window.setTitle("Game");
                Window.setLocationRelativeTo(null);
                Window.setVisible(true);
                while(IT >= 0) {
                    System.out.println(IT);
                    IT = time.tick(1);
                    while(IT > 0) {
                        TOD = IT / 2400000;
                    }
                }
            } catch(Exception e) {
                Dimension size = new Dimension(800,600);
                JFrame Window = new JFrame();
                Window.setTitle("Game");
                Window.setPreferredSize(size);
                Window.setResizable(false);
                Window.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
                Window.setLocationRelativeTo(null);
                Window.setContentPane(new JLabel("Sorry, an error occurred"));
                e.printStackTrace();
                Window.pack();
                Window.setVisible(true);
            }
        }
    }
}

有人可以帮忙吗?...真的很麻烦...

from: https://dev.to//calin92540842/how-do-i-add-content-to-an-already-existing-jframe-with-contentpane-5cog

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值