WEB开发网
开发学院软件开发Java 图种生成器 阅读

图种生成器

 2012-06-08 10:18:35 来源:WEB开发网   
核心提示: 将种子文件(当然不只是种子文件)压缩成zip,再利用jpg图片文件生成图种,这样只需保存图片后,改图片后缀为zip就可以得到种子的压缩文件了.import java.awt.Button;import java.awt.FileDialog;import java.awt.Frame;import java.awt.

 将种子文件(当然不只是种子文件)压缩成zip,再利用jpg图片文件生成图种,这样只需保存图片后,改图片后缀为zip就可以得到种子的压缩文件了.

import java.awt.Button;
import java.awt.FileDialog;
import java.awt.Frame;
import java.awt.GridLayout;
import java.awt.TextField;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;


public class jpgAndZip extends Frame {
	 
	public static void main(String[] args) {
		new jpgAndZip().launchFrame();
	}
	
	public void launchFrame(){
		final TextField tfZip = new TextField("文件名和路径不能含有空格、逗号等字符");
		final TextField tfJpg = new TextField("文件名和路径不能含有空格、逗号等字符");
		final TextField tfFile = new TextField();
		Button zip = new Button("请选择zip文件");
		Button jpg = new Button("请选择jpg文件");
		Button act = new Button("生成文件");
		final FileDialog zipDial = new FileDialog(this,"选择zip文件");
		final FileDialog jpgDial = new FileDialog(this,"选择jpg文件");
		
		this.setLayout(new GridLayout(3,3));
		
		this.add(zip);
		this.add(tfZip);
		this.add(jpg);
		this.add(tfJpg);
		this.add(act);
		this.add(tfFile);
		
		zip.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				zipDial.show();
				if(zipDial.getFile() !=null){
					tfZip.setText(zipDial.getDirectory()+zipDial.getFile());
				}
			}
		});
		
		jpg.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				jpgDial.show();
				if(jpgDial.getFile() != null){
					tfJpg.setText(jpgDial.getDirectory()+jpgDial.getFile());
				}
			}
		});
		
		act.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent arg0) {
				Runtime r=Runtime.getRuntime();
				try{
					if(jpgDial.getFile() != null && zipDial.getFile() !=null){
						String createfile = zipDial.getDirectory() + zipDial.getFile().substring(0, zipDial.getFile().lastIndexOf('.')) + ".jpg";
						String s="cmd /c copy /b " + jpgDial.getDirectory() + jpgDial.getFile() + "+" + zipDial.getDirectory() + zipDial.getFile() +" " + createfile ;
						r.exec(s); 
						tfFile.setText(createfile);
					}else{
						tfFile.setText("出错啦!请先选择文件!");
					}
				}catch(Exception e){ 
					System.out.println("错误:"+e.getMessage()); 
					e.printStackTrace(); 
				}
			}
		});		
		
		this.setLocation(500, 250);
		this.setSize(470, 150);
		this.setVisible(true);
		
		addWindowListener(new WindowAdapter() {
			public void windowClosing(WindowEvent e) {
				System.exit(0);
			}
		});
		
	}
}

Tags:生成器

编辑录入:爽爽 [复制链接] [打 印]
赞助商链接