我编写了一个小程序,在dos中打jar包时提示
E:\java\java100\运行>jar cvfm 自制启动.jar mybao3 2.txt
java.io.FileNotFoundException: mybao3 (拒绝访问。)
at java.io.FileInputStream.open(Native Method)
at java.io.FileInputStream.<init>(FileInputStream.java:106)
at java.io.FileInputStream.<init>(FileInputStream.java:66)
at sun.tools.jar.Main.run(Main.java:131)
at sun.tools.jar.Main.main(Main.java:1022)
程序代码:
package mybao3;
import java.awt.*;
import javax.swing.*;
import java.awt.event.*;
import javax.swing.event.*;
import java.io.*;
import java.net.*;
public class RunDemo extends JFrame
{
private JButton b1,b2,b3,b4,b5,b6;
JPanel jp2=new JPanel();
JLabel jl=new JLabel();
public static void main(String []args)
{
JFrame.setDefaultLookAndFeelDecorated(true);
new RunDemo();
}
public RunDemo()
{
JPanel jp=new JPanel();
ImageIcon im=new ImageIcon("按钮/dota01.jpg");
Dimension d=Toolkit.getDefaultToolkit().getScreenSize();//获取屏幕大小
int h=d.height;
int w=d.width;
//int w = getSize().width;//获取窗体宽度
//int h = getSize().height;//获取窗体高度
//jp.setLayout(new GridLayout(3,2));
b1=new JButton("启动DOTA");
b2=new JButton("启动改建");
b3=new JButton("11搞起");
b4=new JButton("dota地图下载");
b5=new JButton("dota英雄出装");
b6=new JButton("下次再来");
b1.setToolTipText("点击这个按钮,启动游戏");
b2.setToolTipText("点击这个按钮,启动改建");
b3.setToolTipText("点击这个按钮,启动11平台");
b4.setToolTipText("点击这个按钮,下载最新dota地图");
b5.setToolTipText("点击这个按钮,查看英雄出装");
b6.setToolTipText("点击这个按钮,退出");
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
b1.setBounds(100,150,100,50);
b2.setBounds(200,150,100,50);
b3.setBounds(300,150,100,50);
b4.setBounds(100,250,100,50);
b5.setBounds(200,250,100,50);
b6.setBounds(300,250,100,50);
jp.add(b1);
jp.add(b2);
jp.add(b3);
jp.add(b4);
jp.add(b5);
jp.add(b6);
huiZhi();
//setLayout(new FlowLayout());
jp.setLayout(null);
getContentPane().add(jp);
//getContentPane().add(jp2);
int x=(h-300)/2;
int y=(w-800)/2;
event();
setIconImage(im.getImage());
setBounds(x,y,500,500);
// setResizable(false);//不可调整大小
// pack();
setVisible(true);
}
void huiZhi()
{
try
{
ImageIcon im2=createImageIcon("按钮/123.jpg");
jl.setIcon(im2);
}
catch(Exception e)
{
System.out.println(e.toString());
}
}
protected static ImageIcon createImageIcon(String path)
{
java.net.URL img=RunDemo.class.getResource(path);
return new ImageIcon(img);
}
public void event()
{
b1.addActionListener(new ActionListener()
{
public void actionPerformed(ActionEvent e)
{
Runtime r=Runtime.getRuntime();
try
{
r.exec("E:\\魔兽争霸3冰封王座\\War3.exe");
}
catch(IOException ex)
{
System.out.println(ex.toString());
}
}
});
b2.addActionListener(new ActionListener()
{
public void actionPerformed(ActionEvent e)
{
Runtime r=Runtime.getRuntime();
try
{
r.exec("E:\\魔兽争霸3冰封王座\\WarKey.exe");
}
catch(IOException ex)
{
System.out.println(ex.toString());
}
}
});
b3.addActionListener(new ActionListener()
{
public void actionPerformed(ActionEvent e)
{
Runtime r=Runtime.getRuntime();
try
{
r.exec("C:\\Program Files\\11game\\11Game.exe");
}
catch(IOException ex)
{
System.out.println(ex.toString());
}
}
});
b4.addActionListener(new ActionListener()
{
public void actionPerformed(ActionEvent e)
{
Runtime r=Runtime.getRuntime();
try
{
r.exec("explorer http://dota.uuu9.com/list_224.shtml");
}
catch(IOException ex)
{
System.out.println(ex.toString());
}
}
});
b5.addActionListener(new ActionListener()
{
public void actionPerformed(ActionEvent e)
{
Runtime r=Runtime.getRuntime();
try
{
r.exec("explorer http://fight.pcgames.com.cn/warcraft/dota/heros/");
}
catch(IOException ex)
{
System.out.println(ex.toString());
}
}
});
b6.addActionListener(new ActionListener()
{
public void actionPerformed(ActionEvent e)
{
System.exit(0);
}
});
}
}
这是为什么啊。 |
|