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
|
import javax.swing.JPanel;
import javax.swing.JFrame;
import java.awt.GridBagLayout;
import java.awt.Dimension;
import java.awt.Color;
import java.awt.GridBagConstraints;
import java.awt.SystemColor;
import java.awt.Rectangle;
import javax.swing.JButton;
import javax.swing.JToggleButton;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.Point;
import java.util.ArrayList;
import java.util.List;
import javax.swing.JComboBox;
@SuppressWarnings("serial")
public class MaClasse extends JFrame implements ActionListener {
// Enumeration
public enum Tour {
VIDE("",-1),
UN("1",1),
DEUX("2",2),
CINQ("5",5),
DIX("10",10),
CENT("100",100);
String[] tourString = { "","1", "2", "5", "10", "100" };
protected String label;
protected int valeur;
/** Constructeur */
Tour(String plabel, int valeur) {
this.label=plabel;
this.valeur = valeur;
}
public int getValeur() {
return this.valeur;
}
public String getLabel() {
return this.label;
}
}
private JButton jButtonRemiseAZero;
private JToggleButton jToggleButtonAB1;
private JButton jButtonGenerer = null;
private JComboBox jComboBoxNbTour;
public static void main(String[] args) {
new MaClasse();
}
/**
* Constructeur
*/
public MaClasse(){
// jButtonGenerer
jButtonGenerer = new JButton();
jButtonGenerer.setLocation(new Point(120, 520));
jButtonGenerer.setText("Générer");
jButtonGenerer.setSize(new Dimension(150, 40));
//jToggleButtonAB1
jToggleButtonAB1 = new JToggleButton();
jToggleButtonAB1.setLocation(new Point(30, 395));
// jToggleButtonAB1.setIcon(new ImageIcon(
// "C:/Users/Sylvain/Documents/Eclipse workspace/Combat/Armée bleue 1.jpg"));
jToggleButtonAB1.setSize(new Dimension(100, 80));
// jButtonRemiseAZero
jButtonRemiseAZero = new JButton();
jButtonRemiseAZero.setText("Remise à Zéro");
jButtonRemiseAZero.setSize(new Dimension(150, 40));
jButtonRemiseAZero.setLocation(new Point(120, 24));
jButtonRemiseAZero.addActionListener(this);
// jComboBoxNbTour
List<String> tourString = new ArrayList<String>();
for(Tour tour : Tour.values()){
tourString.add(tour.getLabel());
}
jComboBoxNbTour = new JComboBox(tourString.toArray());
jComboBoxNbTour.setPreferredSize(new Dimension(80, 25));
jComboBoxNbTour.addActionListener(this);
// jPanelConfiguration
JPanel jPanelConfiguration = new JPanel();
jPanelConfiguration.setBounds(new Rectangle(0, 0, 384, 600));
jPanelConfiguration.setLayout(null);
jPanelConfiguration.setBackground(SystemColor.activeCaption);
jPanelConfiguration.add(jButtonRemiseAZero, null);
jPanelConfiguration.add(jToggleButtonAB1, null);
jPanelConfiguration.add(jButtonGenerer, null);
// jPanelSimulation
GridBagConstraints gridBagConstraints = new GridBagConstraints();
gridBagConstraints.fill = GridBagConstraints.VERTICAL;
gridBagConstraints.gridy = 1;
gridBagConstraints.weightx = 1.0;
gridBagConstraints.gridx = 0;
JPanel jPanelSimulation = new JPanel();
jPanelSimulation.setLayout(new GridBagLayout());
jPanelSimulation.setBackground(new Color(84, 57, 0));
jPanelSimulation.setBounds(new Rectangle(0, 600, 984, 115));
jPanelSimulation.add(jComboBoxNbTour, gridBagConstraints);
// jPanelCarte
JPanel jPanelCarte = new JPanel();
jPanelCarte.setLayout(new GridBagLayout());
jPanelCarte.setBounds(new Rectangle(384, 0, 600, 600));
jPanelCarte.setBackground(Color.green);
// jContentPane
JPanel jContentPane = new JPanel();
jContentPane.setLayout(null);
jContentPane.setForeground(new Color(51, 102, 120));
jContentPane.add(jPanelConfiguration, null);
jContentPane.add(jPanelCarte, null);
jContentPane.add(jPanelSimulation, null);
// option de la JFrame
this.setSize(1000, 750);
this.setContentPane(jContentPane);
this.setTitle("JFrame");
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
setVisible(true);
}
@Override
public void actionPerformed(ActionEvent ae) {
if(ae.getSource().equals(jComboBoxNbTour)){
String tourLabel = (String) jComboBoxNbTour.getSelectedItem();
for(Tour tour : Tour.values()){
if(tour.getLabel().equals(tourLabel)){
System.out.println(tour.getValeur());
}
}
}
}
} |
Partager