Reputation: 79
I'm following a tutorial and made a JFrame, but it's very tiny. Iv'e searched for this problem on this site, but nothing has helped. Does anybody know the problem? I did it exactly like the tutorial, and it worked for him! I'll post a picture of it also.
Here is the code:
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() {
}
}
Upvotes: 1
Views: 3888
Reputation: 5612
You're calling frame.pack()
with no sized components in your JFrame
. This is going to squish the whole thing down to the tiny window you currently have.
Look at the docs for pack()
:
http://docs.oracle.com/javase/7/docs/api/java/awt/Window.html#pack()
Basically, you need to call setSize()
in your Core
class (which is an applet).
Upvotes: 2
Reputation: 649
Get rid of the line with frame.pack().
This packs the frame in as small as possible while still fitting everything inside it. You have nothing inside it yet (since core is nothing).
Upvotes: 3