List of usage examples for javax.swing JOptionPane showConfirmDialog
public static int showConfirmDialog(Component parentComponent, Object message) throws HeadlessException
From source file:Main.java
public static void main(String args[]) { int choose = JOptionPane.showConfirmDialog(null, "Open Dialog ??"); if (choose == JOptionPane.YES_OPTION) { JOptionPane.showMessageDialog(null, "You Clicked Yes !!"); } else if (choose == JOptionPane.NO_OPTION) { JOptionPane.showMessageDialog(null, "You Clicked NO"); }/*from w ww . j ava 2 s .c o m*/ }
From source file:Main.java
public static void main(String[] argv) throws Exception { int response = JOptionPane.showConfirmDialog(null, "Should i delete all files?"); }
From source file:ConfirmPopUps.java
public static void main(String[] a) { JFrame frame = new JFrame(); int result = JOptionPane.showConfirmDialog(frame, "Continue printing?"); // JOptionPane.showInternalConfirmDialog(desktop, "Continue printing?"); System.out.println(JOptionPane.CANCEL_OPTION == result); }
From source file:Main.java
public static void main(String[] args) { int result = JOptionPane.showConfirmDialog(null, "Show over parent?"); for (int i = 1; i < 4; i++) { JFrame f = new JFrame("Frame " + i); f.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE); Component parent = (JOptionPane.OK_OPTION == result ? f : null); f.setSize(400, 300);/*w w w . j a va 2s .c o m*/ f.setLocationByPlatform(true); f.setVisible(true); JDialog d = new JDialog(f); d.setTitle("Dialog " + i); d.setSize(300, 200); d.setLocationRelativeTo(parent); d.setVisible(true); } }
From source file:Main.java
public static void main(String[] argv) throws Exception { JFrame frame = new JFrame(); String message = "message"; int answer = JOptionPane.showConfirmDialog(frame, message); if (answer == JOptionPane.YES_OPTION) { // User clicked YES. } else if (answer == JOptionPane.NO_OPTION) { // User clicked NO. }//from w w w . j a va 2 s . c o m }
From source file:Main.java
public static void main(String[] args) { JFrame frame = new JFrame(); frame.setSize(200, 200);//from ww w .ja v a 2 s. c o m frame.setVisible(true); JOptionPane.showMessageDialog(frame, "A"); JOptionPane.showMessageDialog(frame, "B", "message", JOptionPane.WARNING_MESSAGE); int result = JOptionPane.showConfirmDialog(null, "Remove now?"); switch (result) { case JOptionPane.YES_OPTION: System.out.println("Yes"); break; case JOptionPane.NO_OPTION: System.out.println("No"); break; case JOptionPane.CANCEL_OPTION: System.out.println("Cancel"); break; case JOptionPane.CLOSED_OPTION: System.out.println("Closed"); break; } String name = JOptionPane.showInputDialog(null, "Please enter your name."); System.out.println(name); JTextField userField = new JTextField(); JPasswordField passField = new JPasswordField(); String message = "Please enter your user name and password."; result = JOptionPane.showOptionDialog(frame, new Object[] { message, userField, passField }, "Login", JOptionPane.OK_CANCEL_OPTION, JOptionPane.QUESTION_MESSAGE, null, null, null); if (result == JOptionPane.OK_OPTION) System.out.println(userField.getText() + " " + new String(passField.getPassword())); }
From source file:Main.java
public static void main(String[] args) throws Exception { String[] properties = { "os.name", "java.version", "java.vm.version", "java.vendor" }; for (String property : properties) { System.out.println(property + ": " + System.getProperty(property)); }/* w ww . ja va 2 s. com*/ JFileChooser jfc = new JFileChooser(); jfc.showOpenDialog(null); jfc.addChoosableFileFilter(new FileFilter() { @Override public boolean accept(File f) { return f.isDirectory() || f.getName().toLowerCase().endsWith(".obj"); } @Override public String getDescription() { return "Wavefront OBJ (*.obj)"; } @Override public String toString() { return getDescription(); } }); int result = JOptionPane.showConfirmDialog(null, "Description was 'All Files'?"); UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName()); SwingUtilities.updateComponentTreeUI(jfc); jfc.showOpenDialog(null); result = JOptionPane.showConfirmDialog(null, "Description was 'All Files'?"); result = JOptionPane.showConfirmDialog(null, "Description was 'All Files'?"); for (UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) { if ("Nimbus".equals(info.getName())) { UIManager.setLookAndFeel(info.getClassName()); SwingUtilities.updateComponentTreeUI(jfc); break; } } jfc.showOpenDialog(null); result = JOptionPane.showConfirmDialog(null, "Description was 'All Files'?"); }
From source file:Examples.java
public static void main(String args[]) { JFrame frame = new JFrame("Example Popup"); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); Container contentPane = frame.getContentPane(); contentPane.setLayout(new GridLayout(0, 1)); JFrame frame2 = new JFrame("Desktop"); final JDesktopPane desktop = new JDesktopPane(); frame2.getContentPane().add(desktop); JButton pick = new JButton("Pick"); pick.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent actionEvent) { System.out.println("Hi"); }/*from www. java2 s. c o m*/ }); frame2.getContentPane().add(pick, BorderLayout.SOUTH); JButton messagePopup = new JButton("Message"); contentPane.add(messagePopup); messagePopup.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent actionEvent) { Component source = (Component) actionEvent.getSource(); JOptionPane.showMessageDialog(source, "Printing complete"); JOptionPane.showInternalMessageDialog(desktop, "Printing complete"); } }); JButton confirmPopup = new JButton("Confirm"); contentPane.add(confirmPopup); confirmPopup.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent actionEvent) { Component source = (Component) actionEvent.getSource(); JOptionPane.showConfirmDialog(source, "Continue printing?"); JOptionPane.showInternalConfirmDialog(desktop, "Continue printing?"); } }); JButton inputPopup = new JButton("Input"); contentPane.add(inputPopup); inputPopup.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent actionEvent) { Component source = (Component) actionEvent.getSource(); JOptionPane.showInputDialog(source, "Enter printer name:"); // Moons of Neptune String smallList[] = { "Naiad", "Thalassa", "Despina", "Galatea", "Larissa", "Proteus", "Triton", "Nereid" }; JOptionPane.showInternalInputDialog(desktop, "Pick a printer", "Input", JOptionPane.QUESTION_MESSAGE, null, smallList, "Triton"); // Moons of Saturn - includes two provisional designations to // make 20 String bigList[] = { "Pan", "Atlas", "Prometheus", "Pandora", "Epimetheus", "Janus", "Mimas", "Enceladus", "Tethys", "Telesto", "Calypso", "Dione", "Helene", "Rhea", "Titan", "Hyperion", "Iapetus", "Phoebe", "S/1995 S 2", "S/1981 S 18" }; // Object saturnMoon = JOptionPane.showInputDialog(source, "Pick // a printer", "Input", JOptionPane.QUESTION_MESSAGE, null, // bigList, "Titan"); Object saturnMoon = JOptionPane.showInputDialog(source, "Pick a printer", "Input", JOptionPane.QUESTION_MESSAGE, null, bigList, null); System.out.println("Saturn Moon: " + saturnMoon); } }); JButton optionPopup = new JButton("Option"); contentPane.add(optionPopup); optionPopup.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent actionEvent) { Component source = (Component) actionEvent.getSource(); Icon greenIcon = new DiamondIcon(Color.green); Icon redIcon = new DiamondIcon(Color.red); Object iconArray[] = { greenIcon, redIcon }; JOptionPane.showOptionDialog(source, "Continue printing?", "Select an Option", JOptionPane.YES_NO_OPTION, JOptionPane.QUESTION_MESSAGE, null, iconArray, iconArray[1]); Icon blueIcon = new DiamondIcon(Color.blue); Object stringArray[] = { "Do It", "No Way" }; JOptionPane.showInternalOptionDialog(desktop, "Continue printing?", "Select an Option", JOptionPane.YES_NO_OPTION, JOptionPane.QUESTION_MESSAGE, blueIcon, stringArray, stringArray[0]); } }); frame.setSize(300, 200); frame.setVisible(true); frame2.setSize(300, 200); frame2.setVisible(true); }
From source file:net.redstonelamp.gui.RedstoneLampGUI.java
public static void main(String[] args) { JFrame frame = new JFrame("RedstoneLamp"); frame.setLayout(new GridLayout(2, 1)); frame.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE); JLabel label = new JLabel("RedstoneLamp"); label.setHorizontalAlignment(SwingConstants.CENTER); frame.add(label);/*from w w w. j a v a2 s . c om*/ JPanel lowPanel = new JPanel(); JPanel left = new JPanel(); left.setLayout(new BoxLayout(left, BoxLayout.Y_AXIS)); lowPanel.add(left); JPanel right = new JPanel(); right.setLayout(new BoxLayout(right, BoxLayout.Y_AXIS)); lowPanel.add(right); JButton openButton = new JButton("Open server at..."); openButton.addActionListener(e -> { JFileChooser chooser = new JFileChooser(new File(".")); chooser.setDialogTitle("Select RedstoneLamp server home"); chooser.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY); chooser.setAcceptAllFileFilterUsed(false); int action = chooser.showOpenDialog(frame); if (action == JFileChooser.APPROVE_OPTION) { File selected = chooser.getSelectedFile(); File jar = new File("RedstoneLamp.jar"); if (!jar.isFile()) { int result = JOptionPane.showConfirmDialog(frame, "Could not find RedstoneLamp installation. " + "Would you like to install RedstoneLamp there?"); if (result == JOptionPane.YES_OPTION) { installCallback(frame, selected); } return; } frame.dispose(); addHistory(selected); currentRoot = new ServerActivity(selected); } }); right.add(openButton); JButton installButton = new JButton("Install server at..."); installButton.addActionListener(e -> { JFileChooser chooser = new JFileChooser("."); chooser.setDialogTitle("Select directory to install server in"); chooser.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY); chooser.setAcceptAllFileFilterUsed(false); int action = chooser.showSaveDialog(frame); if (action == JFileChooser.APPROVE_OPTION) { File selected = chooser.getSelectedFile(); File jar = new File("RedstoneLamp.jar"); if (jar.isFile()) { int result = JOptionPane.showConfirmDialog(frame, "A RedstoneLamp jar installation is present. " + "Are you sure you want to reinstall RedstoneLamp there?"); if (result == JOptionPane.NO_OPTION) { frame.dispose(); addHistory(selected); currentRoot = new ServerActivity(selected); return; } } installCallback(frame, selected); } }); frame.add(lowPanel); frame.pack(); Dimension dimension = Toolkit.getDefaultToolkit().getScreenSize(); frame.setLocation(dimension.width / 2 - frame.getSize().width / 2, dimension.height / 2 - frame.getSize().height / 2); frame.setVisible(true); }
From source file:Main.java
public static boolean confirm(String msg) { return JOptionPane.YES_OPTION == JOptionPane.showConfirmDialog(null, msg); }