Frame trollt mich

Also ich hab angefangen ein Fester in einer anderen Klasse über eine Methode aufzubauen.
Soweit so gut, aber egal welche WIDTH ich einstelle das Fenster wird nie breiter als 4cm, es wird
stat dessen länger o.O WTF

  • Ich hab den Code in einem Tutorial mitgeschrieben und bei dem passt alles. Tell me how … PLS

import java.awt.Canvas;

public class Game extends Canvas implements Runnable{
	
	private static final long serialVersionUID = -1009013565482847585L;
	
	public static final int WIDHT = 640, HEIGHT = 640;
	
	public Game(){
		new Window(WIDTH, HEIGHT, "Game", this);
		
	}

	public synchronized void start(){
		
	}
	
	public void run(){
		
	}

	public static void main(String[] args) {
		
		new Game();
	}

}

import java.awt.Canvas;
import java.awt.Dimension;

import javax.swing.JFrame;

public class Window extends Canvas{

	private static final long serialVersionUID = -2681461688794138902L;
	
	public Window(int width, int height, String title, Game game){
		JFrame frame = new JFrame(title);
		frame.setPreferredSize(new Dimension(width, height));
		frame.setMaximumSize(new Dimension(width, height));
		frame.setMinimumSize(new Dimension(width, height));
		
		frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
		frame.setResizable(false);
		frame.setLocationRelativeTo(null);
		frame.add(game);
		frame.setVisible(true);
		game.start();
	}
	
}

spaßiger Fehler, Canvas definiert

     * This flag in the infoflags argument to imageUpdate indicates that 
     * the width of the base image is now available and can be taken
     * from the width argument to the imageUpdate callback method.
     * @see Image#getWidth
     * @see #imageUpdate
     */
    public static final int WIDTH = 1;

du definierst NICHT eine Konstante WIDTH

ein setSize()-Aufruf sollte beim JFrame dann auch reichen, die anderen drei bewirken potentiell nichts (bei mir),

wenn du Window nicht als Canvas nutzt, dann besser auch nicht dort erben

Das setSize hab ich nur drinnen weils eben nicht funktioniert hat…

Und einer eigenen Klasse den selben Namen wie eine AWT-Klasse zu geben ist, ehm… ungeschickt…

bye
TT