package de.unidue.is.prog.biblio;
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;

public class BuchEingabeOtherLayout extends JPanel
                         implements ActionListener {

    protected JTextField textField1,textField2;
    protected JTextArea textArea;
    protected JButton button1, button2;
    
    // Konstruktor, wir benutzen hier BorderLayout 
    public BuchEingabeOtherLayout() {
        super(new BorderLayout());
        
        JPanel top=new JPanel();
        JPanel buttom=new JPanel();
        
        top.setLayout(new BorderLayout());
        buttom.setLayout(new BorderLayout());
        
        textField1 = new JTextField(20);
        textField2 = new JTextField(20);
        textArea=new JTextArea("");
        textArea.setEditable(false);
        textArea.setColumns(20);
		textArea.setRows(3);
		textArea.setLineWrap(true);
		textArea.setWrapStyleWord(true);
        
        button1=new JButton("Abschicken");
        button1.addActionListener(this);
        button2=new JButton("Loeschen");
        button2.addActionListener(this);
        
        textField1.setText("Buchtitel");
        textField2.setText("ISBN-No.");
        
        top.add(textField1, BorderLayout.NORTH);
        top.add(textField2, BorderLayout.SOUTH);
        buttom.add(button1, BorderLayout.NORTH);
        buttom.add(button2, BorderLayout.SOUTH);
        
        add(top, BorderLayout.NORTH);
        add(textArea, BorderLayout.CENTER);
        add(buttom, BorderLayout.SOUTH);
       
    }

    // was passiert bei einer Aktion ?
    public void actionPerformed(ActionEvent evt) {
    	if (evt.getActionCommand().equals("Abschicken")){
    		Buch buch= new Buch(textField1.getText(),textField2.getText());
    		//regal.addBuch(buch);
    		textField1.setText("");
        	textField2.setText("");
        	textArea.setText(buch.toString());
        	
        }
    	else if  (evt.getActionCommand().equals("Loeschen")){
    		textField1.setText("");
        	textField2.setText("");
        }
    }

    // erzeuge das Eingabefenster
    private static void createAndShowGUI() {
        JFrame.setDefaultLookAndFeelDecorated(true);
        JFrame frame = new JFrame("Buch eingeben:");
        frame.setDefaultCloseOperation(
                          JFrame.EXIT_ON_CLOSE);
        JComponent newContentPane = new BuchEingabeOtherLayout();
        newContentPane.setOpaque(true);
        frame.setContentPane(newContentPane);
        frame.pack();
        frame.setVisible(true);
    }

    // Hauptmethode
    public static void main(String[] args) {
                createAndShowGUI();
    }
}
