1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59
| package robot;
import java.awt.Color;
import java.awt.Graphics;
import java.awt.Image;
import java.io.File;
import java.io.IOException;
import javax.imageio.ImageIO;
import javax.swing.JPanel;
public class Panneau extends JPanel {
int x;
int y;
private static Image backgroundImage = readImage("background.jpeg");
private static Image rubyImage = readImage("RUBY.png");
private static Image readImage(String name) {
try {
return ImageIO.read(new File("images/"+name));
} catch (IOException e) {
e.printStackTrace();
return null;
}
}
public void paintComponent(Graphics g) {
super.paintComponent(g);
if ( backgroundImage!=null ) {
g.drawImage(backgroundImage, 0, 0, this.getWidth(), this.getHeight(), this);
}
if ( rubyImage!=null ) {
g.drawImage(rubyImage, 800/8*x, this.getHeight()/8*y, 800/8, this.getHeight()/8, this);
}
g.setColor(Color.BLACK);
for (int i=0; i<8; i++) {
g.drawLine(800/8*i, 0, 800/8*i, this.getHeight());
g.drawLine(0, this.getHeight()/8*i, 800, this.getHeight()/8*i);
}
}
public void posJoyaux(int x, int y) {
this.x=x;
this.y=y;
this.repaint();
}
/*public void remplacerImage(Image im1, String im2) {
try {
im1 = ImageIO.read(new File('"' + im2 + '"'));
} catch (IOException e) {
e.printStackTrace();
}
}*/
} |
Partager