Hello again,
this is a JFrame which calls a JDialog which calls a JDialog.
Using super(...) in the constructor of SecondDialog makes this dialog
unfocusable as long as FirstDialog is shown. Without super(...) one can freely
move between the dialogs.
Can somebody exlain what "super" does to produce this difference?
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
public class SuperConstructor extends JFrame {
public SuperConstructor() {
setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
setSize(300,300);
setTitle("Super constructor");
Container cp= getContentPane();
JButton b= new JButton("Show dialog");
b.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent evt) {
new FirstDialog(SuperConstructor.this);
}
});
cp.add(b, BorderLayout.SOUTH);
setVisible(true);
}
public static void main(String args[]) {
EventQueue.invokeLater(new Runnable() {
public void run() {
new SuperConstructor();
}
});
}
class FirstDialog extends JDialog {
public FirstDialog(final Frame parent) {
super(parent, "FirstDialog");
setSize(200,200);
setLocationRelativeTo(parent);
setModalityType(Dialog.ModalityType.DOCUMENT_MODAL);
JButton bNext= new JButton("Show next dialog");
bNext.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent evt) {
new SecondDialog(parent, false);
}
});
add(bNext, BorderLayout.SOUTH);
setVisible(true);
}
}
int i;
class SecondDialog extends JDialog {
public SecondDialog(Frame parent, boolean modal) {
super(parent); // Makes this dialog unfocusable as long as FirstDialog is
shown
setSize(200,200);
setLocation(300,50);
setModal(modal);
setTitle("SecondDialog "+(++i));
JButton bClose= new JButton("Close");
bClose.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent evt) {
dispose();
}
});
add(bClose, BorderLayout.SOUTH);
setVisible(true);
}
}
}