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 MenuDefAct extends javax.swing.JFrame { /** * Creates new form MenuDefAct */ public MenuDefAct() { 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() { BackToMain1 = new javax.swing.JButton(); jScrollPane1 = new javax.swing.JScrollPane(); ActTextArea = new javax.swing.JTextArea(); setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE); getContentPane().setLayout(null); BackToMain1.setText("Back"); BackToMain1.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { BackToMain1ActionPerformed(evt); } }); getContentPane().add(BackToMain1); BackToMain1.setBounds(0, 0, 72, 29); ActTextArea.setColumns(20); ActTextArea.setRows(5); jScrollPane1.setViewportView(ActTextArea); 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 BackToMain1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_BackToMain1ActionPerformed // TODO add your handling code here: this.dispose(); }//GEN-LAST:event_BackToMain1ActionPerformed public static void getActions() { MongoClient mongoClient = new MongoClient("localhost", 27017); MongoDatabase db = mongoClient.getDatabase("database"); MongoCollection<Document> elexirCollection = db.getCollection("test"); FindIterable<Document> results = elexirCollection .find(new BasicDBObject("Types", new BasicDBObject("$gt", "0"))); //FindIterable<Document> iter = elexirCollection.find(new BasicDBObject("derivProb", 2)); for (Document doc : results) { List<String> conv = (List<String>) doc.get("Actions"); String[] convArr = new String[conv.size()]; convArr = conv.toArray(convArr); for (String s : convArr) ActTextArea.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(MenuDefAct.class.getName()).log(java.util.logging.Level.SEVERE, null, ex); } catch (InstantiationException ex) { java.util.logging.Logger.getLogger(MenuDefAct.class.getName()).log(java.util.logging.Level.SEVERE, null, ex); } catch (IllegalAccessException ex) { java.util.logging.Logger.getLogger(MenuDefAct.class.getName()).log(java.util.logging.Level.SEVERE, null, ex); } catch (javax.swing.UnsupportedLookAndFeelException ex) { java.util.logging.Logger.getLogger(MenuDefAct.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 MenuDefAct().setVisible(true); } }); } // Variables declaration - do not modify//GEN-BEGIN:variables private static javax.swing.JTextArea ActTextArea; private javax.swing.JButton BackToMain1; private javax.swing.JScrollPane jScrollPane1; // End of variables declaration//GEN-END:variables }