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
| package performyourgame.chrono.demifond;
import java.awt.Font;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.KeyEvent;
import java.awt.event.KeyListener;
import javax.swing.BoxLayout;
import javax.swing.ImageIcon;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JTextField;
public class MainActivity extends JFrame implements KeyListener {
static Chrono chrono = new Chrono();
private static JButton btnStart = new JButton("START");
private static JButton[] btnLap = new JButton[13];
// private static JButton btnStop = new JButton("STOP");
private static JTextField[] time = new JTextField[13];
// private static JButton btnPause = new JButton("PAUSE");
// private static JButton btnResume = new JButton("REPRENDRE");
private static JButton btnErase = new JButton("REMISE A ZERO");
private static JButton btnQuit = new JButton("QUITTER");
private static JLabel allRight = new JLabel();
public static void main(String[] args) {
JFrame frame = new JFrame();
frame.setTitle("3 fois 500 mètres");
frame.setSize(900, 600);
frame.setResizable(true);
frame.setLocationRelativeTo(null);
frame.setDefaultCloseOperation(EXIT_ON_CLOSE);
frame.setIconImage(new ImageIcon("Les-7-merveilles-du-monde.jpg").getImage());
frame.setVisible(true);
JPanel content = new JPanel();
frame.setContentPane(content);
content.setLayout(new BoxLayout(content, BoxLayout.PAGE_AXIS));
Font f = new Font(" TimesRoman ", Font.BOLD + Font.ITALIC, 30);
btnStart.setFont(f);
btnErase.setFont(f);
btnQuit.setFont(f);
content.add(btnStart);
// content.add(btnStop);
// content.add(btnPause);
// content.add(btnResume);
for (int i = 1; i < 13; i++) {
JButton jb = new JButton();
JTextField jt = new JTextField();
btnLap[i] = jb;
time[i] = jt;
btnLap[i].setText("Temps" + i);
content.add(jb);
content.add(jt);
;
}
content.add(btnErase);
content.add(btnQuit);
frame.pack();
allRight.setText("@2015, All's right reserved Romuald Grandin");
content.add(allRight);
frame.validate();
// ================================================================= //
// ====================================================================
// //
// Add action listener to button
btnStart.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
// Execute when button is pressed
chrono.start();
for (int i = 1; i < 13; i++) {
final int j = i;
time[j].setText(chrono.getDureeTxt());
}
}
});
// Add action listener to button
for (int i = 1; i < 13; i++) {
final int j = i;
btnLap[j].addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
// Execute when button is pressed
chrono.timeLap();
time[j].setText(chrono.getDureeTxt());
}
});
}
// Add action listener to button
btnErase.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
// Execute when button is pressed
for (int i = 1; i < 13; i++) {
final int j = i;
time[j].setText("");
}
}
});
// Add action listener to button
btnQuit.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
// Execute when button is pressed
frame.dispose();
}
});
// System.out.println(chrono.getDureeMs()); // affichage du résultat en
// millisecondes
// System.out.println(chrono.getDureeSec()); // affichage en secondes
// System.out.println(chrono.getDureeTxt()); // affichage au format "1 h
// 26 min 32 s"
}
@Override
public void keyTyped(KeyEvent e) {
}
@Override
public void keyPressed(KeyEvent e) {
if (e.getSource() == btnLap) {
if (e.getKeyCode() == KeyEvent.VK_ENTER) {
}
}
}
@Override
public void keyReleased(KeyEvent e) {
// TODO Auto-generated method stub
}
} |
Partager