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
| /*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
/*
* appli_dessin.java
*
* Created on 09-mai-2011, 13:37:56
*/
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
/**
*
* @author Corentin
*/
public class appli_dessin extends javax.swing.JFrame {
/** Creates new form appli_dessin */
public appli_dessin() {
initComponents();
}
Color couleur = Color.lightGray;
Point anchor;
Point currentpoint;
Point starts[] = new Point[500];
Point ends[] = new Point[500];
int currline = 0;
/** This method is called from within the constructor to
* initialize the form.
* WARNING: Do NOT modify this code. The content of this method is
* always regenerated by the Form Editor.
*/
private void bout_couleursActionPerformed(java.awt.event.ActionEvent evt) {
couleur = JColorChooser.showDialog(getContentPane(),"Choisissez une couleur",couleur);
if(couleur == null)
couleur = Color.lightGray;
}
private void couleursMouseClicked(java.awt.event.MouseEvent evt) {
couleur = JColorChooser.showDialog(getContentPane(),"Choisissez une couleur",couleur);
if(couleur == null)
couleur = Color.lightGray;
}
private void PdessinMousePressed(java.awt.event.MouseEvent evt) {
int x = evt.getX();
int y = evt.getY();
anchor = new Point(x,y);
}
private void PdessinMouseReleased(java.awt.event.MouseEvent evt) {
int x = evt.getX();
int y = evt.getY();
addline(x,y);
}
private void PdessinMouseDragged(java.awt.event.MouseEvent evt) {
int x = evt.getX();
int y = evt.getY();
currentpoint = new Point(x,y);
repaint();
}
void addline(int x, int y){
starts[currline] = anchor;
ends[currline] = new Point(x,y);
currline++;
currentpoint = null;
anchor = null;
repaint();
}
public void paint(Graphics g){
super.paint(g);
for(int i = 0 ; i < currline ; i++){
g.drawLine(starts[i].x, starts[i].y,ends[i].x,ends[i].y);
}
g.setColor(Color.blue);
if(currentpoint != null)
g.drawLine(anchor.x,anchor.y,currentpoint.x,currentpoint.y);
}
/**
* @param args the command line arguments
*/
public static void main(String args[]) {
java.awt.EventQueue.invokeLater(new Runnable() {
public void run() {
new appli_dessin().setVisible(true);
}
});
}
// Variables declaration - do not modify
private javax.swing.JPanel Pbout;
private javax.swing.JPanel Pdessin;
private javax.swing.JButton bout_couleurs;
private javax.swing.JButton bout_libre;
private javax.swing.JButton bout_lignes;
private javax.swing.JButton bout_ovales;
private javax.swing.JButton bout_rectangles;
private javax.swing.JButton bout_triangles;
private javax.swing.JMenu couleurs;
private javax.swing.JMenuItem enregistrer;
private javax.swing.JMenu fichier;
private javax.swing.JMenu formes;
private javax.swing.JMenuBar jMenuBar1;
private javax.swing.JMenuItem libre;
private javax.swing.JMenuItem lignes;
private javax.swing.JMenuItem ouvrir;
private javax.swing.JMenuItem ovales;
private javax.swing.JMenuItem rectangles;
private javax.swing.JMenuItem triangles;
// End of variables declaration
} |
Partager