import java.io.*;
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import java.awt.image.*;
import javax.imageio.*;
public class Xtreme extends JFrame
implements ActionListener, MouseListener, WindowListener, KeyListener {
JPanel game;
JPanel set;
JButton ende;
BufferedImage player;
BufferedImage background;
ImageIcon close;
int location = 100;
int height = 420;
boolean coolJump = true;
JFrame frame;
public static void main(String [] args) throws IOException {
Xtreme go = new Xtreme();
go.setTitle("Volleyball X-treme");
//go.setSize(Toolkit.getDefaultToolkit().getScreenSize());
go.setBounds(500,200,200,200);
go.setUndecorated(false); //Wenn fertig programmiert und getestet, auf true setzen
go.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
go.setResizable(false);
go.setVisible(true);
}
Xtreme() {
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("TestFrame");
frame.setLayout(new GridLayout(1,1));
frame.add(new JLeinwand());
//frame.setSize(Toolkit.getDefaultToolkit().getScreenSize());
frame.setSize(400,800);
frame.addKeyListener(this);
try {
background = ImageIO.read(new File("Background_Street.gif"));
player = ImageIO.read(new File("player_one.gif"));
}
catch(IOException e) {
e.getMessage();
}
frame.setVisible(true); // XXX Zuletzt visible machen!!!
}
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, location, height, game); // XXX auf null testen
}
}
public void keyReleased(KeyEvent ev) {
System.out.println(ev.getKeyCode()+" "+KeyEvent.VK_UP);
if (ev.getKeyCode() == KeyEvent.VK_UP) {
//Hier entsteht der Sprung.
new Thread(new Runnable()
{
public void run()
{
for(int i=0; i<1 ; i++)
{
if (coolJump) {
coolJump = false;
System.out.println("height "+height);
height -= 50;
frame.repaint();
try { Thread.sleep(50); } catch(InterruptedException e) {}
height -= 40;
frame.repaint();
try { Thread.sleep(50); } catch(InterruptedException e) {}
height -= 30;
frame.repaint();
try { Thread.sleep(50); } catch(InterruptedException e) {}
height -= 10;
frame.repaint();
try { Thread.sleep(120); } catch(InterruptedException e) {}
height += 60;
frame.repaint();
try { Thread.sleep(50); } catch(InterruptedException e) {}
height += 50;
frame.repaint();
try { Thread.sleep(50); } catch(InterruptedException e) {}
height += 20;
frame.repaint();
try { Thread.sleep(1000); } catch(InterruptedException e) {}
coolJump = true;
}
}
}
}).start();
}
}
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_LEFT && location != 0) {
location-=10;
repaint();
}
if (ev.getKeyCode() == KeyEvent.VK_RIGHT && location != 450) {
location+=10;
repaint();
}
}
public void keyTyped(KeyEvent ev) { }
}