Hallo,
ich habe ein Tutorial befolgt und diesen Code verfasst:
leider zeigt mir Eclipse nur eine leere Oberfläche an, obwohl sie schwarz gefärbt sein sollte und den Schriftzug "Tetris" haben sollte
kann mir jemand helfen?
LG
Schweizergeizer
ich habe ein Tutorial befolgt und diesen Code verfasst:
Java:
[SPOILER="Code"]package Tetirs;
import java.awt.Canvas;
import java.awt.Color;
import java.awt.Font;
import java.awt.Graphics2D;
import java.awt.event.KeyListener;
import java.awt.image.BufferStrategy;
import javax.swing.JFrame;
public class TetrisMain extends Canvas implements Runnable {
public static final int WIDTH = 400, HEIGHT = 565;
public static void main(String args[]){
JFrame frame = new JFrame("Tetris");
frame.setSize(WIDTH, HEIGHT);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setLocationRelativeTo(null);
frame.setResizable(false);
frame.setLayout(null);
TetrisMain tm = new TetrisMain();
tm.setBounds(0, 25, WIDTH, HEIGHT - 25);
frame.add(tm);
frame.setVisible(true);
}
public void stat(){
Thread t = new Thread(this);
t.setPriority(Thread.MAX_PRIORITY);
t.start();
}
public void run(){
boolean running = true;
while(running){
update();
BufferStrategy buf = getBufferStrategy();
if(buf == null){
createBufferStrategy(3);
continue;
}
Graphics2D g = (Graphics2D) buf.getDrawGraphics();
render(g);
buf.show();
}
}
public void update(){
}
public void render(Graphics2D g){
g.setColor(Color.BLACK);
g.fillRect(0,0,WIDTH,HEIGHT);
g.setColor(Color.WHITE);
g.setFont(new Font("Calibri", 20, Font.PLAIN));
g.drawString("Tetris", 200, 50);
}
public void keyPressed(java.awt.event.KeyEvent e){
}
public void keyTyped(java.awt.event.KeyEvent e){
}
}
[/SPOILER]
kann mir jemand helfen?
LG
Schweizergeizer