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 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110
| import java.awt.Color;
import java.awt.Graphics;
import java.awt.Graphics2D;
import java.awt.MediaTracker;
import java.awt.image.BufferedImage;
import java.io.File;
import java.io.IOException;
import javax.imageio.ImageIO;
import javax.swing.*;
public class Panel2 extends JPanel {
Graphics g2;
MediaTracker tracker;
File file;
JButton marche,arret;
ImageIO io;
ImageIcon image;
BufferedImage input;
int p2512[] ={0,1,0,0,1,0,1,0,0,1,1,1};
public Panel2()
{
marche = new JButton("Reprendre");
marche.setLocation(1, 1);
this.add(marche);
arret = new JButton("Arreter");
arret.setLocation(1, 10);
this.add(arret);
try
{
file = new File("test.jpg");
input = ImageIO.read(file);
}
catch (IOException e)
{
e.printStackTrace();
}
}
public void paintComponent(Graphics g)
{
//super.paintComponent(g);
// initialisation de limage
Graphics2D g2d2 = input.createGraphics();
int j=0;
for(int i=0;i<6;i++)
{
if(p2512[j]==1)
g2d2.setColor(Color.GREEN);
else
g2d2.setColor(Color.red);
g2d2.fillRect(292+16*i, 44, 10, 10);
System.out.println(j);
j++;
}
for(int h=0;h<6;h++)
{
if(p2512[j]==1)
g2d2.setColor(Color.GREEN);
else
g2d2.setColor(Color.red);
g2d2.fillRect(292+16*h, 62, 10, 10);
System.out.println(j);
j++;
}
int w = input.getWidth();
int h = input.getHeight();
boolean zoom = (w > getWidth() || h > getHeight());
if (zoom)
{
g.drawImage(input, 0, 0, getWidth(), getHeight(), null);
}
else
{
g.drawImage(input, (getWidth()-w)/2, (getHeight()-h)/2, null);
}
//g.dispose();
}
public static void main (String [] args)
{
JFrame jf = new JFrame ();
jf.getContentPane().add( new Panel2() );
jf.setSize(400,400);
jf.setVisible(true);
}
} |
Partager