unknown_member hat gesagt.:Es ist vllt einiges noch schlecht oder unpraktisch, da ich gerade an diesem Fehler gescheitert bin und nicht weitergemacht habe
Aber wieso wird das nicht gezeichnet
Frage weiter unten wegen falschem editieren!
unknown_member hat gesagt.:Es ist vllt einiges noch schlecht oder unpraktisch, da ich gerade an diesem Fehler gescheitert bin und nicht weitergemacht habe
import java.io.*;
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import java.awt.image.*;
import javax.imageio.*;
public class Level extends JFrame
implements ActionListener, MouseListener, WindowListener, KeyListener {
JPanel game;
JPanel set;
JButton ende;
BufferedImage player;
BufferedImage background;
BufferedImage block1;
BufferedImage block2;
ImageIcon close;
int location = 100;
int height = 420;
JFrame frame;
public static void main(String [] args) throws IOException {
Level go = new Level();
go.setTitle("Level");
go.setSize(Toolkit.getDefaultToolkit().getScreenSize());
go.setUndecorated(false); //Wenn fertig programmiert und getestet, auf true setzen
go.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
go.setResizable(false);
}
Level() {
makeGui();
addWindowListener(this);
addKeyListener(this);
}
public void makeGui() {
game = new JPanel();
set = new JPanel();
add(BorderLayout.CENTER,game);
close = new ImageIcon( "close.gif" );
frame = new JFrame("Level");
frame.setLayout(new GridLayout(1,1));
frame.add(new JLeinwand());
frame.setSize(Toolkit.getDefaultToolkit().getScreenSize());
frame.addKeyListener(this);
frame.setUndecorated(true);
try {
background = ImageIO.read(new File("background.gif"));
player = ImageIO.read(new File(""));
block1 = ImageIO.read(new File("block1.gif"));
block2 = ImageIO.read(new File(""));
}
catch(IOException e) {
e.getMessage();
}
frame.setVisible(true);
}
class JLeinwand extends JPanel
{
// paints all of the components in this container:
public void paintComponent(Graphics g) {
super.paintComponent(g);
// Z.B.: Ein Bild anzeigen
g.drawImage(background, 0, 0, game); // XXX auf null testen
g.drawImage(player, 0, 0, game); // XXX auf null testen
g.drawImage(block2, 0, 0, game);
g.drawImage(block1, 100, 100, game);
}
}
public void keyReleased(KeyEvent ev) {
}
public void actionPerformed(ActionEvent event) { }
public void mouseEntered(MouseEvent ev) { }
public void mouseExited(MouseEvent ev) { }
public void mouseClicked(MouseEvent ev) { }
public void mouseReleased(MouseEvent ev) { }
public void mousePressed(MouseEvent ev) { }
public void windowOpened(WindowEvent e) { }
public void windowIconified(WindowEvent e) { }
public void windowClosed(WindowEvent e) { }
public void windowActivated(WindowEvent e) { }
public void windowDeiconified(WindowEvent e) { }
public void windowDeactivated(WindowEvent e) { }
public void warten()
{
try {
Thread.sleep(1000);
} catch (InterruptedException e) { }
}
public void windowClosing(WindowEvent e) {
}
public void keyPressed(KeyEvent ev) {
if (ev.getKeyCode() == KeyEvent.VK_ESCAPE) {
System.exit(0);
}
}
public void keyTyped(KeyEvent ev) { }
}
PS (Post-Scriptum icon_wink.gif ): Falls es nötig ist, kann ich gerne auch die bilder posten.
}
public void keyTyped(KeyEvent ev) { }
}