Vous n’avez pas trouvé la réponse que vous recherchez ?
Posez votre questionpublic void itemStateChanged(ItemEvent e) { CheckBox c = (CheckBox)e.getItemSelectable() if (orientation[0] == c) System.out.println("Nord "); else System.out.println("Sud "); }
package toto; import java.awt.Panel; import java.awt.BorderLayout; import java.awt.CheckboxGroup; import java.awt.Checkbox; import java.applet.Applet; import java.awt.Event; public class ActionCheckbox extends Applet { Panel pansud = new Panel(); BorderLayout borderLayout1 = new BorderLayout(); CheckboxGroup latitude; Checkbox [] orientation; String [] sz = {"N", "S"}; boolean [] bool = {false, true}; public void init() { try { Init(); } catch(Exception e) { e.printStackTrace(); } } private void Init() throws Exception { this.setLayout(borderLayout1); latitude = new CheckboxGroup(); orientation= new Checkbox[2]; for(int i = 0; i < orientation.length; i++){ orientation[i] = new Checkbox(sz[i], latitude, bool[i]); pansud.add(orientation[i]); } this.add(pansud, BorderLayout.CENTER); } public boolean action (Event event, Object eventArg){ if (event.target == orientation[0]) { if (orientation[0].getLabel().startsWith("N")) { System.out.println("Nord"); } return true; }else if (event.target == orientation[1]) { if (orientation[1].getLabel().startsWith("S")) { System.out.println("Sud"); } return true; } return super.action(event, eventArg); } }
public boolean action (Event event, Object eventArg){ if (event.target == orientationA_0[0]) { if (orientationA_0[0].getLabel().startsWith("N")) { System.out.println("Nord"); } return true; }else if (event.target == orientationA_0[1]) { if (orientationA_0[1].getLabel().startsWith("S")) { System.out.println("Sud"); } return true; }else if (event.target == orientationA_1[0]) { if (orientationA_1[0].getLabel().startsWith("N")) { System.out.println("Nord"); } return true; }else if (event.target == orientationA_1[1]) { if (orientationA_1[1].getLabel().startsWith("S")) { System.out.println("Sud"); } return true; } return super.action(event1, eventArg); }