Mega Code Archive

 
Categories / Java / Swing JFC
 

Exercise Options

import javax.swing.JFrame; import javax.swing.JOptionPane; import javax.swing.JPasswordField; import javax.swing.JTextField; public class Main {   public static void main(String[] args) {     JFrame frame = new JFrame();     frame.setSize(200, 200);     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()));   } }