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 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237
| /*
Fenetre des parametres 5048
*/
import java.awt.Graphics;
import java.awt.Graphics2D;
import java.awt.Point;
import java.awt.event.*;
import java.awt.event.MouseEvent;
import java.awt.event.MouseListener;
import java.awt.image.BufferedImage;
import java.awt.image.Raster;
import java.io.File;
import java.io.IOException;
import javax.imageio.ImageIO;
import javax.swing.JComponent;
import javax.swing.JFrame;
import javax.swing.*;
import java.awt.*;
import java.awt.Polygon.*;
import java.lang.*;
public class monprog extends JFrame implements MouseListener{
//JScrollPane scrollF; //ICI
Raster data;
BufferedImage buff;
//JDesktopPane desktop;
//JInternalFrame jif;
//JLabel on_off = new JLabel("ON");
JButton b_ONOFF = new JButton("ON");
JButton b_ESC = new JButton("ESC");
JButton b_ENTER = new JButton("ENTER");
JButton b_UP = new JButton("UP");
JButton b_DOWN = new JButton("DOWN");
boolean isOFF = false;
int onoff;
Polygon poly_ESC = new Polygon();
Polygon poly_UP = new Polygon();
Polygon poly_DOWN = new Polygon();
Polygon poly_ENTER = new Polygon();
Polygon poly_ON_OFF = new Polygon();
JTextArea txtLCD = new JTextArea();
public monprog() {
/* DECORATION*/
Image im = Toolkit.getDefaultToolkit().getImage("icon.gif");
setIconImage(im);
setTitle("Access to Parameters");
//FIN DECO
setDefaultCloseOperation(EXIT_ON_CLOSE);
setSize(800, 600);
setLocationRelativeTo(null);
addMouseListener(this);
txtLCD.setBackground(Color.green);
// txtLCD.setBounds(109,173,175,59);
txtLCD.setEditable(false);
txtLCD.setText("HELLO");
setSize(520, 570);
setVisible(true);
ImageIcon i5048 = new ImageIcon("5048.png");
getContentPane().add(new JLabel(i5048));
//add(txtLCD);
//txtLCD.setBounds(109,173,175,59);
Dimension screenDimension = Toolkit.getDefaultToolkit().getScreenSize();
int screenX = (screenDimension.width - this.getWidth()) / 2;
int screenY = (screenDimension.height - this.getHeight()) / 2;
setLocation(screenX,screenY);
//new Frame().setVisible(true);
Image img = i5048.getImage();
buff = new BufferedImage(img.getWidth(null), img.getHeight(null), BufferedImage.TYPE_INT_RGB);
data = buff.getData();
//Graphics2D graphics = (Graphics2D)buff.getGraphics();
//graphics.drawString("my text goes here", 109, 173);
//repaint();
//Graphics2D graphics = (Graphics2D)buff.getGraphics();
//setForeground(Color.green);
//graphics.drawString("my text goes here", 50, 50);
//Ajout des points aux polygones
poly_ESC.addPoint(300,187);
poly_ESC.addPoint(323,187);
poly_ESC.addPoint(323,207);
poly_ESC.addPoint(300,207);
poly_ENTER.addPoint(386,186);
poly_ENTER.addPoint(409,186);
poly_ENTER.addPoint(409,209);
poly_ENTER.addPoint(386,209);
poly_UP.addPoint(343,154);
poly_UP.addPoint(367,154);
poly_UP.addPoint(367,174);
poly_UP.addPoint(343,174);
poly_DOWN.addPoint(345,213);
poly_DOWN.addPoint(368,213);
poly_DOWN.addPoint(368,232);
poly_DOWN.addPoint(345,232);
poly_ON_OFF.addPoint(221,334);
poly_ON_OFF.addPoint(309,334);
poly_ON_OFF.addPoint(309,399);
poly_ON_OFF.addPoint(221,399);
}
public static void main(String[] args) {
monprog p5048 = new monprog();
monprog.setVisible(true);
}
/*
public void parameter(){
System.out.println("dans PARAMETER");
}
*/
public void goMenu(){
switch(onoff){
case 0: System.out.println("go Menu OFF");break;
//OFF => StartSystem
case 1: System.out.println("go Menu ON");break;
default: break;
}
}
public void writeLCD(){
}
/*
public void paint( Graphics g ){
g.setFont(new Font("Serif",Font.PLAIN,12));
g.setColor(Color.RED);
g.drawString("HelloWord",50,50);
}
*/
public void testLocation(Point mouse, String text) {
System.out.println("in TEST LOCATION");
// test si la souris est dans les data de l'image
if(data.getBounds().contains(mouse))
System.out.println(text + " - image");
else
System.out.println(text + " - !image");
}
public void mouseClicked(MouseEvent e) {
//récupération de la position de la souri
System.out.println("MOUSECLICKED");
Point p = e.getPoint();
testLocation(p, "mouseClicked");
int x= e.getX();
int y= e.getY();
System.out.println("x= "+x +" y= "+y);
if(poly_ON_OFF.contains(x,y) == true){
System.out.println("le point est dans ON_OFF");
b_ONOFF.setSelected(true);
if(isOFF == true){
onoff = 1;
System.out.println("ON");
isOFF = false;
goMenu();
}else{
onoff = 0;
System.out.println("OFF");
isOFF = true;
goMenu();
}
}
if(poly_ESC.contains(x,y) == true){
System.out.println("le point est dans ESC");
b_ESC.setSelected(true);
}
if(poly_ENTER.contains(x,y) == true){
System.out.println("le point est dans ENTER");
b_ENTER.setSelected(true);
}
if(poly_UP.contains(x,y) == true){
System.out.println("le point est dans UP");
b_UP.setSelected(true);
}
if(poly_DOWN.contains(x,y) == true){
System.out.println("le point est dans DOWN");
b_DOWN.setSelected(true);
}
}
public void mousePressed(MouseEvent e) {
//récupération de la position de la souri
System.out.println("MOUSEPRESSED");
Point p = e.getPoint();
testLocation(p, "mousePressed");
}
public void mouseReleased(MouseEvent e) {
//récupération de la position de la souri
System.out.println("MOUSERELEASED");
Point p = e.getPoint();
testLocation(p, "mouseReleased");
}
public void mouseEntered(MouseEvent e) { }
public void mouseExited(MouseEvent e) { }
/*
public void paint(Graphics g){
g.drawLabel();
}
*/
} |
Partager