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:Classes.DBConnection.java

/**
 * Initialize the connections configuration
 *///  w ww  .j  ava 2  s .  c o  m
public static void init_BasicDataSourceFactory() {
    Properties propiedades = new Properties();
    /*
    setMaxActive(): N mx de conexiones que se pueden abrir simultneamente.
    setMinIdle(): N mn de conexiones inactivas que queremos que haya. Si el n de conexiones baja de este n, se abriran ms.
    setMaxIdle(): N mx de conexiones inactivas que queremos que haya. Si hay ms, se irn cerrando.
    */
    propiedades.setProperty("driverClassName", "com.mysql.jdbc.Driver");
    propiedades.setProperty("url", "jdbc:mysql://localhost:3306/prog");
    propiedades.setProperty("maxActive", "10");
    propiedades.setProperty("maxIdle", "8");
    propiedades.setProperty("minIdle", "0");
    propiedades.setProperty("maxWait", "500");
    propiedades.setProperty("initialSize", "5");
    propiedades.setProperty("defaultAutoCommit", "true");
    propiedades.setProperty("username", "root");
    propiedades.setProperty("password", "12345");
    propiedades.setProperty("validationQuery", "select 1");
    propiedades.setProperty("validationQueryTimeout", "100");
    propiedades.setProperty("initConnectionSqls", "SELECT 1;SELECT 2");
    propiedades.setProperty("poolPreparedStatements", "true");
    propiedades.setProperty("maxOpenPreparedStatements", "10");

    try {
        dataSource = (BasicDataSource) BasicDataSourceFactory.createDataSource(propiedades);
    } catch (Exception e) {
        e.printStackTrace();
        JOptionPane.showMessageDialog(null, e.toString());
    }
}

From source file:App.classes.BD_Connection.java

/**
 * public Connection AbrirConexion() {/*from  w  w w.  j ava  2 s  .com*/
 *
 * Connection con = null; try { Class.forName("com.mysql.jdbc.Driver");
 * String urlOdbc = "jdbc:mysql://127.0.0.1:3306/db_admin"; con =
 * (java.sql.DriverManager.getConnection(urlOdbc, "root", ""));
 *
 * } catch (Exception e) {
 *
 *
 * //e.printStackTrace(); JOptionPane.showMessageDialog(null, "Ha sido
 * imposible establecer la conexion!"); } return con; }
 *
 * /**
 * cerramos la conexion en la bd
 *
 * @param con
 */
/*
        
        
public void CerrarConexion(Connection con) {
try {
    if (con != null) {
        con.close();
    }
} catch (SQLException e) {
        
    JOptionPane.showMessageDialog(null, "Ha sido imposible cerrar la conexion!");
}
}
        
 */
public static void initialize_BasicDataSourceFactory() {
    Properties propiedades = new Properties();
    /*
    setMaxActive(): N mx de conexiones que se pueden abrir simultneamente.
    setMinIdle(): N mn de conexiones inactivas que queremos que haya. Si el n de conexiones baja de este n, se abriran ms.
    setMaxIdle(): N mx de conexiones inactivas que queremos que haya. Si hay ms, se irn cerrando.
     */
    propiedades.setProperty("driverClassName", "com.mysql.jdbc.Driver");
    propiedades.setProperty("url", "jdbc:mysql://localhost:3306/mysql");
    propiedades.setProperty("maxActive", "10");
    propiedades.setProperty("maxIdle", "8");
    propiedades.setProperty("minIdle", "0");
    propiedades.setProperty("maxWait", "5000");
    propiedades.setProperty("initialSize", "5");
    propiedades.setProperty("defaultAutoCommit", "true");
    propiedades.setProperty("username", "root");
    propiedades.setProperty("password", "");
    propiedades.setProperty("validationQuery", "select 1");
    propiedades.setProperty("validationQueryTimeout", "10000");
    propiedades.setProperty("initConnectionSqls", "SELECT 1;SELECT 2");
    propiedades.setProperty("poolPreparedStatements", "true");
    propiedades.setProperty("maxOpenPreparedStatements", "10");

    try {
        //propiedades.load(new FileInputStream("src/config/datasource_config.properties"));
        Singleton_App.dataSource = (BasicDataSource) BasicDataSourceFactory.createDataSource(propiedades);
    } catch (Exception e) {
        JOptionPane.showMessageDialog(null, e.toString());
    }
}

From source file:com.vrane.metaGlacier.gui.MetaDataSignUpDialog.java

MetaDataSignUpDialog() {
    super(Main.frame, true);
    JPanel signUpPanel = new JPanel(new GridLayout(4, 2));
    final JTextField nameJT = new JTextField(10);
    final JTextField emailJT = new JTextField(10);
    final JTextField emailJT1 = new JTextField(10);
    final JButton signUpButton = new JButton("Sign up");

    signUpPanel.setBorder(BorderFactory.createEmptyBorder(10, 5, 5, 5));

    signUpPanel.add(new JLabel("name (optional)"));
    signUpPanel.add(nameJT);//from ww w  .  java  2 s  .c  om

    signUpPanel.add(new JLabel("email"));
    signUpPanel.add(emailJT);

    signUpPanel.add(new JLabel("email again"));
    signUpPanel.add(emailJT1);

    signUpPanel.add(new JLabel());

    signUpPanel.add(signUpButton);
    signUpButton.addActionListener(new ActionListener() {

        @Override
        public void actionPerformed(ActionEvent ae) {
            final String email = emailJT.getText();
            final String email1 = emailJT1.getText();
            final String name = nameJT.getText();
            boolean success = false;

            if (!email.equals(email1)) {
                JOptionPane.showMessageDialog(null, "Email addresses do not match");
                return;
            }
            if (!EmailValidator.getInstance().isValid(email)) {
                JOptionPane.showMessageDialog(null, "Invalid email address");
                return;
            }
            try {
                success = new SignUp().signup(email, name);
            } catch (SDKException ex) {
                LGR.log(Level.SEVERE, null, ex);
            }
            if (success) {
                JOptionPane.showMessageDialog(null, "Please check your email to confirm");
                dispose();
                return;
            }
            JOptionPane.showMessageDialog(null, "Error signing up");
        }
    });
    add(signUpPanel);
    pack();
    setLocationRelativeTo(Main.frame);
    setVisible(true);
}

From source file:mysynopsis.FTPUploader.java

public static void display() throws IOException {

    JTextField address = new JTextField(server);
    JTextField username = new JTextField(user);
    JPasswordField password = new JPasswordField(pass);
    JTextField directory = new JTextField(dir);

    JPanel panel = new JPanel(new GridLayout(10, 1));
    panel.add(new JLabel("Server Address:"));
    panel.add(address);/*  w  w w . ja  v  a 2  s .  c o m*/
    panel.add(new JLabel("Username:"));
    panel.add(username);
    panel.add(new JLabel("Password:"));
    panel.add(password);
    panel.add(new JLabel("Upload Directory:"));
    panel.add(directory);

    int result;

    /*JOptionPane pane = new JOptionPane(panel,JOptionPane.PLAIN_MESSAGE, JOptionPane.YES_NO_CANCEL_OPTION);
    JDialog dialog = pane.createDialog(MotherFrame.mframe, "FTP Upload Wizard - My Synopsis");
    dialog.setSize(new Dimension(300,300));
    dialog.setVisible(true);*/

    result = JOptionPane.showConfirmDialog(MotherFrame.mframe, panel, "FTP Upload Wizard",
            JOptionPane.OK_CANCEL_OPTION, JOptionPane.PLAIN_MESSAGE);

    if (result == JOptionPane.OK_OPTION) {

        server = address.getText();
        user = username.getText();
        pass = new String(password.getPassword());
        //    System.out.println(pass);
        dir = directory.getText();

        JOptionPane.showMessageDialog(MotherFrame.mframe, "Press OK to start FTP Upload");

        HTMLWriter.writeHTML();

        JOptionPane.showMessageDialog(MotherFrame.mframe, uploadWizard());

    } else {
        //  System.out.println("Cancelled");
    }
}

From source file:MFPIM.NotificationFrame.java

private void initEmpNotifTable() {
    try {/*  ww  w  .j a  va2  s . c  o  m*/

        DateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd");
        Date date = DateUtils.addMonths(new Date(), -5);
        String newDate = dateFormat.format(date);

        String sql = "select empNo,fName,lName from Employee where dateHired <= '" + newDate
                + "' and empStatus='Probationary'";
        conn = DBConnect.connect();
        pst = conn.prepareStatement(sql);
        rs = pst.executeQuery();
        probEmpNotifTable.setModel(DbUtils.resultSetToTableModel(rs));
        ChangeName(probEmpNotifTable, 0, "Employee ID No.");
        ChangeName(probEmpNotifTable, 1, "First Name");
        ChangeName(probEmpNotifTable, 2, "Surname");
    } catch (Exception e) {
        JOptionPane.showMessageDialog(null, "initEmpNotifTable:" + e);
    } finally {
        if (rs != null) {
            try {
                rs.close();
            } catch (SQLException ex) {
                JOptionPane.showMessageDialog(null, ex);
            }
        }
        if (pst != null) {
            try {
                pst.close();
            } catch (SQLException ex) {
                JOptionPane.showMessageDialog(null, ex);
            }
        }
        if (conn != null) {
            try {
                conn.close();
            } catch (SQLException ex) {
                JOptionPane.showMessageDialog(null, ex);
            }
        }
    }
}

From source file:Main.java

/**
 * opens the URL in a browser.//from w  w w.j  ava  2  s  . c  o m
 * 
 * @param parent the parent component
 * @param url the URL to open
 * @param showDialog whether to display a dialog in case of an error or just
 *          print the error to the console
 */
public static void openURL(Component parent, String url, boolean showDialog) {
    String osName = System.getProperty("os.name");
    try {
        // Mac OS
        if (osName.startsWith("Mac OS")) {
            Class<?> fileMgr = Class.forName("com.apple.eio.FileManager");
            Method openURL = fileMgr.getDeclaredMethod("openURL", new Class[] { String.class });
            openURL.invoke(null, new Object[] { url });
        }
        // Windows
        else if (osName.startsWith("Windows")) {
            Runtime.getRuntime().exec("rundll32 url.dll,FileProtocolHandler " + url);
        }
        // assume Unix or Linux
        else {
            String browser = null;
            for (int count = 0; count < LINUX_BROWSERS.length && browser == null; count++) {
                // look for binaries and take first that's available
                if (Runtime.getRuntime().exec(new String[] { "which", LINUX_BROWSERS[count] }).waitFor() == 0) {
                    browser = LINUX_BROWSERS[count];
                    break;
                }
            }
            if (browser == null) {
                throw new Exception("Could not find web browser");
            } else {
                Runtime.getRuntime().exec(new String[] { browser, url });
            }
        }
    } catch (Exception e) {
        String errMsg = "Error attempting to launch web browser:\n" + e.getMessage();

        if (showDialog) {
            JOptionPane.showMessageDialog(parent, errMsg);
        } else {
            System.err.println(errMsg);
        }
    }
}

From source file:classes.SharedClass.java

public static void print(String message, JTable table) {
    MessageFormat header = new MessageFormat(message);
    MessageFormat footer = new MessageFormat("(0,number,nteger)");
    try {/* w  w w .  j  av a  2 s  .co m*/
        boolean result = table.print(JTable.PrintMode.FIT_WIDTH, header, footer);
        if (result) {
            JOptionPane.showMessageDialog(null, "   ");
        }
    } catch (PrinterException ex) {
        Logger.getLogger(SharedClass.class.getName()).log(Level.SEVERE, null, ex);
    }
}

From source file:ModeloConection.Email.java

/**
 * Metodo contm as informaes do email, para quem quem envia, assunto,
 * mensagem e para quem ser enviado, ocorre o envio
 *
 * @param from/*from   w  w w .j a  va 2 s.co  m*/
 * @param subject
 * @param msg
 * @param to
 */
public void enviarEmail(String from, String subject, String msg, String to) {
    // public void enviarEmail() {
    try {
        email.setFrom(from);//quem est enviando 
        email.setSubject(subject); //assuntoe
        email.setMsg(msg); // mensagem
        email.addTo(to); // quem recebe

        email.send();// envio do email
        email.setDebug(true);
        JOptionPane.showMessageDialog(null, "Teste de envio de email concluido com sucesso.\n");
    } catch (EmailException ex) {
        JOptionPane.showMessageDialog(null, "Erro ao realizar o envio do email!\n" + ex.getMessage());

    }
}

From source file:mysynopsis.JSONReader.java

public static void readData() throws FileNotFoundException, IOException, ParseException {

    try {//from w  w w .  j  av a  2  s . co m
        JSONParser parser = new JSONParser();
        Object obj = parser.parse(new FileReader("data.json"));
        JSONObject read;
        read = (JSONObject) obj;

        name = (String) read.get("Name");
        initial = (String) read.get("Initial");
        biog = (String) read.get("Bio");
        designation = (String) read.get("Designation");
        dept = (String) read.get("Department");
        university = (String) read.get("University");
        universityAddress = (String) read.get("University_Address");
        office = (String) read.get("Office");
        officehours = (String) read.get("Ohours");
        phone = (String) read.get("Phone");
        email = (String) read.get("Email");
        resumelink = (String) read.get("Resume_Link");
        education = (String) read.get("Educational");
        professional = (String) read.get("Professional");
        awards = (String) read.get("Awards");

        imgExtension = (String) read.get("Image_Ext");
        imgString = (String) read.get("Image_String");

        /*JSONArray education = (JSONArray) read.get("Education");
                
        for(int i=0;i<8;i++) {
                
        educ[i] = (String) education.get(i);
                
        }*/
        JSONArray ftpinfo = (JSONArray) read.get("Server_Information");

        server = (String) ftpinfo.get(0);
        user = (String) ftpinfo.get(1);
        dir = (String) ftpinfo.get(2);
    } catch (IOException | ParseException e) {

        JOptionPane.showMessageDialog(null, "Something went wrong. Please re-run the software.");
    }
}

From source file:PersistentFrameTest.java

 public void load()
{
   // show file chooser dialog
   int r = chooser.showOpenDialog(null);

   // if file selected, open
   if(r == JFileChooser.APPROVE_OPTION)
   {//  ww w .j  av  a2s .  c o m
      try
      {
         File file = chooser.getSelectedFile();
         XMLDecoder decoder = new XMLDecoder(new FileInputStream(file));
         decoder.readObject(); 
         decoder.close();
      }
      catch (IOException e)
      {
         JOptionPane.showMessageDialog(null, e);
      }
   }
}