Oberklasse:
Unterklasse:
Wir rufen in einer anderen Klasse w2 = new Warning2(this, "Achtung", "Wollen Sie wirklich alle Gerichte löschen", "Okay", "Nein"); auf.
Das "Nein" erscheint komischerweise nicht auf dem Button "southBtn" in der Klasse Warning2. Kann jemand erklären warum?
MfG Marco
Code:
import java.awt.*;
import java.awt.event.*;
public class Warning extends Dialog implements ActionListener
{
private Panel centerPnl;
protected static Panel southPnl;
private Label centerLbl;
private Button southBtn;
private String command;
private String text;
private String buttonText;
Warning(Dialog d, String title, String text, String buttonText)
{
super(d, title, true);
this.text = text;
this.buttonText = buttonText;
setForeground(Color.black);
setBackground(Color.gray);
setBounds(260, 230, 300, 150);
initLayout();
addWindowListener(new MyListener());
pack();
setResizable(false);
setVisible(true);
}
protected void initLayout()
{
setLayout(new BorderLayout());
//center
centerPnl = new Panel(new FlowLayout());
centerLbl = new Label(text);
centerPnl.add(centerLbl);
add("Center", centerPnl);
//south
southPnl = new Panel(new FlowLayout());
southBtn = new Button(buttonText);
southBtn.setBackground(Color.gray);
southBtn.addActionListener(this);
southPnl.add(southBtn);
add("South", southPnl);
}
// inner class
class MyListener extends WindowAdapter
{
public void windowClosing( WindowEvent e) //window closing
{
exitPopUp( );
}
}
//ActionPerformed
public void actionPerformed(ActionEvent e)
{
command = e.getActionCommand();
if (command.equals(buttonText))
{
exitPopUp();
}
}
// closing the application
void exitPopUp()
{
dispose();
}
}
Unterklasse:
Code:
import java.awt.*;
import java.awt.event.*;
public class Warning2 extends Warning
{
private String buttonText2;
private Button southBtn;
private Panel southPnl;
private String command;
Warning2(Dialog d, String title, String text, String buttonText, String buttonText2)
{
super(d, title, text, buttonText);
this.buttonText2 = buttonText2;
initLayout();
}
public void initLayout()
{
super.initLayout();
southBtn = new Button(buttonText2);
southBtn.setBackground(Color.gray);
southBtn.addActionListener(this);
Warning.southPnl.add(southBtn);
}
}
Wir rufen in einer anderen Klasse w2 = new Warning2(this, "Achtung", "Wollen Sie wirklich alle Gerichte löschen", "Okay", "Nein"); auf.
Das "Nein" erscheint komischerweise nicht auf dem Button "southBtn" in der Klasse Warning2. Kann jemand erklären warum?
MfG Marco