当前位置: 技术问答>java相关
我用jar做个可执行文件,出现问题?
来源: 互联网 发布时间:2015-10-27
本文导语: ButtonTest.java原代码: import java.awt.*; import java.awt.event.*; import javax.swing.*; class ButtonPanel extends JPanel implements ActionListener { public ButtonPanel() { yellowButton = new JButton("Yellow")...
ButtonTest.java原代码:
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
class ButtonPanel extends JPanel
implements ActionListener
{
public ButtonPanel()
{
yellowButton = new JButton("Yellow");
blueButton = new JButton("Blue");
redButton = new JButton("Red");
add(yellowButton);
add(blueButton);
add(redButton);
yellowButton.addActionListener(this);
blueButton.addActionListener(this);
redButton.addActionListener(this);
}
public void actionPerformed(ActionEvent evt)
{
Object source = evt.getSource();
Color color = getBackground();
if(source == yellowButton) color = Color.yellow;
else if(source == blueButton) color = Color.blue;
else if(source == redButton) color = Color.red;
setBackground(color);
repaint();
}
private JButton yellowButton;
private JButton blueButton;
private JButton redButton;
}
class ButtonFrame extends JFrame
{
public ButtonFrame()
{
setTitle("ButtonTest");
setSize(300,200);
addWindowListener(new WindowAdapter()
{
public void windowClosing(WindowEvent e)
{
System.exit(0);
}
});
Container contentPane = getContentPane();
contentPane.add(new ButtonPanel());
}
}
public class ButtonTest
{
public static void main(String[] args)
{
JFrame frame = new ButtonFrame();
frame.show();
}
};
解译后
H:amstudyJavabutton>javac ButtonTest.java
H:amstudyJavabutton>java ButtonTest
成功。
生成ButtonTest.class,ButtonFrame.class ,ButtonPanel.class ButtonFrame$.class.
manifest.mft原代码:
Manifest-Version: 1.0
Main-Class: ButtonTest
Classpath: .Button.jar
(保证前后无空格)
制作jar文件
H:amstudyJavabutton>jar cvfm Button.jar manifest.mft ButtonTest.class ButtonFrame.class ButtonFrame$1.class ButtonPanel.class
标明清单(manifest)
增加:ButtonTest.class(读入= 348) (写出= 263)(压缩了 24%)
增加:ButtonFrame.class(读入= 663) (写出= 437)(压缩了 34%)
增加:ButtonFrame$1.class(读入= 471) (写出= 330)(压缩了 29%)
增加:ButtonPanel.class(读入= 1183) (写出= 668)(压缩了 43%)
但是,结果,双击,没反应。
谁能告诉我怎么回事?
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
class ButtonPanel extends JPanel
implements ActionListener
{
public ButtonPanel()
{
yellowButton = new JButton("Yellow");
blueButton = new JButton("Blue");
redButton = new JButton("Red");
add(yellowButton);
add(blueButton);
add(redButton);
yellowButton.addActionListener(this);
blueButton.addActionListener(this);
redButton.addActionListener(this);
}
public void actionPerformed(ActionEvent evt)
{
Object source = evt.getSource();
Color color = getBackground();
if(source == yellowButton) color = Color.yellow;
else if(source == blueButton) color = Color.blue;
else if(source == redButton) color = Color.red;
setBackground(color);
repaint();
}
private JButton yellowButton;
private JButton blueButton;
private JButton redButton;
}
class ButtonFrame extends JFrame
{
public ButtonFrame()
{
setTitle("ButtonTest");
setSize(300,200);
addWindowListener(new WindowAdapter()
{
public void windowClosing(WindowEvent e)
{
System.exit(0);
}
});
Container contentPane = getContentPane();
contentPane.add(new ButtonPanel());
}
}
public class ButtonTest
{
public static void main(String[] args)
{
JFrame frame = new ButtonFrame();
frame.show();
}
};
解译后
H:amstudyJavabutton>javac ButtonTest.java
H:amstudyJavabutton>java ButtonTest
成功。
生成ButtonTest.class,ButtonFrame.class ,ButtonPanel.class ButtonFrame$.class.
manifest.mft原代码:
Manifest-Version: 1.0
Main-Class: ButtonTest
Classpath: .Button.jar
(保证前后无空格)
制作jar文件
H:amstudyJavabutton>jar cvfm Button.jar manifest.mft ButtonTest.class ButtonFrame.class ButtonFrame$1.class ButtonPanel.class
标明清单(manifest)
增加:ButtonTest.class(读入= 348) (写出= 263)(压缩了 24%)
增加:ButtonFrame.class(读入= 663) (写出= 437)(压缩了 34%)
增加:ButtonFrame$1.class(读入= 471) (写出= 330)(压缩了 29%)
增加:ButtonPanel.class(读入= 1183) (写出= 668)(压缩了 43%)
但是,结果,双击,没反应。
谁能告诉我怎么回事?
|
双机没反映是因为在windows下没有跟java关联起来
|
运行命令
java -jar Button.jar
java -jar Button.jar
|
manifest.mf
我记得应该是这个文件吧
放在meta-inf目录下
里面还应该有一行
Manifest-Version: 1.0
Main-Class: com.hoten.Main.Main
来指定你的主类
我记得应该是这个文件吧
放在meta-inf目录下
里面还应该有一行
Manifest-Version: 1.0
Main-Class: com.hoten.Main.Main
来指定你的主类