⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 appletpanel.java

📁 it is Also Kmeans Algorithm in java.
💻 JAVA
字号:
/* * AppletPanel.java * * Created on 14 February 2008, 14:21 */package clusteranalysis;import javax.swing.*;import java.awt.*;import java.awt.event.*;import java.util.*;/** * * @author  hako */public class AppletPanel extends javax.swing.JPanel {        ArrayList<Point> points;    KMeanCluster cluster;    double[][] data;    Color color1,color2,color3,color4,color5;    int W,H;    int groupCount=2;        /** Creates new form AppletPanel */    public AppletPanel() {        initComponents();        initMe();    }        public void initMe(){        W=this.getWidth();        H=this.getHeight();        this.setLayout(null);        this.setBackground(Color.BLACK);        points=new ArrayList<Point>();        color1=Color.RED;        color2=Color.GREEN;        color3=Color.BLUE;        color4=Color.YELLOW;        color5=Color.ORANGE;    }         public void paint(Graphics g){        super.paint(g);        Point p=null;        if (points.size()>2){            clusterIt();        }                for (int i=0;i<points.size();i++){            p=points.get(i);            g.setColor(Color.WHITE);            try{                if (cluster.indices[i]==0) g.setColor(this.color1);                if (cluster.indices[i]==1) g.setColor(this.color2);                if (cluster.indices[i]==2) g.setColor(this.color3);                if (cluster.indices[i]==3) g.setColor(this.color4);                if (cluster.indices[i]==4) g.setColor(this.color5);            }catch (Exception e){                            }            g.fillOval((int)p.getX(), (int)p.getY(), 5, 5);            g.drawString(String.valueOf(i+1), (int)p.getX()-3, (int)p.getY()-3);        }    }        public void clusterIt(){        data=new double[points.size()][2];        Point p;        for (int i=0;i<points.size();i++){            p=points.get(i);            data[i][0]=p.getX();            data[i][1]=p.getY();        }        cluster=new KMeanCluster(data, this.groupCount);        cluster.doIt();    }        /** 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() {        addMouseListener(new java.awt.event.MouseAdapter() {            public void mouseClicked(java.awt.event.MouseEvent evt) {                formMouseClicked(evt);            }        });        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this);        this.setLayout(layout);        layout.setHorizontalGroup(            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)            .addGap(0, 400, Short.MAX_VALUE)        );        layout.setVerticalGroup(            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)            .addGap(0, 300, Short.MAX_VALUE)        );    }// </editor-fold>//GEN-END:initComponents    private void formMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_formMouseClicked        points.add(evt.getPoint());        repaint();    }//GEN-LAST:event_formMouseClicked            // Variables declaration - do not modify//GEN-BEGIN:variables    // End of variables declaration//GEN-END:variables    }

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -