hi guys i need little help with my "breakout" program
i need a code to move the paddle "easy code" with arrow keys
this is my code!!
i need a code to move the paddle "easy code" with arrow keys
this is my code!!
public class Brick {
int xPos,yPos;
}
import java.awt.*;
import java.awt.event.*;
public class test extends Canvas {
Graphics buffer;
Image bufferI;
Brick[] brickor = new Brick[12];
public test () {
setPreferredSize(new Dimension(480,480));
for (int n=0; n<2; n++) {
for (int m = 0; m<6; m++) {
brickor[n*6+m] = new Brick();
brickor[n*6+m].xPos = m*80;
brickor[n*6+m].yPos = n*12;
}
}
}
public void update(Graphics g) {
paint(g);
}
public void paint(Graphics yta) {
if (buffer == null) {
bufferI = createImage(480,480);
buffer = bufferI.getGraphics();
}
buffer.setColor(Color.BLACK);
buffer.fillRect(0,0,480,480);
// Ritar ut alla block
for (int n = 0; n<12; n++) {
buffer.setColor(Color.RED);
buffer.fillRect(brickor[n].xPos,brickor[n].yPos,78,10);
}
// Hنr skriv koden fِr att rita ut "pinnen".
buffer.setColor(Color.BLUE);
buffer.fillRect(x,y,80,10);
yta.drawImage(bufferI,0,0,null);
}
}
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
public class breakout extends JFrame implements KeyListener
{
int velX = 0, velY = 0;
int x = 200;
int y = 350;
public breakout()
{
setTitle("BreakOut");
test kludd = new test();
add(kludd);
pack();
setVisible(true);
kludd.addKeyListener(this);
addKeyListener(this);
setFocusable(true);
setFocusTraversalKeysEnabled(false);
}
public void keyPressed(KeyEvent e) {
// System.out.println(e);
System.out.println(e.getKeyCode());
if (e.getKeyCode() == 37){
System.out.println("Du tryckte pه hِgerpil!!!");
}
}
public void keyReleased(KeyEvent e) {
System.out.println("Key Released!!!");
}
public void keyTyped(KeyEvent e) {
}
public static void main(String[] arg)
{
new breakout();
}
}