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 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337
|
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.DefaultListModel;
import javax.swing.Timer;
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
/*
* JFrame1.java
*
* Created on 16 avr. 2009, 04:32:33
*/
/**
*
* @author abdel
*/
public class JFrame1 extends javax.swing.JFrame {
/** Creates new form JFrame1 */
public JFrame1() {
initComponents();
listeModel = new DefaultListModel();
jList1.setModel(listeModel);
int delai=100;
ActionListener al =new ActionListener() {
public void actionPerformed(ActionEvent e) {
// ici evenement
int min, sec, heu;
sec = Integer.parseInt(Secondes.getText());
min = Integer.parseInt(Minutes.getText());
heu = Integer.parseInt(Heures.getText());
sec++;
if (sec==60){
sec=0; min++;
}
if (min==60){
min=0; heu++;
}
if (heu==24){
heu=0;
}
Secondes.setText(String.valueOf(sec));
Minutes.setText(String.valueOf(min));
Heures.setText(String.valueOf(heu));
calculer(sec, min, heu);
}
};
timer = new Timer(delai,al);
}
private void calculer (int sec, int min, int heu){
double duree = min + sec/60.0 + heu*60.0;
if (interurbain.isSelected()) duree *=2;
if (interNational.isSelected()) duree *=3;
double leCout = duree * Double.parseDouble(PU.getSelectedItem().toString());
cout.setText(String.valueOf(leCout));
}
/** 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.
*/
@SuppressWarnings("unchecked")
// <editor-fold defaultstate="collapsed" desc="Generated Code">
private void initComponents() {
buttonGroup1 = new javax.swing.ButtonGroup();
jPanel1 = new javax.swing.JPanel();
jLabel1 = new javax.swing.JLabel();
PU = new javax.swing.JComboBox();
Heures = new javax.swing.JLabel();
Minutes = new javax.swing.JLabel();
Secondes = new javax.swing.JLabel();
jPanel2 = new javax.swing.JPanel();
urbain = new javax.swing.JRadioButton();
interurbain = new javax.swing.JRadioButton();
interNational = new javax.swing.JRadioButton();
cout = new javax.swing.JLabel();
jLabel2 = new javax.swing.JLabel();
decrocher = new javax.swing.JToggleButton();
raccrocher = new javax.swing.JToggleButton();
jScrollPane1 = new javax.swing.JScrollPane();
jList1 = new javax.swing.JList();
jLabel3 = new javax.swing.JLabel();
total = new javax.swing.JLabel();
setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
jPanel1.setBackground(new java.awt.Color(102, 102, 255));
jLabel1.setForeground(new java.awt.Color(255, 255, 255));
jLabel1.setText("PU");
PU.setForeground(new java.awt.Color(255, 255, 255));
PU.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "1.20", "1.50", "1.70" }));
Heures.setFont(new java.awt.Font("Tahoma", 1, 12));
Heures.setForeground(new java.awt.Color(255, 255, 255));
Heures.setText("0");
Minutes.setFont(new java.awt.Font("Tahoma", 1, 12));
Minutes.setForeground(new java.awt.Color(255, 255, 255));
Minutes.setText("0");
Secondes.setFont(new java.awt.Font("Tahoma", 1, 12));
Secondes.setForeground(new java.awt.Color(255, 255, 255));
Secondes.setText("0");
jPanel2.setBackground(new java.awt.Color(153, 153, 255));
urbain.setBackground(new java.awt.Color(153, 153, 255));
buttonGroup1.add(urbain);
urbain.setForeground(new java.awt.Color(255, 255, 255));
urbain.setSelected(true);
urbain.setText("Urbain");
interurbain.setBackground(new java.awt.Color(153, 153, 255));
buttonGroup1.add(interurbain);
interurbain.setForeground(new java.awt.Color(255, 255, 255));
interurbain.setText("InterUrbain");
interNational.setBackground(new java.awt.Color(153, 153, 255));
buttonGroup1.add(interNational);
interNational.setForeground(new java.awt.Color(255, 255, 255));
interNational.setText("InterNational");
javax.swing.GroupLayout jPanel2Layout = new javax.swing.GroupLayout(jPanel2);
jPanel2.setLayout(jPanel2Layout);
jPanel2Layout.setHorizontalGroup(
jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(jPanel2Layout.createSequentialGroup()
.addContainerGap()
.addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(urbain)
.addComponent(interurbain)
.addComponent(interNational))
.addContainerGap(19, Short.MAX_VALUE))
);
jPanel2Layout.setVerticalGroup(
jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(jPanel2Layout.createSequentialGroup()
.addContainerGap()
.addComponent(urbain)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
.addComponent(interurbain)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
.addComponent(interNational)
.addContainerGap())
);
cout.setBackground(new java.awt.Color(255, 255, 255));
cout.setFont(new java.awt.Font("Tahoma", 3, 18));
cout.setForeground(new java.awt.Color(255, 51, 51));
cout.setText("0");
jLabel2.setForeground(new java.awt.Color(255, 255, 255));
jLabel2.setText("COUT");
decrocher.setText("Décrocher");
decrocher.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
decrocherActionPerformed(evt);
}
});
raccrocher.setLabel("raccrocher");
raccrocher.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
raccrocherActionPerformed(evt);
}
});
jScrollPane1.setViewportView(jList1);
jLabel3.setText("A Payer");
total.setFont(new java.awt.Font("Tahoma", 3, 18)); // NOI18N
total.setForeground(new java.awt.Color(255, 102, 102));
total.setText("0");
javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
jPanel1.setLayout(jPanel1Layout);
jPanel1Layout.setHorizontalGroup(
jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(jPanel1Layout.createSequentialGroup()
.addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(jPanel1Layout.createSequentialGroup()
.addGap(39, 39, 39)
.addComponent(jLabel2, javax.swing.GroupLayout.PREFERRED_SIZE, 55, javax.swing.GroupLayout.PREFERRED_SIZE)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
.addComponent(cout, javax.swing.GroupLayout.PREFERRED_SIZE, 50, javax.swing.GroupLayout.PREFERRED_SIZE)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 129, Short.MAX_VALUE)
.addComponent(jLabel3, javax.swing.GroupLayout.PREFERRED_SIZE, 80, javax.swing.GroupLayout.PREFERRED_SIZE)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(total, javax.swing.GroupLayout.PREFERRED_SIZE, 132, javax.swing.GroupLayout.PREFERRED_SIZE)
.addGap(8, 8, 8))
.addGroup(jPanel1Layout.createSequentialGroup()
.addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false)
.addGroup(javax.swing.GroupLayout.Alignment.LEADING, jPanel1Layout.createSequentialGroup()
.addGap(19, 19, 19)
.addComponent(jPanel2, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
.addGroup(javax.swing.GroupLayout.Alignment.LEADING, jPanel1Layout.createSequentialGroup()
.addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false)
.addGroup(javax.swing.GroupLayout.Alignment.LEADING, jPanel1Layout.createSequentialGroup()
.addGap(28, 28, 28)
.addComponent(Heures, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
.addGroup(javax.swing.GroupLayout.Alignment.LEADING, jPanel1Layout.createSequentialGroup()
.addGap(36, 36, 36)
.addComponent(jLabel1)))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(Minutes, javax.swing.GroupLayout.PREFERRED_SIZE, 24, javax.swing.GroupLayout.PREFERRED_SIZE)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(Secondes, javax.swing.GroupLayout.PREFERRED_SIZE, 24, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(PU, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
.addComponent(raccrocher, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
.addComponent(decrocher, javax.swing.GroupLayout.DEFAULT_SIZE, 153, Short.MAX_VALUE))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 68, Short.MAX_VALUE)
.addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 149, javax.swing.GroupLayout.PREFERRED_SIZE)))
.addContainerGap())
);
jPanel1Layout.setVerticalGroup(
jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(jPanel1Layout.createSequentialGroup()
.addContainerGap()
.addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
.addGroup(jPanel1Layout.createSequentialGroup()
.addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
.addGroup(jPanel1Layout.createSequentialGroup()
.addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(jLabel1)
.addComponent(PU, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
.addGap(18, 18, 18)
.addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(Heures)
.addComponent(Minutes)
.addComponent(Secondes))
.addGap(24, 24, 24))
.addGroup(jPanel1Layout.createSequentialGroup()
.addComponent(raccrocher)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(decrocher)
.addGap(6, 6, 6)))
.addComponent(jPanel2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
.addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 182, javax.swing.GroupLayout.PREFERRED_SIZE))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(cout)
.addComponent(jLabel2)
.addComponent(jLabel3)
.addComponent(total))
.addContainerGap(54, Short.MAX_VALUE))
);
javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
getContentPane().setLayout(layout);
layout.setHorizontalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addContainerGap()
.addComponent(jPanel1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
);
layout.setVerticalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addContainerGap()
.addComponent(jPanel1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
);
pack();
}// </editor-fold>
private void raccrocherActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here
timer.start();
raccrocher.setVisible(false);
decrocher.setVisible(true);
}
private void decrocherActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
timer.stop();
raccrocher.setVisible(true);
decrocher.setVisible(false);
listeModel.addElement(cout.getText());
double tot = Double.parseDouble(cout.getText()) + Double.parseDouble(total.getText());
total.setText(String.valueOf(tot));
Secondes.setText("0");
Minutes.setText("0");
}
/**
* @param args the command line arguments
*/
public static void main(String args[]) {
java.awt.EventQueue.invokeLater(new Runnable() {
public void run() {
new JFrame1().setVisible(true);
}
});
}
// Variables declaration - do not modify
private javax.swing.JLabel Heures;
private javax.swing.JLabel Minutes;
private javax.swing.JComboBox PU;
private javax.swing.JLabel Secondes;
private javax.swing.ButtonGroup buttonGroup1;
private javax.swing.JLabel cout;
private javax.swing.JToggleButton decrocher;
private javax.swing.JRadioButton interNational;
private javax.swing.JRadioButton interurbain;
private javax.swing.JLabel jLabel1;
private javax.swing.JLabel jLabel2;
private javax.swing.JLabel jLabel3;
private javax.swing.JList jList1;
private javax.swing.JPanel jPanel1;
private javax.swing.JPanel jPanel2;
private javax.swing.JScrollPane jScrollPane1;
private javax.swing.JToggleButton raccrocher;
private javax.swing.JLabel total;
private javax.swing.JRadioButton urbain;
// End of variables declaration
Timer timer;
DefaultListModel listeModel;
} |
Partager