Hi, ich bin grad am programmieren eines Ping Pong spiels, ich weiß aber leider nicht wie ich das mit dem update hinbekommen soll, ich las im internet mehrere artikel, versuchte das ganze einzubauen, hat nie geklappt, kann mir einer von euch helfen?
Danke für jede Antwort
Developer_X
Java:
package Pong;
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
@SuppressWarnings("serial")
public class Ping extends JFrame implements Runnable, KeyListener
{
//Attribute
//Dimension
Dimension d = Toolkit.getDefaultToolkit().getScreenSize();
//Ping Pong Attribute
int player_points = 0;
int ki_points = 0;
int player_height = d.height/2;
int ball_height = d.height/2;
public Ping()
{
setTitle("Ping Pong");
setUndecorated(true);
setSize(d);
addKeyListener(this);
}
public void paint(final Graphics g)
{
g.setColor(Color.black);
g.fillRect(0,0,d.width,d.height);
g.setColor(Color.green);
g.setFont(new Font("Times New Roman",3,40));
g.drawString("Player : "+player_points,d.width/5,d.height-20);
g.drawString("KI : "+ki_points, d.width/2,d.height-20);
g.fillRect(d.width/5,player_height,20,d.height/5);
g.fillRect(d.width-d.width/5,ball_height,20,d.height/5);
}
public static void main(String[]args)
{
Ping p = new Ping();
p.setVisible(true);
}
public void run()
{
repaint();
}
public void keyPressed(KeyEvent arg0)
{
if(arg0.getKeyCode()==KeyEvent.VK_UP)
{
player_height++;
}
if(arg0.getKeyCode()==KeyEvent.VK_DOWN)
{
player_height--;
}
}
public void keyReleased(KeyEvent arg0)
{
}
public void keyTyped(KeyEvent arg0)
{
}
}
Developer_X