Example usage for javax.swing JOptionPane showMessageDialog

List of usage examples for javax.swing JOptionPane showMessageDialog

Introduction

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

Prototype

public static void showMessageDialog(Component parentComponent, Object message) throws HeadlessException 

Source Link

Document

Brings up an information-message dialog titled "Message".

Usage

From source file:com.tvh.gmaildrafter.Drafter.java

/**
 * @param args the command line arguments
 *///  www.j a  v  a  2  s .c  om
public static void main(String[] args) {
    Options options = getCMDLineOptions();
    CommandLineParser parser = new PosixParser();
    try {
        CommandLine cmd = parser.parse(options, args);
        if (cmd.hasOption("help")) {
            printHelpMessage(options);
            System.exit(0);
        }

        String emailBody = null;
        String emailSubject = null;

        if (cmd.hasOption("body")) {
            String bodyFile = cmd.getOptionValue("body");
            File body = new File(bodyFile);
            emailBody = FileUtils.readFileToString(body);
            if (cmd.hasOption("deletebody")) {
                body.delete();
            }
        } else if (cmd.hasOption("stdin")) {
            emailBody = Util.readEntireStdin();
        }

        if (cmd.hasOption("subject"))
            emailSubject = cmd.getOptionValue("subject");
        else if (cmd.hasOption("subjectfile")) {
            String subjectFile = cmd.getOptionValue("subjectfile");
            File subject = new File(subjectFile);
            emailSubject = FileUtils.readFileToString(subject);
            if (cmd.hasOption("deletesubjectfile"))
                subject.delete();
        }

        String username = null;
        if (cmd.hasOption("username"))
            username = cmd.getOptionValue("username");

        String password = null;
        if (cmd.hasOption("password"))
            password = cmd.getOptionValue("password");

        String[] bcc = cmd.getOptionValues("bcc");
        String[] cc = cmd.getOptionValues("cc");

        Boolean sendImmediately = cmd.hasOption("immediate");

        String[] attachments = cmd.getOptionValues("attachments");
        String[] attachmentnames = cmd.getOptionValues("attachmentnames");
        String[] destinations = cmd.getOptionValues("to");

        Credentials credentials = Authenticater.getValidCredentials(username, password);

        if (credentials != null) {
            boolean success = false;
            while (!success) {
                try {
                    composeMail(credentials, emailSubject, emailBody, attachments, attachmentnames,
                            destinations, cc, bcc, sendImmediately);
                    success = true;
                } catch (AuthenticationFailedException e) {
                    JOptionPane.showMessageDialog(null, "Invalid login, please try again!");
                    credentials = Authenticater.getValidCredentials(username, null);
                    success = false;
                }

            }
        }

    } catch (ParseException ex) {
        javax.swing.JOptionPane.showMessageDialog(null, ex.getMessage());
        printHelpMessage(options);
        System.exit(7);
    } catch (IOException ex) {
        System.out.println("IO Exception " + ex.getLocalizedMessage());
        printHelpMessage(options);
        System.exit(2);
    } catch (LoginException ex) {
        System.out.println(ex.getMessage());
        System.exit(3);
    }

    System.exit(0);

}

From source file:com.moss.appprocs.swing.ProgressMonitorPanel.java

/**
 * Not useful beyond testing this class.
 *//* ww w. j  a v  a2 s. c o m*/
@SuppressWarnings("serial")
public static void main(String[] args) throws Exception {
    UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
    Action a = new AbstractAction("Do Something") {

        public void actionPerformed(ActionEvent e) {
            JOptionPane.showMessageDialog(null, "Hi");
        }

    };
    JFrame window = new JFrame("Test");
    ProgressMonitorPanel panel = new ProgressMonitorPanel(true);
    panel.addNonPersistentProcess(new TestProcess());
    panel.addNonPersistentProcess(new TestProcess());
    panel.addNonPersistentProcess(new TrackableTestProcess());
    panel.addNonPersistentProcess(new TestProcess());
    panel.addPersistentProcess(new TrackableTestProcess(), a);
    //      
    //      JPanel panel = new JPanel();
    //      panel.add(new JLabel("Howdy"));
    //      panel.setBorder(new LineBorder(Color.BLUE, 5));

    window.getContentPane().add(panel);
    window.setSize(400, 800);
    window.setVisible(true);

    window.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
}

From source file:barChart1.BarChartDemo.java

/**
 * Starting point for the demonstration application.
 *
 * @param args  ignored./*from w w  w.  ja  va  2s  . c o m*/
 */
