Dialogbox
Dialogbox
--> 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)
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
public class MyFrame implements ActionListener{
JFrame f1;
JButton b1;
MyFrame() {
f1 = new JFrame();
f1.setSize(500, 500);
f1.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
f1.setLayout(new FlowLayout());
------------------------------------------------------------------
//confirm dialog
int choice= JOptionPane.showConfirmDialog(null,"Are you sure??");
if(choice==0)
JOptionPane.showMessageDialog(null,"You chose Yes");
else if(choice==1)
JOptionPane.showMessageDialog(null,"You chose No");
else if(choice==2)
JOptionPane.showMessageDialog(null,"You chose Cancel");