·您的位置: 首页 » 资源教程 » 编程开发 » JAVA、JSP » JAVA实现:文件选择器中运行.EXE文件

JAVA实现:文件选择器中运行.EXE文件

类别: JSP教程  评论数:0 总得分:0
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import java.io.*;


class Chooserrun extends JFrame implements ActionListener
{
JButton button;
JTextArea text;
JTextPane textpane;
FileInputStream readfile;
JScrollPane scroll;
// Container con;
Jpanel con;
JFileChooser chooser=new JFileChooser();
//==========================================

public Chooserrun()
{
super("有文件选择器的窗口");
button=new JButton("打开文件选择器");
button.addActionListener(this);
textpane=new JTextPane();
JFileChooser chooser=new JFileChooser();
scroll=new JScrollPane(textpane);
// JFileChooser chooser=new JFileChooser();
//不能在此处初始化!
this.setSize( new Dimension(200,200));
setVisible(true);
con=(Jpanel)this.getContentPane();
con.add(button,BorderLayout.NORTH);
con.add(scroll,BorderLayout.CENTER);
addWindowListener(new WindowAdapter() {
public void windowClosing(WindowEvent e) {
dispose();System.exit(0);}});
}
//====================================================
public void actionPerformed(ActionEvent e)
{
if(e.getSource()==button)
{
String s;
int state =chooser.showOpenDialog(null);
File file=chooser.getSelectedFile();
{
try
{ Runtime ce=Runtime.getRuntime();
ce.exec(file.toString());
}
catch(IOException e1)
{
e1.printStackTrace();
}
}
}
}
//--------------------------------------
}
import javax.swing.UIManager;
import java.awt.*;
public class mytest
{
public static void main(String args[])
{
Chooserrun run=new Chooserrun();
run.pack();
Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
Dimension frameSize = run.getSize();
if (frameSize.height > screenSize.height) {
frameSize.height = screenSize.height;
}
if (frameSize.width > screenSize.width) {
frameSize.width = screenSize.width;
}
run.setLocation((screenSize.width - frameSize.width) / 2, (screenSize.height - frameSize.height) / 2);
}
} 
-= 资 源 教 程 =-
文 章 搜 索
关键词:
类型:
范围:
纯粹空间 softpure.com
Copyright © 2006-2008 暖阳制作 版权所有
QQ: 15242663 (拒绝闲聊)  Email: faisun@sina.com
 纯粹空间 - 韩国酷站|酷站欣赏|教程大全|资源下载|免费博客|美女壁纸|设计素材|技术论坛   Valid XHTML 1.0 Transitional
百度搜索 谷歌搜索 Alexa搜索 | 粤ICP备19116064号-1