i have a Jframe (Mainz),
it have a button (showDialog),
when user click the button,
jdialog (Dialogz) will show,
that jdialog have a button
- how to close jdialog from that button (inside jdialog)?
- can i change the modal of dialog after i create instance of it?
i need to block the owner of that jdialog
heres i try ...
import java.awt.FlowLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.JButton;
import javax.swing.JDialog;
import javax.swing.JFrame;
public class Mainz extends JFrame implements ActionListener{
JButton showDialog = new JButton("show dialog");
public Mainz() {
setLayout(new FlowLayout());
showDialog.addActionListener(this);
add(showDialog);
setVisible(true);
}
@Override
public void actionPerformed(ActionEvent e) {
new Dialogz(this, true);
}
public static void main(String[]args){
new Mainz();
}
}
class Dialogz extends JDialog{
JButton close = new JButton("close");
public Dialogz(JFrame owner,boolean modal) {
super(owner, modal);
System.out.println(this.getModalityType());
add(close);
setLocationRelativeTo(owner);
setVisible(true);
close.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent ae){
closez();
}
});
}
void closez(){
setModal(false);
this.dispose();
System.out.println("Method Done");
}
}
thanks a lot for any kind of help