MenuDefObj.java Source code

Java tutorial

Introduction

Here is the source code for MenuDefObj.java

Source

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 MenuDefObj extends javax.swing.JFrame {

    /**
     * Creates new form MenuDefObj
     */
    public MenuDefObj() {
        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() {

        jButton1 = new javax.swing.JButton();
        jScrollPane1 = new javax.swing.JScrollPane();
        ObjTextArea = new javax.swing.JTextArea();

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
        getContentPane().setLayout(null);

        jButton1.setText("Back");
        jButton1.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton1ActionPerformed(evt);
            }
        });
        getContentPane().add(jButton1);
        jButton1.setBounds(0, 0, 72, 29);

        ObjTextArea.setColumns(20);
        ObjTextArea.setRows(5);
        jScrollPane1.setViewportView(ObjTextArea);

        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 jButton1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton1ActionPerformed
        // TODO add your handling code here:
        this.dispose();
    }//GEN-LAST:event_jButton1ActionPerformed

    public static void getObjects() {

        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("Objects");

            String[] convArr = new String[conv.size()];
            convArr = conv.toArray(convArr);

            for (String s : convArr)
                ObjTextArea.append(s + "\n");

        }
    }

    /**
     * @param args the command line arguments
     */
    public static void main(String args[]) {

        //getObjects();
        /* Create and display the form */
        java.awt.EventQueue.invokeLater(new Runnable() {
            public void run() {
                new MenuDefObj().setVisible(true);

            }
        });
    }

    // Variables declaration - do not modify//GEN-BEGIN:variables
    private static javax.swing.JTextArea ObjTextArea;
    private javax.swing.JButton jButton1;
    private javax.swing.JScrollPane jScrollPane1;
    // End of variables declaration//GEN-END:variables
}