Click here to Skip to main content
15,884,975 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
Java
/*
 * ClusterForm.java
 *
 * Created on September 20, 2010, 2:53 PM
 */
package ctrend;
import javax.swing.*;
import java.awt.*;
import java.util.*;
/**
 *
 * @author  Raja
 */
public class ClusterForm extends javax.swing.JFrame {
    /** Creates new form ClusterForm */
    FlowLayout layout=new FlowLayout();
    DataSet ds;
    ArrayList<String>coldata;
    ClusterBean cbean;
    public ClusterForm() {
        initComponents();
     ds=new DataSet();
     coldata=ds.loadFields();
     cmbColNames.removeAllItems();
     for(int i=0;i<coldata.size();i++)
         cmbColNames.addItem(coldata.get(i).toUpperCase());
    }
    /** 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.
     */
    // <editor-fold defaultstate="collapsed" desc=" Generated Code ">//GEN-BEGIN:initComponents
    private void initComponents() {
        jPanel1 = new javax.swing.JPanel();
        jLabel1 = new javax.swing.JLabel();
        cmbColNames = new javax.swing.JComboBox();
        butSubmit = new javax.swing.JButton();
        butShowTimePeriods = new javax.swing.JButton();
        butShowGraph = new javax.swing.JButton();
        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
        jPanel1.setBorder(javax.swing.BorderFactory.createEtchedBorder());
        jLabel1.setFont(new java.awt.Font("Tahoma", 1, 11));
        jLabel1.setText("Select Time Related Field");
        butSubmit.setText("Submit");
        butSubmit.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                butSubmitActionPerformed(evt);
            }
        });
        butShowTimePeriods.setText("Show Time Periods");
        butShowTimePeriods.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                butShowTimePeriodsActionPerformed(evt);
            }
        });
        butShowGraph.setText("Show Graph");
        butShowGraph.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                butShowGraphActionPerformed(evt);
            }
        });
        javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
        jPanel1.setLayout(jPanel1Layout);
        jPanel1Layout.setHorizontalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addComponent(jLabel1)
                        .addContainerGap(745, Short.MAX_VALUE))
                    .addComponent(butSubmit)
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addComponent(cmbColNames, javax.swing.GroupLayout.PREFERRED_SIZE, 125, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addContainerGap(762, Short.MAX_VALUE))
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addComponent(butShowTimePeriods)
                        .addContainerGap(766, Short.MAX_VALUE))
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addComponent(butShowGraph)
                        .addContainerGap(796, Short.MAX_VALUE))))
        );
        jPanel1Layout.setVerticalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jLabel1)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(cmbColNames, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(8, 8, 8)
                .addComponent(butSubmit)
                .addGap(15, 15, 15)
                .addComponent(butShowTimePeriods)
                .addGap(17, 17, 17)
                .addComponent(butShowGraph)
                .addContainerGap(70, Short.MAX_VALUE))
        );
        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addComponent(jPanel1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addContainerGap())
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addComponent(jPanel1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap(278, Short.MAX_VALUE))
        );
        pack();
    }// </editor-fold>//GEN-END:initComponents
    private void butShowGraphActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_butShowGraphActionPerformed
        buildGraph();
        GraphPanel.tp=cbean.tp;
        System.out.println("TP SIZE:"+cbean.tp.size());
        JFrame frm=new JFrame();
        frm.setTitle("C-TREND Temporal Graph Model");
        frm.setBackground(Color.black);
        GraphPanel gp=new GraphPanel();
        frm.add(gp);
        frm.setSize(800,600);
        frm.setVisible(true);
        frm.setDefaultCloseOperation(frm.DISPOSE_ON_CLOSE);
    }//GEN-LAST:event_butShowGraphActionPerformed
    private void butShowTimePeriodsActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_butShowTimePeriodsActionPerformed
        for(int i=0;i<cbean.tp.size();i++)
        {
            TimePeriod curtp=cbean.tp.get(i);
            curtp.findMedioids();
            curtp.showMedioids();
        }
    }//GEN-LAST:event_butShowTimePeriodsActionPerformed
    public void buildGraph()
    {
        int row,col;
        col=100;
        for(int i=0;i<cbean.tp.size();i++)
        {
            TimePeriod curtp=cbean.tp.get(i);
            row=50;
            for(int j=0;j<curtp.centroids.size();j++,row+=100)
            {
                DataObject curcentroid=curtp.centroids.get(j);
                curcentroid.xc=col;
                curcentroid.yc=row;
                System.out.println(curcentroid.xc+","+curcentroid.yc);
            }
            col+=400;
        }
    }
    private void butSubmitActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_butSubmitActionPerformed
    try
    {
        DataSet ds=new DataSet();
        int colidx=cmbColNames.getSelectedIndex();
        System.out.println("Selected Idx:"+colidx);
        ds.buildTables();
        cbean=new ClusterBean();
        cbean.buildClusters(colidx);
        //ds.loadField(colidx);
    }catch(Exception e)
    {
        e.printStackTrace();
        JOptionPane.showMessageDialog(null,e.toString());
    }
    }//GEN-LAST:event_butSubmitActionPerformed
    /**
     * @param args the command line arguments
     */
    public static void main(String args[]) {
        java.awt.EventQueue.invokeLater(new Runnable() {
            public void run() {
                new ClusterForm().setVisible(true);
            }
        });
    }
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton butShowGraph;
    private javax.swing.JButton butShowTimePeriods;
    private javax.swing.JButton butSubmit;
    private javax.swing.JComboBox cmbColNames;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JPanel jPanel1;
    // End of variables declaration//GEN-END:variables
}
Posted
Updated 26-Mar-11 7:53am
v2
Comments
Аslam Iqbal 26-Mar-11 13:54pm    
Edited for <pre> tag only.
Toli Cuturicu 27-Mar-11 15:16pm    
Code dump; ask for work; rude

Why would someone do the work for you (for free)? :confused: If you have specific problems in translating certain thing to C#, you could pinpoint the problem and ask for help to solve that issue. If you're going to maintain the code by yourself it's crucial that you also understand what the C# code does.
 
Share this answer
 
Comments
Sergey Alexandrovich Kryukov 26-Mar-11 16:58pm    
What else could your answer? My 5.
--SA
Wendelius 26-Mar-11 17:10pm    
Beats me... Thanks for the vote.
Take a look here[^].

There are loads more out there, some better than others. I have no idea how good this one is, it is just the first hit from a search on java to c# converter

I doubt that any of them will do a perfect job though, so you're going to have to learn some C# to complete the job.
 
Share this answer
 
Comments
Sergey Alexandrovich Kryukov 26-Mar-11 17:00pm    
"Perfect job" would be a great exaggeration even in the best case, but could useful, good to know, my 5.
--SA

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
Top Experts
Last 24hrsThis month


CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900