Advertisement
RupeshAcharya60

Dialog Box in Java

Mar 25th, 2023
683
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.81 KB | Source Code | 0 0
  1.  
  2. import javax.swing.*;
  3. import java.awt.event.ActionEvent;
  4. import java.awt.event.ActionListener;
  5.  
  6.  
  7. class NewFrame implements ActionListener {
  8.     JFrame frame;
  9.     JButton b;
  10.     JDialog dialog;
  11.     NewFrame(){
  12.         frame = new JFrame();
  13.         b = new JButton("Show Dialog");
  14.         dialog = new JDialog(frame, "My Dialog", false);
  15.         JLabel label = new JLabel("Hello, world!");
  16.  
  17.         b.addActionListener(this);
  18.         dialog.add(label);
  19.         frame.add(b);
  20.  
  21.         frame.setSize(400,400);
  22.         frame.setVisible(true);
  23.  
  24.  
  25.  
  26.  
  27.  
  28.  
  29.     }
  30.  
  31.  
  32.     public void actionPerformed(ActionEvent event){
  33.         dialog.setVisible(true);
  34.         dialog.setSize(600,600);
  35.     }
  36.  
  37.  
  38. }
  39.  
  40.  
  41. public class GUI {
  42.     public static void main(String[] args) {
  43.         new NewFrame();
  44.  
  45.  
  46.  
  47.  
  48.     }
  49. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement