Example usage for javax.swing JOptionPane showInputDialog

List of usage examples for javax.swing JOptionPane showInputDialog

Introduction

In this page you can find the example usage for javax.swing JOptionPane showInputDialog.

Prototype

public static String showInputDialog(Object message) throws HeadlessException 

Source Link

Document

Shows a question-message dialog requesting input from the user.

Usage

From source file:Main.java

public static void main(String[] args) {
    String input = JOptionPane.showInputDialog("Enter Input:");
    System.out.println(input);
}

From source file:Main.java

public static void main(String[] args) {
    String input = JOptionPane.showInputDialog("Enter the x coordinate of the circle");
    int xc = Integer.parseInt(input);
    System.out.println(xc);/* ww  w  . j  a v  a2s  .c  o  m*/
}

From source file:Main.java

public static void main(String[] args) {
    String response = JOptionPane.showInputDialog("Please enter.");

    if (response == null) {
        System.out.println("cancelled.");
    } else {/*  w w  w  .ja va  2s. c  o m*/
        System.out.println("entered:  " + response);
    }

}

From source file:MainClass.java

public static void main(String[] args) {
    String s;// ww w. j  a  va 2 s .  c o  m
    s = JOptionPane.showInputDialog("Enter an integer:");
    int x = Integer.parseInt(s);
    System.out.println("You entered " + x + ".");
}

From source file:Main.java

public static void main(String[] args) {
    String inputValue = JOptionPane.showInputDialog("Please input a value");

    if (inputValue == null) {
        System.out.println("CANCEL");
    } else if (inputValue.equals("")) {
        System.out.println("OK");
    } else {/*from  www . j ava  2  s .  co  m*/
        JOptionPane.showMessageDialog(null, inputValue);
    }
}

From source file:MainClass.java

public static void main(String args[]) {
    String response = JOptionPane.showInputDialog("What is your first name?");
    System.out.println(response);
}

From source file:Main.java

public static void main(String[] args) throws ParseException {
    String input = JOptionPane.showInputDialog("Enter Input:");
    if (input == null) {
        System.out.println("Calcel pressed");
    } else {/*from   w  ww  .j a  va  2s .  c  om*/
        System.out.println("OK pressed");
    }

}

From source file:edu.mit.fss.tutorial.part4.ElementGUI.java

/**
 * The main method.//www .  j a va 2 s  .com
 *
 * @param args the arguments
 * @throws RTIexception the RTI exception
 */
public static void main(String[] args) throws RTIexception {
    // Configure the logger and set it to display info messages.
    BasicConfigurator.configure();
    logger.setLevel(Level.INFO);

    // Use an input dialog to request the element's name.
    String name = null;
    while (name == null || name.isEmpty()) {
        name = JOptionPane.showInputDialog("Enter element name:");
    }

    // Create a MobileElement object instance. The "final" keyword allows 
    // it to be referenced in the GUI thread below.
    final MobileElement element = new MobileElement(name, new Vector3D(0, 0, 0));

    // Create an OnlineTutorialFederate object instance. The "final" 
    // keyword allows it to be referenced in the GUI thread below.
    final OnlineTutorialFederate fed = new OnlineTutorialFederate(element);

    // Create the graphical user interface using the Event Dispatch Thread.
    try {
        SwingUtilities.invokeAndWait(new Runnable() {
            @Override
            public void run() {
                // Create a new ControlPanel object instance.
                ControlPanel controlPanel = new ControlPanel();

                // Bind it to the element above.
                controlPanel.setBoundElement(element);

                // Add the control panel as an object change listener.
                fed.addObjectChangeListener(controlPanel);

                // Create a new frame to display the panel. Add the panel
                // as the content, pack it, and make it visible.
                JFrame frame = new JFrame();
                frame.setContentPane(controlPanel);
                frame.pack();
                frame.setVisible(true);

                // Add a new WindowAdapter object instance to exit the
                // federate when the window is closing.
                frame.addWindowListener(new WindowAdapter() {
                    @Override
                    public void windowClosing(WindowEvent e) {
                        fed.exit();
                    }
                });
            }
        });
    } catch (InvocationTargetException | InterruptedException e) {
        logger.error(e);
    }

    // Execute the federate.
    fed.execute(0, Long.MAX_VALUE, 1000);
}

From source file:info.sugoiapps.xoclient.XOverClient.java

/**
 * @param args the command line arguments
 *//*from   w w  w.j a v  a2s.c o  m*/

public static void main(String[] args) {
    // System.getProperty("user.dir")); gets working directory in the form: C:\Users\Munyosz\etc...\
    final String SEPARATOR = " - ";
    XOverClient client = new XOverClient();
    String ladrs = getLocalAddress();
    if (client.validAddress(ladrs)) {
        MACHINE_IP = ladrs;

    } else {
        JOptionPane.showMessageDialog(null,
                "Your machine's internal IP couldn't be retreived, program will exit.");
        System.exit(0);
    }

    REMOTE_IP = null;
    if (!new File(CONFIG_FILENAME).exists()) {
        while (REMOTE_IP == null || REMOTE_IP.equalsIgnoreCase(""))
            REMOTE_IP = JOptionPane
                    .showInputDialog("Enter the internal IP of the machine you want to connect to.\n"
                            + "Must be in the format 192.168.xxx.xxx");
        String machinename = JOptionPane.showInputDialog("Now enter a name for the machine with internal IP "
                + "\"" + REMOTE_IP + "\"" + "\n"
                + "You will be able to select this machine from a list the next time you start the program.");
        new ListWriter(CONFIG_FILENAME).writeList(machinename + SEPARATOR + REMOTE_IP, APPEND);
    } else {
        MachineChooser mc = new MachineChooser(CONFIG_FILENAME, SEPARATOR, client);
        mc.setVisible(true);
        mc.setAddressInfo(MACHINE_IP);

        while (REMOTE_IP == null) {
            try {
                Thread.sleep(1000);
            } catch (InterruptedException ex) {
                JOptionPane.showMessageDialog(null, ex.getMessage());
                Logger.getLogger(XOverClient.class.getName()).log(Level.SEVERE, null, ex);
            }
        }
    }
    new XOverClientGUI(REMOTE_IP, MACHINE_IP).setVisible(true);
    new FileServer().execute();
}

From source file:driver.ieSystem2.java

