Skip to content Skip to sidebar Skip to footer

Java Open a Jdialog Again Until Condition Is Met

Java Swing | JDialog with examples

JDialog is a office Coffee swing parcel. The main purpose of the dialog is to add components to it. JDialog can be customized according to user need .
Constructor of the class are:

  1. JDialog() : creates an empty dialog without whatsoever championship or any specified owner
  2. JDialog(Frame o) :creates an empty dialog with a specified frame every bit its owner
  3. JDialog(Frame o, String s) : creates an empty dialog with a specified frame as its owner
    and a specified title
  4. JDialog(Window o) : creates an empty dialog with a specified window every bit its possessor
  5. JDialog(Window o, String t) : creates an empty dialog with a specified window as its owner and specified title.
  6. JDialog(Dialog o) :creates an empty dialog with a specified dialog as its owner
  7. JDialog(Dialog o, Cord southward) : creates an empty dialog with a specified dialog as its owner and specified title.

Commonly used methods

  1. setLayout(LayoutManager m) : sets the layout of the dialog to specified layout manager
  2. setJMenuBar(JMenuBar m) : sets the menubar of the dialog to specified menubar
  3. add(Component c): adds component to the dialog
  4. isVisible(boolean b): sets the visibility of the dialog, if value of the boolean is true then visible else invisible
  5. update(Graphics g) : calls the paint(g) part
  6. remove(Component c) : removes the component c
  7. getGraphics() : returns the graphics context of the component.
  8. getLayeredPane() : returns the layered pane for the dialog
  9. setContentPane(Container c) :sets the content pane for the dialog
  10. setLayeredPane(JLayeredPane l) : ready the layered pane for the dialog
  11. setRootPane(JRootPane r) : sets the rootPane for the dialog
  12. getJMenuBar() : returns the menubar of the component
  13. setTransferHandler(TransferHandler n) : Sets the transferHandler property, which is a machinery to support transfer of data into this component.
  14. setRootPaneCheckingEnabled(boolean enabled) : Sets whether calls to add together and setLayout are forwarded to the contentPane.
  15. setRootPane(JRootPane root) :Sets the rootPane property of the dialog.
  16. setGlassPane(Component glass) : Sets the glassPane property of the dialog.
  17. repaint(long time, int x, int y, int width, int height): Repaints the specified rectangle of this component within fourth dimension milliseconds.
  18. remove(Component c): Removes the specified component from the dialog.
  19. isRootPaneCheckingEnabled() : Returns whether calls to add and setLayout are forwarded to the contentPane or non .
  20. getTransferHandler() : returns the transferHandler belongings.
  21. getRootPane() : Returns the rootPane object for this dialog.
  22. getGlassPane() : Returns the glassPane object for this dialog.
  23. createRootPane() : Chosen by the constructor methods to create the default rootPane.
  24. addImpl(Component co, Object c, int i) : Adds the specified child Component to the dialog.

The following programs volition illustrate the use of JDialog
one .Programme to create a simple JDialog

Java

import java.awt.event.*;

import coffee.awt.*;

import javax.swing.*;

class solve extends JFrame implements ActionListener {

static JFrame f;

public static void chief(String[] args)

{

f = new JFrame( "frame" );

solve south = new solve();

JPanel p = new JPanel();

JButton b = new JButton( "click" );

b.addActionListener(south);

p.add(b);

f.add(p);

f.setSize( 400 , 400 );

f.bear witness();

}

public void actionPerformed(ActionEvent east)

{

Cord s = e.getActionCommand();

if (southward.equals( "click" )) {

JDialog d = new JDialog(f, "dialog Box" );

JLabel l = new JLabel( "this is a dialog box" );

d.add together(l);

d.setSize( 100 , 100 );

d.setVisible( true );

}

}

}

Output:

2. Program to create a dialog within a dialog

Java

import coffee.awt.event.*;

import java.awt.*;

import javax.swing.*;

class solve extends JFrame implements ActionListener {

static JFrame f;

static JDialog d, d1;

public static void chief(String[] args)

{

f = new JFrame( "frame" );

solve south = new solve();

JPanel p = new JPanel();

JButton b = new JButton( "click" );

b.addActionListener(s);

p.add(b);

f.add together(p);

f.setSize( 400 , 400 );

f.show();

}

public void actionPerformed(ActionEvent e)

{

String s = east.getActionCommand();

if (s.equals( "click" )) {

d = new JDialog(f, "dialog Box" );

JLabel l = new JLabel( "this is first dialog box" );

JButton b = new JButton( "click me" );

b.addActionListener( this );

JPanel p = new JPanel();

p.add(b);

p.add(l);

d.add together(p);

d.setSize( 200 , 200 );

d.setVisible( true );

}

else {

d1 = new JDialog(d, "dialog Box" );

JLabel l = new JLabel( "this is second dialog box" );

d1.add together(fifty);

d1.setSize( 200 , 200 );

d1.setLocation( 200 , 200 );

d1.setVisible( truthful );

}

}

}

Output :

Note : The in a higher place programs might non run in an online compiler delight use an offline IDE


messickblarand.blogspot.com

Source: https://www.geeksforgeeks.org/java-swing-jdialog-examples/

Post a Comment for "Java Open a Jdialog Again Until Condition Is Met"