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

📄 output.java

📁 Clustering demo.very good
💻 JAVA
字号:
import javax.swing.*;
import javax.swing.event.*;
import java.awt.*;
import java.awt.event.*;
import java.io.*;
import java.util.*;

class Output extends JFrame implements ActionListener{
   JLabel lnoOfClusters=null,clusters=null;
   JTextArea ta=null;
   JScrollPane sp=null;
   JTextField tnoOfClusters=null;
   JButton exit=null,showGraph=null,saveOutput=null;
   //JButton back=null;
   File f=null;
   FileOutputStream fos=null;
   BufferedOutputStream bos=null;
   byte b[],b1[];
   Cluster[] clustersOutput=null;
//   CURE cure;
    ClusterAlgorithm cj=null;
    Vector v=null;
        public Output(ClusterAlgorithm ca){
	super("Output");

	cj=ca;	
	lnoOfClusters=new JLabel("No. Of Clusters Are");
	saveOutput=new JButton("Save Output");
	clusters=new JLabel("Clusters Are");
	ta=new JTextArea(5,1);
	sp=new JScrollPane(ta);
	tnoOfClusters=new JTextField();
	exit=new JButton("Exit");
	//back=new JButton("BACK");
	showGraph=new JButton("Show Graph");
	clustersOutput=cj.getClusters();
	v=new Vector();

	Container c=this.getContentPane();
	c.setLayout(null);	

	tnoOfClusters.setText(""+cj.getNoOfClusters());
	
	lnoOfClusters.setBounds(300,75,200,45);
	tnoOfClusters.setBounds(325,125,100,30);
	clusters.setBounds(300,180,200,30);
	sp.setBounds(300,225,300,300);
	showGraph.setBounds(250,560,125,50);
	saveOutput.setBounds(380,560,125,50);
	exit.setBounds(510,560,125,50);
	//back.setBounds(430,560,125,50);

	c.add(lnoOfClusters);
	c.add(tnoOfClusters);
	c.add(clusters);
	//c.add(ta);
	c.add(sp);
	c.add(showGraph);
	c.add(saveOutput);
	c.add(exit);
	c.setBackground(new Color(255,200,218));
	
	showGraph.addActionListener(this);
	saveOutput.addActionListener(this);
	exit.addActionListener(this);
	//back.addActionListener(this);
	
	setSize(1025,750);
	setVisible(true);
	v=ReadFile.getDP();

	for(int i=0; i<clustersOutput.length; i++,ta.append("\n")){
	     ta.append("CLUSTER "+(i+1)+"\n");
	     ta.append("----------------\n");
	      for(int j=0; j<clustersOutput[i].getClusterSize(); j++){
		String s="("+(clustersOutput[i].getDataPoint(j).getX())+","+(clustersOutput[i].getDataPoint(j).getY())+")--"+(v.indexOf(clustersOutput[i].getDataPoint(j))+1)+"--\n";
		ta.append(s);
	     }
	}		

         if (cj instanceof CURE){
	for(int i=0; i<clustersOutput.length; i++,ta.append("\n")){
	     ta.append("CLUSTER "+(i+1)+" RepPoints\n");
	     ta.append("-----------------------------\n");
	      for(int j=0; j<clustersOutput[i].getNoOfRepPoints(); j++){
		String s="("+(clustersOutput[i].getRepPoint(j).getX())+","+(clustersOutput[i].getDataPoint(j).getY())+")\n";
		ta.append(s);
	     }
	}
         }//if 
     }
      public void actionPerformed(ActionEvent ae){
	if(ae.getSource()==exit){
		System.exit(0);
	}else if(ae.getSource()==saveOutput){
	         try{
		String s=JOptionPane.showInputDialog(null,"Enter the file name to erite the output","Input",JOptionPane.INFORMATION_MESSAGE);
		String s1;
		f=new File(s);
		fos=new FileOutputStream(f);
		bos=new BufferedOutputStream(fos);
		int i,j,k;
		for(i=0; i<clustersOutput.length; i++){
		         s="----------------CLUSTER "+(i+1)+"----------------\r\n";
		         b=s.getBytes();	
		         bos.write(b);
		     for(j=0; j<clustersOutput[i].getClusterSize(); j++){
  			s1="(";
			b1=s1.getBytes();
			bos.write(b1);
			bos.flush();
			s=""+(clustersOutput[i].getDataPoint(j)).getX();
			b=s.getBytes();
			bos.write(b);
			bos.flush();
			s1=",";
			b1=s1.getBytes();
			bos.write(b1);
			bos.flush();
			s=""+(clustersOutput[i].getDataPoint(j)).getY()+"--"+(v.indexOf(clustersOutput[i].getDataPoint(j))+1)+"--";
			b=s.getBytes();
			bos.write(b);
			bos.flush();
			s1=")\r\n";
			b1=s1.getBytes();
			bos.write(b1);
			bos.flush();
		     }
		      System.out.println("Cluster"+(i+1)+"successfully written");
		}

	  if (cj instanceof CURE){
		for(i=0; i<clustersOutput.length; i++){
		         s="----------------CLUSTER "+(i+1)+" RepPoints----------------\r\n";
		         b=s.getBytes();	
		         bos.write(b);
		         bos.flush();
		     for(j=0; j<clustersOutput[i].getNoOfRepPoints(); j++){
  			s1="(";
			b1=s1.getBytes();
			bos.write(b1);
			bos.flush();
			s=""+(clustersOutput[i].getRepPoint(j)).getX();
			b=s.getBytes();
			bos.write(b);
			bos.flush();
			s1=",";
			b1=s1.getBytes();
			bos.write(b1);
			bos.flush();
			s=""+(clustersOutput[i].getRepPoint(j)).getY();
			b=s.getBytes();
			bos.write(b);
			bos.flush();
			s1=")\r\n";
			b1=s1.getBytes();
			bos.write(b1);
			bos.flush();
		     }
		      System.out.println("Cluster"+(i+1)+" RepPoints successfully written");
		}
                             }//if CURE
	         }catch(Exception ex){	
		ex.printStackTrace();
	        }			
	}else if(ae.getSource()==showGraph){
		       cj.showGraph();
	}
     }
}

⌨️ 快捷键说明

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