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

📄 grawriter.java

📁 Java实现的常用数据结构算法
💻 JAVA
字号:
 package graph;
 import java.io.*;
 import java.util.*;
 import java.awt.*;
 public class GraWriter{
    public	FileWriter fw;
 	public  GraWriter(String filename){
 		try{			
 		fw=new FileWriter(filename+".obj",true);			
 		}catch(IOException e){
        e.printStackTrace();
         }
 		
 	}
 	public void close(){
 		   try{fw.close();}
           catch(IOException e){}
 	}
 	public void newFile(String filename){
		try{
		int i=0;
		while(new File(filename+i+".obj").exists()){
			i++;
		}			
		fw=new FileWriter(filename+i+".obj",true);			
 		}catch(IOException e){
        e.printStackTrace();
         }
 	}
 	public void write(Point v)throws IOException{
 			fw.write("v "+v.x+" "+v.y+"\n");
 		
 	}
 	public void write(int i ,int j)throws IOException{
 			fw.write("l "+i+" "+j+"\n");
 		
 	}
 	public void write(boolean[][] link)throws IOException{
 		int len=link.length;
 		for(int i=0;i<len;i++){
 			for(int j=0;j<len;j++){
 				if(link[i][j]==true)
 				write(i,j);
 			}
 		}
 	}
 	public void write(Object[] obj)throws IOException{
 		int len=obj.length;
 		Point[] ps=new Point[len];
 		for(int i=0;i<len;i++){
 		 ps[i]=(Point)obj[i];
 		}
 		for(int i=0;i<len;i++){
 		 write(ps[i]);
 		}
 		
 	}
 	public void write(Point[] points)throws IOException{
 		int len=points.length;
 		fw.write("size "+len+"\n");
 		for(int i=0;i<len;i++){
 		 write(points[i]);
 		}
 	}
 	public void write(Vector v)throws IOException{
 		int len=v.size();
 		int i=0;
 		while(i<len){
 			write((Point)v.elementAt(i));
 		}
 	}
 	public void writeEd(Point[] v)throws IOException{
 		int len=v.length;
 		for(int i=0;i<len;i++){
 		 write(v[i].x,v[i].y);
 		}
 	}
 	public void save(DrawPanel panel){
 		newFile("temp");
 		try{
 			write(panel.points);
 			write(panel.links);
 			fw.close();
 		}catch(IOException e){
        e.printStackTrace();
         }
        
 	}
 	public void write(Graph graph){
 		try{
 		write(graph.labels);
 		write(graph.edges);
 		//fw.close();
 		}catch(IOException e){
        e.printStackTrace();
          }
 	}

 }

⌨️ 快捷键说明

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