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 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268
|
/*
* EnveloppeConvexeJApplet.java
*
* Created on 22 mars 2006, 20:44
*/
import java.awt.Color;
import java.awt.Graphics;
/**
*
* @author root
*/
public class EnveloppeConvexeJApplet extends javax.swing.JApplet
{
ListePoints liste;
public EnveloppeConvexeJApplet()
{
setSize(650,450);
liste = new ListePoints();
}
/** Initializes the applet EnveloppeConvexeJApplet */
public void init()
{
try
{
java.awt.EventQueue.invokeAndWait(new Runnable()
{
public void run()
{
initComponents();
}
});
}
catch (Exception ex)
{
ex.printStackTrace();
}
}
public void paint(Graphics g)
{
dessinPanel.setBackground(Color.white);
liste.draw(dessinPanel.getGraphics(),5,5,Color.black);
}
/** This method is called from within the init() method to
* initialize the form.
* WARNING: Do NOT modify this code. The content of this method is
* always regenerated by the Form Editor.
*/
// <editor-fold defaultstate="collapsed" desc=" Generated Code ">//GEN-BEGIN:initComponents
private void initComponents()
{
mainPanel = new javax.swing.JPanel();
dessinPanel = new javax.swing.JPanel();
boutonEffacer = new javax.swing.JButton();
boutonAjouter = new javax.swing.JButton();
champX = new javax.swing.JTextField();
champY = new javax.swing.JTextField();
labelX = new javax.swing.JLabel();
labelY = new javax.swing.JLabel();
boutonGenerer = new javax.swing.JButton();
labelGenerer = new javax.swing.JLabel();
champGenerer = new javax.swing.JTextField();
setBackground(new java.awt.Color(0, 0, 0));
setName("appletPanel");
mainPanel.setBackground(new java.awt.Color(102, 153, 255));
mainPanel.setMaximumSize(new java.awt.Dimension(650, 450));
mainPanel.setMinimumSize(new java.awt.Dimension(650, 450));
mainPanel.setName("mainPanel");
mainPanel.setPreferredSize(new java.awt.Dimension(650, 450));
dessinPanel.setBackground(new java.awt.Color(255, 255, 255));
dessinPanel.setBorder(new javax.swing.border.LineBorder(new java.awt.Color(0, 0, 0), 1, true));
/*ici*/
dessinPanel.addMouseListener(new java.awt.event.MouseAdapter()
{
public void mouseClicked(java.awt.event.MouseEvent evt)
{
dessinPanelMouseClicked(evt);
}
});
org.jdesktop.layout.GroupLayout dessinPanelLayout = new org.jdesktop.layout.GroupLayout(dessinPanel);
dessinPanel.setLayout(dessinPanelLayout);
dessinPanelLayout.setHorizontalGroup(
dessinPanelLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
.add(0, 473, Short.MAX_VALUE)
);
dessinPanelLayout.setVerticalGroup(
dessinPanelLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
.add(0, 336, Short.MAX_VALUE)
);
boutonEffacer.setText("Effacer");
boutonEffacer.addMouseListener(new java.awt.event.MouseAdapter()
{
public void mouseClicked(java.awt.event.MouseEvent evt)
{
boutonEffacerMouseClicked(evt);
}
});
boutonAjouter.setText("Ajouter");
boutonAjouter.addMouseListener(new java.awt.event.MouseAdapter()
{
public void mouseClicked(java.awt.event.MouseEvent evt)
{
boutonAjouterMouseClicked(evt);
}
});
champY.setMaximumSize(new java.awt.Dimension(10, 19));
champY.setMinimumSize(new java.awt.Dimension(10, 19));
champY.setPreferredSize(new java.awt.Dimension(10, 19));
labelX.setText("X :");
labelY.setText("Y :");
boutonGenerer.setText("G\u00e9n\u00e9rer");
boutonGenerer.addMouseListener(new java.awt.event.MouseAdapter()
{
public void mouseClicked(java.awt.event.MouseEvent evt)
{
boutonGenererMouseClicked(evt);
}
});
labelGenerer.setText("Nombre de points :");
org.jdesktop.layout.GroupLayout mainPanelLayout = new org.jdesktop.layout.GroupLayout(mainPanel);
mainPanel.setLayout(mainPanelLayout);
mainPanelLayout.setHorizontalGroup(
mainPanelLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
.add(mainPanelLayout.createSequentialGroup()
.add(dessinPanel, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
.addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
.add(mainPanelLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
.add(boutonEffacer, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 159, Short.MAX_VALUE)
.add(mainPanelLayout.createSequentialGroup()
.add(labelX)
.addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
.add(champX, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 31, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
.addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED, 62, Short.MAX_VALUE)
.add(labelY)
.addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
.add(champY, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 32, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))
.add(boutonAjouter, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 159, Short.MAX_VALUE)
.add(labelGenerer, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 159, Short.MAX_VALUE)
.add(champGenerer, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 159, Short.MAX_VALUE)
.add(boutonGenerer, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 159, Short.MAX_VALUE))
.addContainerGap())
);
mainPanelLayout.setVerticalGroup(
mainPanelLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
.add(mainPanelLayout.createSequentialGroup()
.add(mainPanelLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
.add(mainPanelLayout.createSequentialGroup()
.addContainerGap()
.add(mainPanelLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE)
.add(labelX)
.add(champX, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
.add(labelY)
.add(champY, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))
.addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
.add(boutonAjouter)
.add(18, 18, 18)
.add(labelGenerer)
.addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
.add(champGenerer, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
.addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
.add(boutonGenerer)
.add(95, 95, 95)
.add(boutonEffacer))
.add(dessinPanel, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))
.addContainerGap(112, Short.MAX_VALUE))
);
org.jdesktop.layout.GroupLayout layout = new org.jdesktop.layout.GroupLayout(getContentPane());
getContentPane().setLayout(layout);
layout.setHorizontalGroup(
layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
.add(mainPanel, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
);
layout.setVerticalGroup(
layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
.add(mainPanel, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
);
}// </editor-fold>//GEN-END:initComponents
private void boutonGenererMouseClicked(java.awt.event.MouseEvent evt)//GEN-FIRST:event_boutonGenererMouseClicked
{//GEN-HEADEREND:event_boutonGenererMouseClicked
if (evt.getButton() == java.awt.event.MouseEvent.BUTTON1)
{
int nb = 0;
try
{
nb = Integer.parseInt(champGenerer.getText());
liste.effacer();
repaint();
liste.generer(nb,dessinPanel.getWidth(),dessinPanel.getHeight());
}
catch(Exception e)
{}
}
}//GEN-LAST:event_boutonGenererMouseClicked
private void boutonAjouterMouseClicked(java.awt.event.MouseEvent evt)//GEN-FIRST:event_boutonAjouterMouseClicked
{//GEN-HEADEREND:event_boutonAjouterMouseClicked
if (evt.getButton() == java.awt.event.MouseEvent.BUTTON1)
{
int x = 1;
int y = 1;
try
{
x = Integer.parseInt(champX.getText());
y = Integer.parseInt(champY.getText());
liste.add(x,y);
liste.draw(dessinPanel.getGraphics(),5,5,Color.black);
}
catch(Exception e)
{}
}
}//GEN-LAST:event_boutonAjouterMouseClicked
private void boutonEffacerMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_boutonEffacerMouseClicked
if (evt.getButton() == java.awt.event.MouseEvent.BUTTON1)
{
liste.effacer();
dessinPanel.setBackground(Color.white);
dessinPanel.repaint();
}
}//GEN-LAST:event_boutonEffacerMouseClicked
private void dessinPanelMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_dessinPanelMouseClicked
int x = evt.getX();
int y = evt.getY();
if (evt.getButton() == java.awt.event.MouseEvent.BUTTON1)
{
liste.add(x,y);
liste.draw(dessinPanel.getGraphics(),5,5,Color.black);
}
}//GEN-LAST:event_dessinPanelMouseClicked
// Variables declaration - do not modify//GEN-BEGIN:variables
private javax.swing.JButton boutonAjouter;
private javax.swing.JButton boutonEffacer;
private javax.swing.JButton boutonGenerer;
private javax.swing.JTextField champGenerer;
private javax.swing.JTextField champX;
private javax.swing.JTextField champY;
private javax.swing.JPanel dessinPanel;
private javax.swing.JLabel labelGenerer;
private javax.swing.JLabel labelX;
private javax.swing.JLabel labelY;
private javax.swing.JPanel mainPanel;
// End of variables declaration//GEN-END:variables
} |
Partager