0

上部に 30px の JPanel を使用して JFrame を作成し、その下に Minecraft アプレットを追加しようとしています。どちらも自動的にサイズ変更する必要があります。GridBagLayout でこれを達成しようとしています。

public void start(Applet mcApplet, String user, String session) throws MalformedURLException {
    JLabel label = new JLabel();
    Thread animation = new Thread();
    Dimension size = new Dimension(900, 540);

            JPanel basic = new JPanel(new GridBagLayout());
            basic.setPreferredSize(size);
            GridBagConstraints c = new GridBagConstraints();

            // ADD MINEBOOK MENU
            JLabel menu = new JLabel(new ImageIcon(new URL("http://modpacks.minebook.co.uk/images/menu.png")));

    if(!animationname.equalsIgnoreCase("empty")) {
        try {
            animation.start();
            label = new JLabel(new ImageIcon(animationname));
            label.setBounds(0, 0, size.width, size.height);
            fixSize(size);
            getContentPane().setBackground(Color.black);
            add(label);
            animation.sleep(3000);
            animation.stop();
        } catch (Exception e) {
            label.add(label);
        } finally {
            remove(label);
        }
    }

    try {
                appletWrap = new Launcher(mcApplet, new URL("http://www.minecraft.net/game"));
    } catch (MalformedURLException ignored) { }
    appletWrap.setParameter("username", user);
    appletWrap.setParameter("sessionid", session);
    appletWrap.setParameter("stand-alone", "true");
    mcApplet.setStub(appletWrap);
            mcApplet.setPreferredSize(size);

            c.fill = GridBagConstraints.HORIZONTAL;
            c.gridx = 0;
            c.gridy = 0;
            c.ipady = 30;
            basic.add(menu, c);

            c.fill = GridBagConstraints.BOTH;
            c.gridx = 0;
            c.gridy = 1;
            c.ipady = 0;
            basic.add(appletWrap, c);

            add(basic);

            pack();
    validate();
    appletWrap.init();
    appletWrap.start();
    fixSize(size);
    setVisible(true);
}
4

1 に答える 1

1

を使用しBorderLayout、30px パネルをそのNORTH位置に配置し、Minecraft アプレットをそのCENTER位置に配置することをお勧めします。

于 2013-05-12T08:59:40.087 に答える