








Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
Prepare for your exams
Study with the several resources on Docsity
Earn points to download
Earn points by helping other students or get them with a premium plan
Its my self made tutorial pdf for students help
Typology: Lecture notes
1 / 14
This page cannot be seen from the preview
Don't miss anything!









JDialog Declaration:
CLASS HIERARCHY: CONSTRUCTORS:
boolean modal, GraphicsConfiguration gc)
protected void dialogInit ()^ Called by the constructors
enabled)
int height)
Examples: Example1:Write a program in Java to create simple JDialog Box. Program
Output
// create a label JLabel l = new JLabel("this is first dialog box"); // create a button JButton b = new JButton("click me"); // add Action Listener b.addActionListener(this); // create a panel JPanel p = new JPanel(); p.add(b); p.add(l); // add panel to dialog d.add(p); // setsize of dialog d.setSize(200, 200); // set visibility of dialog d.setVisible(true); } else { // create a dialog Box d1 = new JDialog(d, "dialog Box"); // create a label JLabel l = new JLabel("this is second dialog box"); d1.add(l); // setsize of dialog d1.setSize(200, 200); // set location of dialog d1.setLocation(200, 200); // set visibility of dialog d1.setVisible(true); } } } Output
Example3:Write a program which can add components to Jdialog box. Program
Example4:Write a program to create a dynamic fit table with Edit Text Event in Jdialog box. Code
Output
cancelButton }); JDialog dialog = new JDialog(frame, "Click a button", false); cancelButton.addActionListener(e -> dialog.setVisible(false)); dialog.setContentPane(optionPane); dialog.setDefaultCloseOperation(JDialog.DO_NOTHING_ON_CLOSE); dialog.setLocation(100, 100); dialog.pack(); dialog.setVisible(true); } public static void main(String[] args) { JFrame frame = new JFrame(); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); frame.setContentPane(new Main(frame)); frame.pack(); frame.setVisible(true); } } Output Exercise Questions