import java.awt.*;
import java.awt.event.*;
import javax.swing.*;

public class BuchLoeschen extends JDialog
{

  	private Buch buch;

  	//GUI spezifisches
  	JButton b_Ja;
  	JButton b_Nein;
  	JTextField textField;
  	JLabel label;

  	//Konstruktor
  	public BuchLoeschen(JFrame parent, Buch buch) 
  	{
    		super (parent);
    		this.buch = buch;
    
		this.setLocation(230,150);
		this.setSize(new Dimension(260, 170));
		this.setBackground(SystemColor.activeCaptionBorder);
    		this.setTitle("Löschen");
    		this.getContentPane().setLayout(null);
    		this.setResizable(false);
    		this.addWindowListener(new WindowAdapter() {public void windowClosing(WindowEvent we) {setVisible(false); } });
		this.setDefaultCloseOperation(HIDE_ON_CLOSE);

		label = new JLabel();
		this.getContentPane().add(label);
		label.setFont(new java.awt.Font("SansSerif", 1, 18));
		label.setText("Dieses Buch löschen?");
		label.setBounds(30,30,210,24);
    
		textField = new JTextField();
		textField.setBackground(SystemColor.inactiveCaptionText);
    		textField.setFont(new java.awt.Font("SansSerif", 1, 14));
    		textField.setEnabled(false);
    		textField.setText("textField");
    		textField.setBounds(30,56,195,24);

    		b_Ja = new JButton();
    		b_Ja.setText("Ja");
    		b_Ja.setBounds(40,100,80,24);
    
    		b_Nein = new JButton();
    		b_Nein.setText("Nein");
		b_Nein.setBounds(130,100,80,24);

    		this.getContentPane().add(b_Ja);
    		this.getContentPane().add(b_Nein);
    		this.getContentPane().add(textField);
    
		b_Ja.addActionListener(
			new ActionListener() {
				public void actionPerformed(ActionEvent ae) {setVisible(false); loescheBuch(); } 
			}
		);
    		b_Nein.addActionListener(
    		new ActionListener() {
    			public void actionPerformed(ActionEvent ae) {setVisible(false); } 
    		}
    		);
    
		setzeTextField();
    
  	}// Konstruktor


  	//Operation setzeTextField() zeigt an, welches Buch gelöscht werden soll
  	void setzeTextField()
  	{
    		textField.setText(buch.getName()+"  "+buch.getPreis());
  	}// setzeTextField

  	//Operation loescheBuch() wird durch Button b_Ja ausgelöst und ruft delete() in Buch auf
  	private void loescheBuch() 
  	{
    		BuecherVerwaltung.delete(buch);
  	}// loescheBuch
}// class: BuchLoeschen