我正在尝试在顶部制作一个 30px JPanel 的 JFrame,然后在下面添加 Minecraft Applet,两者都需要自动调整大小,我正在尝试使用 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);
}