Test.java Source code

Java tutorial

Introduction

Here is the source code for Test.java

Source

import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;

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

public class Test extends JFrame {
    public Test() {
        setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        getContentPane().add(new JLabel("Placeholder label"));
        pack();
        setSize(200, 200);
        setVisible(true);

        int replaced = JOptionPane.showConfirmDialog(this, "Replace existing selection?");

        String result = "?";
        switch (replaced) {
        case JOptionPane.CANCEL_OPTION:
            result = "Canceled";
            break;
        case JOptionPane.CLOSED_OPTION:
            result = "Closed";
            break;
        case JOptionPane.NO_OPTION:
            result = "No";
            break;
        case JOptionPane.YES_OPTION:
            result = "Yes";
            break;
        default:
            ;
        }
        System.out.println("Replace? " + result);
    }

    public static void main(String[] args) {
        new Test();
    }
}