Dialog Box
--> Dialog box is a window like frame, however, it contains only close (x) button
i.e it does not have maximize and minimize buttons.
--> A dialog box can be built-in/library dialog box(message dialog, confirm dialog,
input dialog, file dialog, print dialog, font dialog, color dialog) or it can be
user defined dialog box.
--> For creating user defined dialog box(custom dialog box) we use JDialog class.
Its constructors are:
a. JDialog(JFrame parent)
b. JDialog(JFrame parent, boolean isModal)
c. JDialog(JFrame parent, String title, boolean isModal)
Note: A dialog box can be modal or non-modal.
1. Modal Dialog Box: A dialog box which does not allow to access the features of
its parent application until it is closed is called modal dialog box.
2. Non-Modal Dialog Box: A dialog box which allows to access the features of its
parent application before it is closed is called non-modal dialog box.
import [Link].*;
import [Link].*;
import [Link].*;
public class MyFrame implements ActionListener{
JFrame f1;
JButton b1;
MyFrame() {
f1 = new JFrame();
[Link](500, 500);
[Link](JFrame.EXIT_ON_CLOSE);
[Link](new FlowLayout());
b1=new JButton("About Us");
[Link](b1);
[Link](this);
[Link](true);
public static void main(String[] args) {
MyFrame ob = new MyFrame();
}
public void actionPerformed(ActionEvent e){
JDialog d1=new JDialog(f1,true);
[Link](300,300);
[Link](new FlowLayout());
JLabel L1=new JLabel("Contact Us At: abc@[Link]");
[Link](L1);
[Link](true);
}
}
------------------------------------------------------------------
Using message, input and confirm dialog
--------------------------------------
import [Link];
public class TestDialog {
public static void main(String[] args) {
//input dialog
int a=[Link]([Link]("Enter a number"));
if(a%2==0)
//message dialog
[Link](null,"Even");
else
//message dialog
[Link](null,"Odd");
//confirm dialog
int choice= [Link](null,"Are you sure??");
if(choice==0)
[Link](null,"You chose Yes");
else if(choice==1)
[Link](null,"You chose No");
else if(choice==2)
[Link](null,"You chose Cancel");