Io ho sto codice
codice:
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
public class scorriwords extends JFrame implements Runnable,KeyListener{
int x=10,y=400;
Thread runner;
scorriwords(){
super("ScorriWords v.1.0 - Keratox");
setBounds(20,10,700,500);
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
JPanel pan = new JPanel();
pan.addKeyListener(this);
setContentPane(pan);
if(runner==null){
runner= new Thread(this);
runner.start();
}
}
public void run(){
while(true){
if(y<2){
y=588;
}
if(y>599){
y=4;
}
try{
Thread.sleep(150);
}
catch(Exception et){ }
repaint();
}
}
public void keyReleased(KeyEvent ker){
System.out.println("Movimento 1:");
}
public void keyTyped(KeyEvent ket){
System.out.println("Movimento 2:");
}
public void keyPressed(KeyEvent kep){
System.out.println("Movimento 3:");
int id = kep.getKeyCode();
if(id==KeyEvent.VK_DOWN){
y+=10;
System.out.println("Giu'");
}
if(id==KeyEvent.VK_UP){
y-=10;
System.out.println("SU");
}
if(id==KeyEvent.VK_LEFT){
x-=10;
System.out.println("SINISTRA'");
}
if(id==KeyEvent.VK_RIGHT){
x+=10;
System.out.println("DESTRA'");
}
repaint();
}
public void paint(Graphics g){
Graphics2D g2 = (Graphics2D)g;
g2.fillRect(0, 0, getWidth()-1, getHeight()-1);
Font fontz = new Font("Courier new", Font.BOLD, 15);
g2.setFont(fontz);
g2.setColor(Color.YELLOW);
g2.drawString("Word", x,y);
}
public static void main(String[] args){
scorriwords sw = new scorriwords();
sw.setBackground(Color.BLACK);
sw.show();
}
}
Ma non mi va