package Semester2; import javax.swing.*; import java.awt.*; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; public class Vorlesung4 extends JFrame { public Vorlesung4(String title) { super(title); } public static void main(String[] args) { // Erstelle Fenster JFrame window = new Vorlesung4("Demo"); window.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); window.setVisible(true); window.setSize(700, 500); window.setLocationRelativeTo(null); // Erstelle 2 Tabs JTabbedPane tabs = new JTabbedPane(); window.add(tabs, BorderLayout.CENTER); JPanel tab1 = new JPanel(); tabs.addTab("Verbindungssuche", tab1); tab1.setLayout(new BoxLayout(tab1, BoxLayout.Y_AXIS)); JPanel tab2 = new JPanel(); tabs.addTab("Erweiterte Suche", tab2); // Erstelle Sprachlinks JPanel sprachPanel = new JPanel(new FlowLayout(FlowLayout.RIGHT)); JLabel deutschLink = new JLabel("deutsch"); JLabel englishLink = new JLabel("english"); JLabel francaisLink = new JLabel("francais"); JLabel italianoLink = new JLabel("italiano"); sprachPanel.add(deutschLink); sprachPanel.add(new JLabel("|")); sprachPanel.add(englishLink); sprachPanel.add(new JLabel("|")); sprachPanel.add(francaisLink); sprachPanel.add(new JLabel("|")); sprachPanel.add(italianoLink); window.add(sprachPanel, BorderLayout.NORTH); // Anpassung der Überschriften Font headerFont = new Font("Arial", Font.BOLD, 14); Dimension headerSize = new Dimension(700, 30); // Erstelle erste Überschrift JPanel zeilePanel1 = new JPanel(new FlowLayout(FlowLayout.LEFT)); zeilePanel1.setBackground(Color.BLUE); zeilePanel1.setPreferredSize(headerSize); JLabel ueberschrift1 = new JLabel("Start&Ziel"); ueberschrift1.setForeground(Color.WHITE); ueberschrift1.setFont(headerFont); zeilePanel1.add(ueberschrift1); tab1.add(zeilePanel1); // Erste Felder in Grid zum Auswählen der Bahnhöfe JPanel tabellePanel1 = new JPanel(new GridLayout(2, 4, 10, 10)); tabellePanel1.setBorder(BorderFactory.createEmptyBorder(10, 10, 10, 10)); JLabel labelVon = new JLabel("Von: "); tabellePanel1.add(labelVon); JLabel labelBahnhof1 = new JLabel("Bahnhof/Haltestelle"); tabellePanel1.add(labelBahnhof1); JTextField textField1 = new JTextField(10); tabellePanel1.add(textField1); JLabel labelInfo7 = new JLabel("Info"); tabellePanel1.add(labelInfo7); JLabel labelNach = new JLabel("Nach: "); tabellePanel1.add(labelNach); JLabel labelBahnhof2 = new JLabel("Bahnhof/Haltestelle"); tabellePanel1.add(labelBahnhof2); JTextField textField2 = new JTextField(10); tabellePanel1.add(textField2); JButton button = new JButton("Über"); tabellePanel1.add(button); tab1.add(tabellePanel1); // Erstelle 2. Überschrift JPanel zeilePanel2 = new JPanel(new FlowLayout(FlowLayout.LEFT)); zeilePanel2.setBackground(Color.BLUE); zeilePanel2.setPreferredSize(headerSize); JLabel ueberschrift2 = new JLabel("Reisedatum & Zeit"); ueberschrift2.setForeground(Color.WHITE); ueberschrift2.setFont(headerFont); zeilePanel2.add(ueberschrift2); tab1.add(zeilePanel2); // Erstelle Übergrid um links/rechts zu teilen JPanel tabellePanel2 = new JPanel(new GridLayout(1, 2, 10, 10)); tabellePanel2.setBorder(BorderFactory.createEmptyBorder(10, 10, 10, 10)); // Linke Seite JPanel tabellePanelLinks = new JPanel(new GridLayout(2, 3, 10, 10)); tabellePanel2.add(tabellePanelLinks); JLabel labelHinfahrt = new JLabel("Hinfahrt: "); tabellePanelLinks.add(labelHinfahrt); JLabel labelDatum = new JLabel("Datum: "); tabellePanelLinks.add(labelDatum); // Beispiel für Datum Picker - Anpassung erforderlich JTextField datePicker1 = new JTextField("Datum Picker hier"); tabellePanelLinks.add(datePicker1); JLabel labelInfo2 = new JLabel(""); // Leeres Feld tabellePanelLinks.add(labelInfo2); JLabel labelUhrzeit = new JLabel("Uhrzeit: "); tabellePanelLinks.add(labelUhrzeit); // Beispiel für Uhrzeit Picker - Anpassung erforderlich JTextField timePicker1 = new JTextField("Uhrzeit Picker hier"); tabellePanelLinks.add(timePicker1); // Rechte Seite JPanel tabellePanelRechts = new JPanel(new GridLayout(2, 3, 10, 10)); tabellePanel2.add(tabellePanelRechts); JLabel labelRueckfahrt = new JLabel("Rückfahrt: "); tabellePanelRechts.add(labelRueckfahrt); JLabel labelDatum1 = new JLabel("Datum: "); tabellePanelRechts.add(labelDatum1); // Beispiel für Datum Picker - Anpassung erforderlich JTextField datePicker2 = new JTextField("Datum Picker hier"); tabellePanelRechts.add(datePicker2); JLabel labelInfo5 = new JLabel(""); // Leeres Feld tabellePanelRechts.add(labelInfo5); JLabel labelUhrzeit1 = new JLabel("Uhrzeit: "); tabellePanelRechts.add(labelUhrzeit1); // Beispiel für Uhrzeit Picker - Anpassung erforderlich JTextField timePicker2 = new JTextField("Uhrzeit Picker hier"); tabellePanelRechts.add(timePicker2); tab1.add(tabellePanel2); // Erstelle 3. Überschrift JPanel zeilePanel3 = new JPanel(new FlowLayout(FlowLayout.LEFT)); zeilePanel3.setBackground(Color.BLUE); zeilePanel3.setPreferredSize(headerSize); JLabel ueberschrift3 = new JLabel("Angaben zur Preisberechnung"); ueberschrift3.setForeground(Color.WHITE); ueberschrift3.setFont(headerFont); zeilePanel3.add(ueberschrift3); tab1.add(zeilePanel3); // Beispiel für zusätzliche Komponenten zur Preisberechnung JPanel tabellePanel3 = new JPanel(new GridLayout(2, 4, 10, 10)); tabellePanel3.setBorder(BorderFactory.createEmptyBorder(10, 10, 10, 10)); // Erste Zeile JLabel labelReisende = new JLabel("Reisende: "); tabellePanel3.add(labelReisende); JComboBox pickerErwachsenKind = new JComboBox<>(new String[]{"Erwachsener", "Kind"}); tabellePanel3.add(pickerErwachsenKind); JComboBox pickerErmaessigung = new JComboBox<>(new String[]{"Keine", "BahnCard 25", "BahnCard 50"}); tabellePanel3.add(pickerErmaessigung); JComboBox pickerKlasse = new JComboBox<>(new String[]{"1. Klasse", "2. Klasse"}); tabellePanel3.add(pickerKlasse); // Zweite Zeile JButton buttonPersonHinzufuegen = new JButton("Person hinzufügen"); tabellePanel3.add(buttonPersonHinzufuegen); JLabel labelInfo = new JLabel("Info"); tabellePanel3.add(labelInfo); JButton buttonAuslandspreise = new JButton("Auslandspreise"); tabellePanel3.add(buttonAuslandspreise); JLabel labelInfo3 = new JLabel("Info"); tabellePanel3.add(labelInfo3); tab1.add(tabellePanel3); // Erstelle 4. Überschrift JPanel zeilePanel4 = new JPanel(new FlowLayout(FlowLayout.LEFT)); zeilePanel4.setBackground(Color.BLUE); zeilePanel4.setPreferredSize(headerSize); JLabel ueberschrift4 = new JLabel("Angaben zur Verbindung"); ueberschrift4.setForeground(Color.WHITE); ueberschrift4.setFont(headerFont); zeilePanel4.add(ueberschrift4); tab1.add(zeilePanel4); // 2x4 Grid für Angaben zur Verbindung JPanel tabellePanel4 = new JPanel(new GridLayout(2, 4, 10, 10)); tabellePanel4.setBorder(BorderFactory.createEmptyBorder(10, 10, 10, 10)); // Zeile 1 JLabel labelVerkehrsmittel = new JLabel("Verkehrsmittel: "); tabellePanel4.add(labelVerkehrsmittel); JComboBox pickerVerkehrsmittel = new JComboBox<>(new String[]{"Standardsuche", "Option 1", "Option 2"}); tabellePanel4.add(pickerVerkehrsmittel); JButton buttonErweitert = new JButton("Erweitert"); tabellePanel4.add(buttonErweitert); JLabel labelInfo8 = new JLabel("Info"); tabellePanel4.add(labelInfo8); // Zeile 2 JLabel labelLeer = new JLabel(""); // Leeres Feld tabellePanel4.add(labelLeer); JCheckBox checkBoxSchnellsteVerbindung = new JCheckBox("Schnellste Verbindung"); tabellePanel4.add(checkBoxSchnellsteVerbindung); JLabel labelInfo9 = new JLabel("Info"); tabellePanel4.add(labelInfo9); JCheckBox checkBoxFahrradmitnahme = new JCheckBox("Fahrradmitnahme"); tabellePanel4.add(checkBoxFahrradmitnahme); tab1.add(tabellePanel4); // Trennlinie JSeparator separator = new JSeparator(); tab1.add(separator); // Footer mit 3 Buttons JPanel footerPanel = new JPanel(new FlowLayout(FlowLayout.CENTER, 10, 10)); JButton buttonVerbindungSuchen = new JButton("Verbindung suchen"); JButton buttonNeueAnfrage = new JButton("Neue Anfrage"); JButton buttonMeinAnfrageprofil = new JButton("Mein Anfrageprofil"); footerPanel.add(buttonVerbindungSuchen); footerPanel.add(buttonNeueAnfrage); footerPanel.add(buttonMeinAnfrageprofil); tab1.add(footerPanel); buttonVerbindungSuchen.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { // Hier werden die Eingaben aus den Textfeldern und Kombinationsfeldern gelesen String von = textField1.getText(); String nach = textField2.getText(); String hinfahrtDatum = datePicker1.getText(); String hinfahrtZeit = timePicker1.getText(); String rueckfahrtDatum = datePicker2.getText(); String rueckfahrtZeit = timePicker2.getText(); String reisende = pickerErwachsenKind.getSelectedItem().toString(); String ermaessigung = pickerErmaessigung.getSelectedItem().toString(); String klasse = pickerKlasse.getSelectedItem().toString(); String verkehrsmittel = pickerVerkehrsmittel.getSelectedItem().toString(); boolean schnellsteVerbindung = checkBoxSchnellsteVerbindung.isSelected(); boolean fahrradmitnahme = checkBoxFahrradmitnahme.isSelected(); JOptionPane.showMessageDialog(window, "Von: " + von + "\n" + "Nach: " + nach + "\n" + "Hinfahrt - Datum: " + hinfahrtDatum + ", Uhrzeit: " + hinfahrtZeit + "\n" + "Rückfahrt - Datum: " + rueckfahrtDatum + ", Uhrzeit: " + rueckfahrtZeit + "\n" + "Reisende: " + reisende + "\n" + "Ermäßigung: " + ermaessigung+ "\n" + "Klasse: " + klasse+ "\n" + "Verkehrsmittel: " + verkehrsmittel+ "\n" + "Schnellste Verbindung: " + schnellsteVerbindung+ "\n" + "Fahrradmitnahme: " + fahrradmitnahme); } }); } }