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

public class BuchEingabe extends JPanel
                         implements ActionListener {

    protected JTextField textField1,textField2;
    protected JTextArea textArea;
    protected JButton button1, button2;
    
    // Konstruktor, wir benutzen hier GridBagLayout
    public BuchEingabe() {
        super(new GridBagLayout());
        GridBagConstraints c = new GridBagConstraints();
        c.gridwidth = GridBagConstraints.REMAINDER;
        c.fill = GridBagConstraints.HORIZONTAL;
        
        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.");
        
        add(textField1, c);
        add(textField2, c);
        add(textArea, c);
        add(button1, c);
        add(button2, c);
        
        
        c.fill = GridBagConstraints.BOTH;
    }

    // was passiert bei einer Aktion ?
    public void actionPerformed(ActionEvent evt) {
    	if (evt.getActionCommand().equals("Abschicken")){
    		Buch buch= new Buch(textField1.getText(),textField2.getText());
    		textArea.setText(buch.toString());
        }
 		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 BuchEingabe();
        newContentPane.setOpaque(true);
        frame.setContentPane(newContentPane);
        frame.pack();
        frame.setVisible(true);
    }

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