Pac-Man/src/MapMenu.java

89 lines
1.8 KiB
Java
Raw Normal View History

2020-06-07 17:42:52 +02:00
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
2020-06-07 17:09:33 +02:00
import java.io.File;
2020-06-07 17:42:52 +02:00
import java.sql.SQLException;
2020-06-07 17:09:33 +02:00
import javax.swing.JButton;
import javax.swing.JComboBox;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JTextField;
public class MapMenu extends JFrame {
2020-06-07 17:42:52 +02:00
public boolean rdy;
2020-06-07 17:09:33 +02:00
JButton button;
JPanel panel;
2020-06-07 17:42:52 +02:00
2020-06-07 17:09:33 +02:00
JComboBox bob;
2020-06-07 17:42:52 +02:00
2020-06-07 17:09:33 +02:00
String[] maps;
2020-06-07 17:42:52 +02:00
2020-06-07 17:09:33 +02:00
File path;
2020-06-07 17:42:52 +02:00
2020-06-07 17:09:33 +02:00
Game game;
2020-06-07 17:42:52 +02:00
String selectedMap;
2020-06-07 17:09:33 +02:00
public MapMenu() {
2020-06-07 17:42:52 +02:00
2020-06-07 17:09:33 +02:00
super("Map Menu");
2020-06-07 17:42:52 +02:00
System.setProperty("sun.java2d.opengl", "true");
2020-06-07 17:09:33 +02:00
path = new File("assets/maps");
2020-06-07 17:42:52 +02:00
2020-06-07 17:09:33 +02:00
maps = path.list();
2020-06-07 17:42:52 +02:00
for (int i = 0; i < maps.length; i++) {
maps[i] = maps[i].substring(0, maps[i].length() - 4);
}
2020-06-07 17:09:33 +02:00
this.setVisible(true);
this.setBounds(100, 100, 300, 200);
this.setResizable(false); // Man kann die Gr<47><72>e des Frame nicht ver<65>ndern
panel = new JPanel(); // Panel auf dem visuellen Elemente angezeigt werden
// Der Inhalt des Panels wird auf dem Frame angezeigt:
this.setContentPane(panel);
this.getContentPane().setLayout(null);
2020-06-07 17:42:52 +02:00
2020-06-07 17:09:33 +02:00
button = new JButton("Lauch dat shit");
panel.add(button);
button.setBounds(20, 100, 150, 30);
2020-06-07 17:42:52 +02:00
button.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent evt) {
try {
button_ActionPerformed(evt);
} catch (Exception e) {
e.printStackTrace();
}
}
});
2020-06-07 17:09:33 +02:00
bob = new JComboBox(maps);
panel.add(bob);
bob.setBounds(30, 30, 180, 30);
}
2020-06-07 17:42:52 +02:00
public String getSelectedMap() {
return selectedMap;
}
// Was passieren soll, wenn der Button gedr<64>ckt wird
public void button_ActionPerformed(ActionEvent evt) throws SQLException {
selectedMap = String.valueOf(bob.getSelectedItem());
System.out.println(selectedMap + " is now the selected Map!");
rdy = true;
2020-06-07 17:50:14 +02:00
this.setVisible(false);
2020-06-07 17:42:52 +02:00
}
2020-06-07 17:09:33 +02:00
}