Rated 3 out of 5 stars

U2

import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import java.io.*;

public class Urlaub extends JFrame implements ActionListener{

Buchen zArray[] = new Buchen[6];

private JLabel ziel = new JLabel("Reiseziel:");
private JLabel zeit = new JLabel("Zeitraum:");
private JLabel kategorie = new JLabel("Kategorie:");
private JLabel preis = new JLabel("Preis:");

private JButton element0 = new JButton("Daten zeigen");
private JButton element1 = new JButton("Abbrechen");
private JButton element2 = new JButton("Buchen");

//Textfeld:
private JTextField textfeld0 = new JTextField(25);
private JTextField textfeld1 = new JTextField(15);
private JTextField textfeld2 = new JTextField(15);
private JTextField textfeld3 = new JTextField("0.0",15);

//Array für Liste:
private static final String[] ORT = {"vergleich", "", "", "", "","","","","",""};
private static final String[] ZEIT = {"", "", "", "", "","","","","",""};
private static final String[] KATEGORIE = {"", "", "", "", "","","","","",""};
private static final String[] PREIS = {"", "", "", "", "","","","","",""};
private static final String[] BILD = {"G:\\vorgabe\\bild1.jpg", "G:\\vorgabe\\", "G:\\vorgabe\\", "G:\\vorgabe\\", "G:\\vorgabe\\","G:\\vorgabe\\","G:\\vorgabe\\","G:\\vorgabe\\","G:\\vorgabe\\","G:\\vorgabe\\"};

//Bild:
private String dateiname;
private String dateinamewahl;
private Image ibild;

private MeinJPanel panel_bild = new MeinJPanel(320,240,ibild);

public Urlaub (String titel) {
super(titel);

//zArray

//Container:
Container cp = getContentPane();

//Layout:
cp.setLayout(new FlowLayout(FlowLayout.LEFT));

//Panel:
JPanel panel_ueber = new JPanel();

JPanel panel_mitte = new JPanel();
JPanel panel_mitte_untereinander = new JPanel();

//Textfeld nicht schreibbar:
textfeld1.setEnabled(false);
textfeld2.setEnabled(false);
textfeld3.setEnabled(false);

//Bild:
dateiname = "G:\\vorgabe\\start.jpg";

Toolkit tk = Toolkit.getDefaultToolkit();
ibild = tk.getImage(dateiname);
panel_bild = new MeinJPanel(240, 320, ibild);

//Layout Überschrift:
panel_ueber.setLayout(new FlowLayout(FlowLayout.LEFT,0,0));

//Layout m:
panel_mitte.setLayout(new FlowLayout(FlowLayout.LEFT,0,10));
panel_mitte_untereinander.setLayout(new GridLayout(4,1,0,10));

//Layout Bild:
panel_bild.setLayout(new FlowLayout(FlowLayout.RIGHT,0,0));

//Panel Überschrift:
cp.add(panel_ueber);
panel_ueber.add(ziel);
panel_ueber.add(textfeld0);
panel_ueber.add(element0);

//Panel m:
cp.add(panel_mitte_untereinander);
panel_mitte_untereinander.add(zeit);
panel_mitte_untereinander.add(textfeld1);
panel_mitte_untereinander.add(kategorie);
panel_mitte_untereinander.add(textfeld2);
panel_mitte_untereinander.add(preis);
panel_mitte_untereinander.add(textfeld3);
panel_mitte_untereinander.add(element1);
panel_mitte_untereinander.add(element2);

//Vereinigung von Panel m:
panel_mitte.add(panel_mitte_untereinander);

//Panel mitte:
cp.add(panel_mitte);

//Panel Bild:
cp.add(panel_bild);

element0.addActionListener(this);
element1.addActionListener(this);
element2.addActionListener(this);

setDefaultCloseOperation(EXIT_ON_CLOSE);
setLocation(200,100);
setSize(700,320);
setVisible(true);
setResizable(true);
}

public void actionPerformed(ActionEvent e){
//Button Beenden:
if (e.getActionCommand().equals("Abbrechen"))
System.exit(0);

//Button:
if (e.getActionCommand().equals("Daten zeigen"))
{
boolean gefunden = false;
for (int i = 0; i < ORT.length; i++)
{
if (textfeld0.getText().equals(ORT[i]))
{
textfeld1.setText(ZEIT[i]);
textfeld2.setText(KATEGORIE[i]);
textfeld3.setText(PREIS[i]);
dateinamewahl = (BILD[i]);
//Image
Toolkit tk = Toolkit.getDefaultToolkit();
ibild = tk.getImage(dateinamewahl);

panel_bild.setAktBild(ibild);
repaint();
gefunden = true;
}
}
if (!gefunden)
new Fehlermeldung("Fehler!");
}
if (e.getActionCommand().equals("Buchen"))
{
String ergebnis1 = textfeld0.getText();
System.out.println("Gebucht: " + ergebnis1);


//Einlesen:
try {
ObjectOutputStream out;
out = new ObjectOutputStream(new FileOutputStream( "buchung.bin" ));

for(Buchen xy : zArray)
{
System.out.println(xy);
out.writeObject(xy);
}
out.flush();
out.close();
} catch( IOException ex ) {
System.out.println( ex );
}

//Auslesen
try {
FileInputStream fs = new FileInputStream("buchung.bin");
ObjectInputStream is = new ObjectInputStream(fs);
Buchen gelesen = (Buchen)is.readObject();
String [][]x = new String [6][6];
x[0][0] = gelesen.getOrt();
x[0][0] = gelesen.getZeit();
x[0][0] = gelesen.getBeschreibung();
x[0][0] = ""+gelesen.getPreis();
System.out.println(gelesen.toString());
is.close();

new Buchungen(x);
} catch (ClassNotFoundException ei) {
System.err.println(e.toString());
} catch (IOException ei) {
System.err.println(e.toString());
}

}
}

public static void main(String[] args){
Urlaub fenster = new Urlaub(null);
}
}