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
| class Gameselection extends JDialog{
Gameselection() {
JPanel pan = new JPanel();
this.setTitle("Choix du jeux");
this.setSize(400, 200);
this.setAlwaysOnTop(true);
this.setResizable(false);
this.setDefaultCloseOperation(this.DISPOSE_ON_CLOSE);
this.setLocationRelativeTo(null);
this.setVisible(true);
this.setContentPane(pan);
pan.setBackground(Color.ORANGE);
pan.setLayout(null);
JButton bouton1 = new JButton("DELETE");
bouton1.setBounds(215, 100, 120, 20);
pan.add(bouton1);
bouton1.addActionListener(new TraitementBut1());
JButton bouton2 = new JButton("NEW GAME");
bouton2.setBounds(50, 100, 120, 20);
pan.add(bouton2);
bouton2.addActionListener(new TraitementBut2());
JComboBox jComboBox1 = new JComboBox();
JLabel label1 = new JLabel("Game Selection");
pan.add(jComboBox1);
pan.add(label1);
jComboBox1.setBounds(60, 35, 265, 30);
label1.setBounds(60, 10, 101, 10);
File directory = new File("src/Games");
String liste[] = directory.list();
for (int i = 0; i < liste.length; i++) {
String aDirectory = liste[i];
jComboBox1.addItem(aDirectory);
jComboBox1.setSelectedItem(Main.GameSelected);
JSONObject obj = new JSONObject();
jComboBox1.addItemListener(e ->
{
if (e.getStateChange() == ItemEvent.SELECTED) {
obj.put("GAMESELECTED",Main.GameSelected = (String) jComboBox1.getSelectedItem());
try {
FileWriter out = new FileWriter("src/Settings/GameSelection/GameSelection.json");
obj.writeJSONString(out);
out.close();
} catch (IOException H) {
H.printStackTrace();
}
try {
Main.setupConfigs();
}catch(Exception z){
z.printStackTrace();
}
}
});
}
}
public class TraitementBut1 implements ActionListener {
/**
* obligatoire car test implémente l'interface ActionListener
*/
public void actionPerformed(ActionEvent e) {
}
}
public class TraitementBut2 implements ActionListener {
/**
* obligatoire car test implémente l'interface ActionListener
*/
public void actionPerformed(ActionEvent e) {
new Nouveaujeux();
// File newdossier = new File("src/Games/"+ "test"); // c'est le nom que vous voulez donner à votre dossier
// newdossier.mkdirs();
}
}
} |
Partager