MenuDefTyp.java Source code

Java tutorial

Introduction

Here is the source code for MenuDefTyp.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 java.util.Scanner;
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 MenuDefTyp extends javax.swing.JFrame {

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

        BackToMain = new javax.swing.JButton();
        jScrollPane1 = new javax.swing.JScrollPane();
        TypTextArea = new javax.swing.JTextArea();

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

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

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

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

    public static void getTypes() {

        MongoClient mongoClient = new MongoClient("localhost", 27017);
        MongoDatabase db = mongoClient.getDatabase("database");
        MongoCollection<Document> elexirCollection = db.getCollection("test");

        FindIterable<Document> results = elexirCollection
                .find(new BasicDBObject("Objects", new BasicDBObject("$gt", ".0001")));
        //FindIterable<Document> iter = elexirCollection.find(new BasicDBObject("derivProb", 2));

        for (Document doc : results) {
            // do something with each result

            List<String> conv = (List<String>) doc.get("Types");

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

            for (String s : convArr)
                TypTextArea.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(MenuDefTyp.class.getName()).log(java.util.logging.Level.SEVERE, null,
                    ex);
        } catch (InstantiationException ex) {
            java.util.logging.Logger.getLogger(MenuDefTyp.class.getName()).log(java.util.logging.Level.SEVERE, null,
                    ex);
        } catch (IllegalAccessException ex) {
            java.util.logging.Logger.getLogger(MenuDefTyp.class.getName()).log(java.util.logging.Level.SEVERE, null,
                    ex);
        } catch (javax.swing.UnsupportedLookAndFeelException ex) {
            java.util.logging.Logger.getLogger(MenuDefTyp.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 MenuDefTyp().setVisible(true);
            }
        });
    }

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