I'm just about to start developing some Java applications so I can get too know that language a little better, for my first real project I'd like to make a application which when it's loaded up will give two different panels, the change-log (which get's retrieved from Tumblr?) and another which isn't as wide which contains either a login form or button to launch the application, once the user has launched to application it closes the launcher then opens up the JFrame for the main application such as a game.
I've had an attempt a getting my JFrame
and such working but haven't had too much success. Wwhat is the best possible way of getting this to happen?
Current Code
import java.awt.BorderLayout;
import java.awt.Canvas;
import java.awt.Dimension;
import javax.swing.BoxLayout;
import javax.swing.JFrame;
import javax.swing.JPanel;
public class Launcher extends Canvas {
private static final long serialVersionUID = 1L;
public static final int LAUNCHER_WIDTH = 350;
public static final int LAUNCHER_HEIGHT = 200;
public static final int LAUNCHER_SCALE = 3;
public static final String LAUNCHER_TITLE = "Launcher";
public static void main(String[] args) {
Launcher l = new Launcher();
JFrame f = new JFrame();
JPanel c = new JPanel();
JPanel u = new JPanel();
JPanel s = new JPanel();
l.setPreferredSize(new Dimension(LAUNCHER_WIDTH * LAUNCHER_SCALE, LAUNCHER_HEIGHT * LAUNCHER_SCALE));
l.setMinimumSize(new Dimension(LAUNCHER_WIDTH * LAUNCHER_SCALE, LAUNCHER_HEIGHT * LAUNCHER_SCALE));
l.setMaximumSize(new Dimension(LAUNCHER_WIDTH * LAUNCHER_SCALE, LAUNCHER_HEIGHT * LAUNCHER_SCALE));
c.setLayout(new BoxLayout(c, BoxLayout.X_AXIS));
c.add(u);
c.add(s);
f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
f.setLayout(new BorderLayout());
f.setTitle(LAUNCHER_TITLE);
f.add(l, BorderLayout.CENTER);
f.add(c);
f.pack();
f.setResizable(false);
f.setLocationRelativeTo(null);
f.setVisible(true);
}
}
A couple of suggestions:
Launcher()
don't extend Canvas
as that is java.awt
. JPanel
or JFrame
instead as these are swing
which will be more compatible with your other swing components
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.