public static void main(String[] args) {

    // Demo to buy tickets to the EK 2016

    System.out.println("Hello UEFA 2016 !!!");

    statistics = "";

    JOptionPane.showMessageDialog(null, "Belgium versus Italy demo start");

    driver = new FirefoxDriver();
    wait = new WebDriverWait(driver, 500);

    //Open Home Page
    driver.manage().window().maximize();
    driver.get("http://www.uefa.com/");

    wait.until(ExpectedConditions.visibilityOfElementLocated(
            By.xpath("//div/header/nav/div/div/ul/li/a[text() = 'UEFA EURO 2016']")));

    driver.findElement(By.xpath("//div/header/nav/div/div/ul/li/a[text() = 'UEFA EURO 2016']")).click();

    wait.until(ExpectedConditions
            .visibilityOfElementLocated(By.xpath("//div/div/div//nav/div/div/ul/li/a[ text() = 'Teams']")));

    wait.until(ExpectedConditions
            .visibilityOfElementLocated(By.xpath("//div/div/div//nav/div/div/ul/li/a[ text() = 'Matches']")))
            .click();

    wait.until(ExpectedConditions.visibilityOfElementLocated(
            By.xpath("//div/div//div//div/a[text() = 'Select your team and follow their EURO journey']")));

    driver.findElement(
            By.xpath("//div/div//div//div/a[text() = 'Select your team and follow their EURO journey']"))
            .click();

    wait2Secs();

    wait.until(ExpectedConditions
            .visibilityOfElementLocated(By.xpath("//div/div/div//ul/li/span[text()='Belgium']")));

    driver.findElement(By.xpath("//div/div/div//ul/li/span[text()='Belgium']")).click();

    // Belgium
    wait2Secs();

    wait.until(ExpectedConditions
            .visibilityOfElementLocated(By.xpath("(//div/table[1]/tbody/tr/td/div/a[text()='21.00'])[1]")));

    driver.findElement(By.xpath("(//div/table[1]/tbody/tr/td/div/a[text()='21.00'])[1]")).click();

    wait2Secs();

    wait.until(ExpectedConditions.visibilityOfElementLocated(By.xpath("//a/span[text()='Pre-match']")));

    // Go to the statistics

    driver.get("http://www.uefa.com/uefaeuro/season=2016/statistics/index.html");

    wait.until(ExpectedConditions.visibilityOfElementLocated(By.xpath("//a/span[text()='Teams']")));

    driver.findElement(By.xpath("//a/span[text()='Teams']")).click();

    // Look up the statistics for Belgium and Italy

    getOverviewStats("BE", "ITA", "Belgium", "Italy");

    wait.until(
            ExpectedConditions.visibilityOfElementLocated(By.xpath("//div/div/div/ul/li/a[text()='Goals']")));

    driver.findElement(By.xpath("//div/div/div/ul/li/a[text()='Goals']")).click();

    wait.until(ExpectedConditions
            .visibilityOfElementLocated(By.xpath("//div/div/div/div/input[@value='Search for a team']")));

    driver.findElement(By.xpath("//div/div/div/div/input[@value='Search for a team']")).sendKeys("Belgium");
    ;

    wait2Secs();

    // getGoalsStats("BE","ITA","Belgium","Italy");

    wait.until(ExpectedConditions
            .visibilityOfElementLocated(By.xpath("//div/div/div/ul/li/a[text()='Attempts']")));

    driver.findElement(By.xpath("//div/div/div/ul/li/a[text()='Attempts']")).click();

    wait.until(ExpectedConditions
            .visibilityOfElementLocated(By.xpath("//div/div/div/div/input[@value='Search for a team']")));

    driver.findElement(By.xpath("//div/div/div/div/input[@value='Search for a team']")).sendKeys("Belgium");
    ;

    wait2Secs();

    wait.until(
            ExpectedConditions.visibilityOfElementLocated(By.xpath("//div/div/div/ul/li/a[text()='Passes']")));

    driver.findElement(By.xpath("//div/div/div/ul/li/a[text()='Passes']")).click();

    wait2Secs();

    // Italy

    wait.until(ExpectedConditions
            .visibilityOfElementLocated(By.xpath("//div/div/div/div/input[@value='Search for a team']")));

    driver.findElement(By.xpath("//div/div/div/div/input[@value='Search for a team']")).sendKeys("Italy");
    ;

    wait.until(ExpectedConditions
            .visibilityOfElementLocated(By.xpath("//div/div/div/ul/li/a[text()='Overview']")));

    driver.findElement(By.xpath("//div/div/div/ul/li/a[text()='Overview']")).click();

    driver.manage().timeouts().implicitlyWait(2, TimeUnit.SECONDS);

    wait.until(ExpectedConditions
            .visibilityOfElementLocated(By.xpath("//div/div/div/div/input[@value='Search for a team']")));

    driver.findElement(By.xpath("//div/div/div/div/input[@value='Search for a team']")).sendKeys("Italy");
    ;

    wait.until(
            ExpectedConditions.visibilityOfElementLocated(By.xpath("//div/div/div/ul/li/a[text()='Goals']")));

    driver.findElement(By.xpath("//div/div/div/ul/li/a[text()='Goals']")).click();

    driver.manage().timeouts().implicitlyWait(2, TimeUnit.SECONDS);

    wait.until(ExpectedConditions
            .visibilityOfElementLocated(By.xpath("//div/div/div/div/input[@value='Search for a team']")));

    driver.findElement(By.xpath("//div/div/div/div/input[@value='Search for a team']")).sendKeys("Italy");
    ;

    wait.until(ExpectedConditions
            .visibilityOfElementLocated(By.xpath("//div/div/div/ul/li/a[text()='Attempts']")));

    driver.findElement(By.xpath("//div/div/div/ul/li/a[text()='Attempts']")).click();

    driver.manage().timeouts().implicitlyWait(2, TimeUnit.SECONDS);

    wait.until(ExpectedConditions
            .visibilityOfElementLocated(By.xpath("//div/div/div/div/input[@value='Search for a team']")));

    driver.findElement(By.xpath("//div/div/div/div/input[@value='Search for a team']")).sendKeys("Italy");
    ;

    wait.until(
            ExpectedConditions.visibilityOfElementLocated(By.xpath("//div/div/div/ul/li/a[text()='Passes']")));

    driver.findElement(By.xpath("//div/div/div/ul/li/a[text()='Passes']")).click();

    wait.until(ExpectedConditions
            .visibilityOfElementLocated(By.xpath("//div/div/div/div/input[@value='Search for a team']")));

    driver.findElement(By.xpath("//div/div/div/div/input[@value='Search for a team']")).sendKeys("Italy");
    ;

    driver.manage().timeouts().implicitlyWait(2, TimeUnit.SECONDS);

    JOptionPane.showMessageDialog(null, "Belgium versus Italy : \n" + statistics);

    BarChartDemo demo = new BarChartDemo("Belgium vs Italy");
    demo.pack();
    RefineryUtilities.centerFrameOnScreen(demo);
    demo.setVisible(true);

}