public static void main(String[] args) throws SQLException {

    Scanner sc = new Scanner(System.in);
    boolean login = false;
    int check = 0;
    int id = 0;/*  w w w. j a v  a 2  s . co m*/
    String user = "";
    String pass = "";
    Person person = null;
    Date day = null;

    JOptionPane.showMessageDialog(null, "WELCOME TO SYSTEM", "Starting Project",
            JOptionPane.INFORMATION_MESSAGE);
    do {
        System.out.println("What do you want?");
        System.out.println("press 1 : Login");
        System.out.println("press 2 : Create New User");
        System.out.println("Press 3 : Exit ");
        System.out.println("");
        do {
            try {
                System.out.print("Enter: ");
                check = sc.nextInt();
            } catch (InputMismatchException e) {
                JOptionPane.showMessageDialog(null, "Invalid Input", "Message", JOptionPane.WARNING_MESSAGE);
                sc.next();
            }
        } while (check <= 1 && check >= 3);

        // EXIT 
        if (check == 3) {
            System.out.println("Close Application");
            System.exit(0);
        }
        // CREATE USER
        if (check == 2) {
            System.out.println("-----------------------------------------");
            System.out.println("Create New User");
            System.out.println("-----------------------------------------");
            System.out.print("Account ID: ");
            id = sc.nextInt();
            System.out.print("Username: ");
            user = sc.next();
            System.out.print("Password: ");
            pass = sc.next();
            try {
                Person.createUser(id, user, pass, 0, 0, 0, 0, 0);
                System.out.println("-----------------------------------------");
                System.out.println("Create Complete");
                System.out.println("-----------------------------------------");
            } catch (Exception e) {
                System.out.println("-----------------------------------------");
                System.out.println("Error, Try again");
                System.out.println("-----------------------------------------");
            }
        } else if (check == 1) {
            // LOGIN
            do {
                System.out.println("-----------------------------------------");
                System.out.println("LOGIN ");
                System.out.print("Username: ");
                user = sc.next();
                System.out.print("Password: ");
                pass = sc.next();
                if (Person.checkUser(user, pass)) {
                    System.out.println("-----------------------------------------");
                    System.out.println("Login Complete");
                } else {
                    System.out.println("-----------------------------------------");
                    System.out.println("Invalid Username / Password");
                }
            } while (!Person.checkUser(user, pass));
        }
    } while (check != 1);
    login = true;

    person = new Person(user);
    do {
        System.out.println("-----------------------------------------");
        System.out.println("Hi " + person.getPerName());
        System.out.println("Press 1 : Add Income");
        System.out.println("Press 2 : Add Expense");
        System.out.println("Press 3 : Add Save");
        System.out.println("Press 4 : History");
        System.out.println("Press 5 : Search");
        System.out.println("Press 6 : Analytics");
        System.out.println("Press 7 : Total");
        System.out.println("Press 8 : All Summary");
        System.out.println("Press 9 : Sign Out");
        do {
            try {
                System.out.print("Enter : ");
                check = sc.nextInt();
            } catch (InputMismatchException e) {
                System.out.println("Invalid Input");
                sc.next();
            }
        } while (check <= 1 && check >= 5);
        // Add Income
        if (check == 1) {
            double Income;
            String catalog = "";
            double IncomeTotal = 0;
            catalog = JOptionPane.showInputDialog("What is your income : ");
            Income = Integer.parseInt(JOptionPane.showInputDialog("How much is it   "));

            person.addIncome(person.getPerId(), day, catalog, Income);
            person.update();
        } //Add Expense
        else if (check == 2) {
            double Expense;
            String catalog = "";
            catalog = JOptionPane.showInputDialog("What is your expense :");
            Expense = Integer.parseInt(JOptionPane.showInputDialog("How much is it   "));
            person.addExpense(person.getPerId(), day, catalog, Expense);
            person.update();
        } //Add Save 
        else if (check == 3) {
            double Saving;
            double SavingTotal = 0;
            String catalog = "";

            Saving = Integer.parseInt(JOptionPane.showInputDialog("How much is it "));
            SavingTotal += Saving;
            person.addSave(person.getPerId(), day, catalog, Saving);
            person.update();
        } //History
        else if (check == 4) {
            String x;
            do {
                System.out.println("-----------------------------------------");
                System.out.println("YOUR HISTORY");
                System.out.println("Date                Type           Amount");
                System.out.println("-----------------------------------------");
                List<History> history = person.getHistory();
                if (history != null) {
                    int count = 1;
                    for (History h : history) {
                        if (count++ <= 1) {
                            System.out.println(h.getHistoryDateTime() + "   " + h.getHistoryDescription()
                                    + "           " + h.getAmount());
                        } else {
                            System.out.println(h.getHistoryDateTime() + "   " + h.getHistoryDescription()
                                    + "           " + h.getAmount());
                        }
                    }
                }
                System.out.println("-----------------------------------------");
                System.out.print("Back to menu (0 or back) : ");
                x = sc.next();
            } while (!x.equalsIgnoreCase("back") && !x.equalsIgnoreCase("0"));
        } //Searh
        else if (check == 5) {
            try {
                Connection conn = ConnectionDB.getConnection();
                long a = person.getPerId();
                String NAME = "Salary";
                PreparedStatement ps = conn.prepareStatement(
                        "SELECT * FROM  INCOME WHERE PERID = " + a + "  and CATALOG LIKE '%" + NAME + "%' ");
                ResultSet rec = ps.executeQuery();

                while ((rec != null) && (rec.next())) {
                    System.out.print(rec.getDate("Days"));
                    System.out.print(" - ");
                    System.out.print(rec.getString("CATALOG"));
                    System.out.print(" - ");
                    System.out.print(rec.getDouble("AMOUNT"));
                    System.out.print(" - ");
                }
                ps.close();
                conn.close();
            } catch (Exception e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            }

        } //Analy 
        else if (check == 6) {
            String x;
            do {
                DecimalFormat df = new DecimalFormat("##.##");
                double in = person.getIncome();
                double ex = person.getExpense();
                double sum = person.getSumin_ex();
                System.out.println("-----------------------------------------");
                System.out.println("Income : " + df.format((in / sum) * 100) + "%");
                System.out.println("Expense : " + df.format((ex / sum) * 100) + "%");
                System.out.println("\n\n");
                System.out.print("Back to menu (0 or back) : ");
                x = sc.next();
            } while (!x.equalsIgnoreCase("back") && !x.equalsIgnoreCase("0"));
        } //TOTAL
        else if (check == 7) {
            String x;
            do {
                System.out.println("-----------------------------------------");
                System.out.println("TOTALSAVE             TOTAL");
                System.out.println(
                        person.getTotalSave() + " Baht" + "             " + person.getTotal() + " Baht");
                System.out.println("\n\n");
                System.out.print("Back to menu (0 or back) : ");
                x = sc.next();
            } while (!x.equalsIgnoreCase("back") && !x.equalsIgnoreCase("0"));
        } //ALL Summy
        else if (check == 8) {
            String x;
            do {
                DecimalFormat df = new DecimalFormat("##.##");
                double in = person.getIncome();
                double ex = person.getExpense();
                double sum = person.getSumin_ex();
                double a = ((in / sum) * 100);
                double b = ((ex / sum) * 100);
                System.out.println("-----------------------------------------");
                System.out.println("ALL SUMMARY");
                System.out.println("Account: " + person.getPerName());
                System.out.println("");
                System.out.println("Total Save ------------- Total");
                System.out
                        .println(person.getTotalSave() + " Baht               " + person.getTotal() + " Baht");
                System.out.println("");

                System.out.println("INCOME --------------- EXPENSE");
                System.out.println(df.format(a) + "%" + "                  " + df.format(b) + "%");

                System.out.println("-----------------------------------------");
                System.out.println("\n\n");
                System.out.print("Back to menu (0 or back) : ");
                x = sc.next();
            } while (!x.equalsIgnoreCase("back") && !x.equalsIgnoreCase("0"));
        } //LOG OUT 
        else {
            System.out.println("See ya.\n");
            login = false;
            break;
        }
    } while (true);
}