爱心技术专栏专题

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

摘录:爱心 来源:爱心 加入时间:2006年09月14日
摘要:
JAVA实现:文件选择器中运行.exe文件
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import java.io.*;


class Chooserrun extends JFrame implements ActionListener
{
JButton button; …

转载:转载请保留本信息,本文来自
http://www.51dibs.com
/html/2006/article/info/a_89c49d0cbcfd8695.htm

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

站点:爱心种子小博士 关键字:JAVA实现:文件选择器中运行.exe文

   
JAVA实现:文件选择器中运行.exe文件
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);
}
}

客户服务中心信箱:[email protected] [email protected] 网站地图

声明

合作伙伴: