Java tutorial
import com.mongodb.BasicDBObject; import com.mongodb.MongoClient; import com.mongodb.client.FindIterable; import com.mongodb.client.MongoCollection; import com.mongodb.client.MongoDatabase; import java.util.List; import org.bson.Document; /* * To change this license header, choose License Headers in Project Properties. * To change this template file, choose Tools | Templates * and open the template in the editor. */ /** * * @author adit */ public class MenuProb extends javax.swing.JFrame { /** * Creates new form MenuProb */ public MenuProb() { initComponents(); } /** * This method is called from within the constructor to initialize the form. * WARNING: Do NOT modify this code. The content of this method is always * regenerated by the Form Editor. */ @SuppressWarnings("unchecked") // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents private void initComponents() { BackToMain3 = new javax.swing.JButton(); jScrollPane1 = new javax.swing.JScrollPane(); ProbTextArea = new javax.swing.JTextArea(); setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE); getContentPane().setLayout(null); BackToMain3.setText("Back"); BackToMain3.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { BackToMain3ActionPerformed(evt); } }); getContentPane().add(BackToMain3); BackToMain3.setBounds(0, 0, 72, 29); ProbTextArea.setColumns(20); ProbTextArea.setRows(5); jScrollPane1.setViewportView(ProbTextArea); getContentPane().add(jScrollPane1); jScrollPane1.setBounds(70, 30, 500, 180); setSize(new java.awt.Dimension(627, 267)); setLocationRelativeTo(null); }// </editor-fold>//GEN-END:initComponents private void BackToMain3ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_BackToMain3ActionPerformed // TODO add your handling code here: this.dispose(); }//GEN-LAST:event_BackToMain3ActionPerformed public static void getProbability() { MongoClient mongoClient = new MongoClient("localhost", 27017); MongoDatabase db = mongoClient.getDatabase("database"); MongoCollection<Document> elexirCollection = db.getCollection("test"); FindIterable<Document> results = elexirCollection .find(new BasicDBObject("Probability", new BasicDBObject("$gt", "0"))); //FindIterable<Document> iter = elexirCollection.find(new BasicDBObject("derivProb", 2)); for (Document doc : results) { List<String> conv = (List<String>) doc.get("Probability"); String[] convArr = new String[conv.size()]; convArr = conv.toArray(convArr); for (String s : convArr) ProbTextArea.append(s + "\n"); } } /** * @param args the command line arguments */ public static void main(String args[]) { /* Set the Nimbus look and feel */ //<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) "> /* If Nimbus (introduced in Java SE 6) is not available, stay with the default look and feel. * For details see http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html */ try { for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) { if ("Nimbus".equals(info.getName())) { javax.swing.UIManager.setLookAndFeel(info.getClassName()); break; } } } catch (ClassNotFoundException ex) { java.util.logging.Logger.getLogger(MenuProb.class.getName()).log(java.util.logging.Level.SEVERE, null, ex); } catch (InstantiationException ex) { java.util.logging.Logger.getLogger(MenuProb.class.getName()).log(java.util.logging.Level.SEVERE, null, ex); } catch (IllegalAccessException ex) { java.util.logging.Logger.getLogger(MenuProb.class.getName()).log(java.util.logging.Level.SEVERE, null, ex); } catch (javax.swing.UnsupportedLookAndFeelException ex) { java.util.logging.Logger.getLogger(MenuProb.class.getName()).log(java.util.logging.Level.SEVERE, null, ex); } //</editor-fold> /* Create and display the form */ java.awt.EventQueue.invokeLater(new Runnable() { public void run() { new MenuProb().setVisible(true); } }); } // Variables declaration - do not modify//GEN-BEGIN:variables private javax.swing.JButton BackToMain3; private static javax.swing.JTextArea ProbTextArea; private javax.swing.JScrollPane jScrollPane1; // End of variables declaration//GEN-END:variables }