How dialog boxes can be created in java by using JDialog class? Explain with java code.
Creating Dialog Boxes with JDialog
With JOptionPane class, it is easy to create dialog boxes, but to create custom dialog boxes we need to use JDialog class as below. JDialog class is foundation for all dialog boxes customized in swing class. We can create dialog boxes by using any one of following constructor defined in JDialog
JDialog()
JDialog(parent_frame)
JDialog(parent_frame, modal)
JDialog(parent_frame, title)
JDialog(parent_frame, title, modal)
Example
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
class DialogDemo extends JFrame
JLabel 1;
JTextField f;
Dialog d;
DialogDemo()
{
setSize (400, 300);
setDefaultLookAndFeelDecorated (true); setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
setVisible(true);
setTitle ("Paraent Frame");
1-new JLabel("Email");
fanew JTextField(15);
d=new JDialog(this,"Dialog Example", true);
d.setLayout (new FlowLayout (FlowLayout. CENTER, 20,20)); d.setSize(300,200);
d.setLocation (50,50);
d.setModal (true);
d.add(1);
d.add(f);
d.setVisible (true);
}
public static void main (String args[])
{
DialogDemo frame=new DialogDemo();
}
Comments
Post a Comment