Swing Dialog Quiz - Java Swing

Java examples for Swing:JDialog

Introduction

Create an input dialog box.

Read string value.

Set the title of the frame by using that value.

Demo Code

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

public class Main extends JFrame {
  public Main() {
    super("Title Frame");

    setSize(300, 200);//from  w  w  w  .  j av  a 2 s.  co m
    setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    setVisible(true);
    String response = JOptionPane.showInputDialog(null,
        "Enter a Title for the Frame:");
    setTitle(response);
  }

  public static void main(String[] arguments) {
    JFrame frame = new Main();
  }
}

Related Tutorials