Answers for "how to make a popup in java"

0

Jframe popup window

package experiments;

import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JOptionPane;

public class CreateDialogFromOptionPane {

    public static void main(final String[] args) {
        final JFrame parent = new JFrame();
        JButton button = new JButton();

        button.setText("Click me to show dialog!");
        parent.add(button);
        parent.pack();
        parent.setVisible(true);

        button.addActionListener(new java.awt.event.ActionListener() {
            @Override
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                String name = JOptionPane.showInputDialog(parent,
                        "What is your name?", null);
            }
        });
    }
}
Posted by: Guest on January-15-2020
0

Java make a popup

import java.awt.Dimension;
import javax.swing.JFrame;
import javax.swing.SwingUtilities;

public class JFrameSize
{

  public static void main(String[] args)
  {
    // schedule this for the event dispatch thread (edt)
    SwingUtilities.invokeLater(new Runnable()
    {
      public void run()
      {
        displayJFrame();
      }
    });
  }

  static void displayJFrame()
  {
    // create our jframe as usual
    JFrame jframe = new JFrame("JFrame Size Example");
    jframe.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

    // set the jframe size and location, and make it visible
    jframe.setPreferredSize(new Dimension(400, 300));
    jframe.pack();
    jframe.setLocationRelativeTo(null);
    jframe.setVisible(true);
  }

}
Posted by: Guest on August-04-2021

Code answers related to "how to make a popup in java"

Code answers related to "Java"

Java Answers by Framework

Browse Popular Code Answers by Language