From source file:Main.java

public static void alert(String msg) {
    JOptionPane.showMessageDialog(null, msg);
}

From source file:Main.java

public static void showMessageDialog(String message) {
    JOptionPane.showMessageDialog(null, message);
}

From source file:Main.java

public static void showDialogWhitImage(URL pathuRL) {

    JPanel panel = new JPanel();
    JLabel jLabel = new JLabel();
    jLabel.setIcon(new javax.swing.ImageIcon(pathuRL)); // NOI18N
    panel.add(jLabel);/*from www  .  ja  v a2 s  .com*/
    JOptionPane.showMessageDialog(null, panel);
    jLabel = null;
    panel = null;
}

From source file:Main.java

public static void displayErrorMessage(JFrame frame, String errorMessage) {
    // create a JTextArea
    JTextArea textArea = new JTextArea(6, 25);
    textArea.setText(errorMessage);//from w  w w.j  a va2  s .  com
    textArea.setEditable(false);

    // wrap a scrollpane around it
    JScrollPane scrollPane = new JScrollPane(textArea);

    // display them in a message dialog
    // TODO i don't know if this will work if this is null
    JOptionPane.showMessageDialog(frame, scrollPane);
}

From source file:Main.java

public static Document CreateCustomerFile(JFrame mainFrame) {
    Document CustomerDoc = null;//from  ww w. j  a  va  2 s .c  o  m
    try {
        DocumentBuilderFactory Factory = DocumentBuilderFactory.newInstance();
        DocumentBuilder Build = Factory.newDocumentBuilder();
        CustomerDoc = Build.newDocument();
        Element rootElem = CustomerDoc.createElement("Customers");
        CustomerDoc.appendChild(rootElem);
    } catch (ParserConfigurationException ex) {
        System.out.println(ex.getMessage());
        JOptionPane.showMessageDialog(mainFrame,
                "There Was an Error Saving The File. Please Restart the Application.");
        System.exit(1);
    }
    return CustomerDoc;
}

From source file:Main.java

/**
 * Opens the given website in the default browser, or show a message saying
 * that no default browser could be accessed.
 *///from  w ww.ja  v a2 s .  c om
public static void browse(Component parent, String uri) {
    boolean error = false;

    if (Desktop.isDesktopSupported() && Desktop.getDesktop().isSupported(Action.BROWSE)) {
        try {
            Desktop.getDesktop().browse(new URI(uri));
        } catch (URISyntaxException ex) {
            throw new RuntimeException(ex);
        } catch (IOException ex) {
            error = true;
        }
    } else {
        error = true;
    }

    if (error) {
        String msg = "Impossible to open the default browser from the application.\nSorry.";
        JOptionPane.showMessageDialog(parent, msg);
    }
}

From source file:Main.java

/**
 * Opens the given website in the default browser, or shows a message saying
 * that no default browser could be accessed.
 *//*from w  w w  .j  ava2 s.c o m*/
public static void browse(String url, Component msgParent) {
    boolean error = false;

    if (Desktop.isDesktopSupported() && Desktop.getDesktop().isSupported(Action.BROWSE)) {
        try {
            Desktop.getDesktop().browse(new URI(url));
        } catch (URISyntaxException ex) {
            throw new RuntimeException(ex);
        } catch (IOException ex) {
            error = true;
        }
    } else {
        error = true;
    }

    if (error) {
        String msg = "Impossible to open the default browser from the application.\nSorry.";
        JOptionPane.showMessageDialog(msgParent, msg);
    }
}