高手求助,Java运行~·
怎么把他弄成可以双击执行的jar文件啊,急急急``import java.awt.*;
import javax.swing.*;
import java.awt.event.*;
import *;
import javax.swing.event.*;
import java.util.*; //Date needed
import
public class MyNotePad extends JFrame {
File file = null;
Color color = Color.black;
GraphicsEnvironment getFont = GraphicsEnvironment.getLocalGraphicsEnvironment();
Font []fonts = getFont.getAllFonts();
JTextPane text = new JTextPane(); //面板
JFileChooser filechooser = new JFileChooser(); //文件选择
JColorChooser colorchooser = new JColorChooser(); //颜色选择
JDialog about = new JDialog(this); //弹出对话框
JMenuBar menubar = new JMenuBar(); //菜单
JToolBar toolbar = new JToolBar(); // 工具栏
/** Creates a new instance of MyNotePad */
public MyNotePad() {
initTextPane();//面板
initMenu();//菜单
initAboutDialog();//关于对话框
initToolBar();//工具栏
}
//----------------------------------------------
//面板初始化
void initTextPane(){
setFont(new Font("Times New Roman",Font.PLAIN,12));
getContentPane().add( new JScrollPane(text));
}
//------------------------------------------------
//菜单按钮和下拉菜单定义
JMenu menus[]= new JMenu[]
{
new JMenu("文件"),
new JMenu("编辑"),
new JMenu("查看"),
new JMenu("工具"),
new JMenu("帮助"),
};
JMenuItem menuitems [][] =new JMenuItem[][]
{
{
new JMenuItem("新建"),
new JMenuItem("打开..."),
new JMenuItem("保存..."),
new JMenuItem("Exit")
},
{
new JMenuItem("Copy"),
new JMenuItem("Cut"),
new JMenuItem("Paste"),
new JMenuItem("选择全部"),
new JMenuItem("Color...")
},
{
new JMenuItem("格式"),
new JMenuItem("字体")
},
{
new JMenuItem("MS 记事本"),
new JMenuItem("MS 计算器"),
new JMenuItem("修改注册表")
},
{
new JMenuItem("About")
}
};
//---------------------------------------------------
//------------------------------------------------------
//菜单初始化
void initMenu(){
for(int i=0;i<menus.length;i++)
{
menubar.add(menus[i]);
for(int j=0;j<menuitems[i].length;j++)
{
menus[i].add(menuitems[i][j]);
menuitems[i][j].addActionListener(action);
}
}
this.setJMenuBar(menubar);
}
//--------------------------------------------------
//-----------------------------------------------
//事件处理
ActionListener action = new ActionListener()
{
public void actionPerformed(ActionEvent e)
{
JMenuItem wf = (JMenuItem)e.getSource();
String id = wf.getText();
if(id.equals("新建")){
Date date=new Date();
text.setText(date.toString());
file = null;
}
else if(id.equals("打开...")){
if(file != null)
filechooser.setSelectedFile(file);
int returnVal = filechooser.showOpenDialog(MyNotePad.this);
if(returnVal == JFileChooser.APPROVE_OPTION){
file = filechooser.getSelectedFile();
openFile();
}
}
else if(id.equals("保存...")){
if (file!=null)
filechooser.setSelectedFile(file);
int returnVal = filechooser.showSaveDialog(MyNotePad.this);
if(returnVal == JFileChooser.APPROVE_OPTION){
file = filechooser.getSelectedFile();
saveFile();
}
}
else if(id.equals("Exit")){
System.exit(0);}
else if(id.equals("Cut")){
text.cut();
}else if(id.equals("Copy")){
text.copy();
}else if(id.equals("Paste")){
text.paste();
}else if(id.equals("选择全部")){
text.selectAll();
}
else if(id.equals("Color...")){
color = JColorChooser.showDialog(MyNotePad.this,"",color);
text.setForeground(color);
}
else if(id.equals("格式")){
}
else if(id.equals("字体")){
}
else if(id.equals("MS 记事本")){
try{
String command = "notepad.exe";
Process child = Runtime.getRuntime().exec(command);
}
catch (IOException ex) {
}
}
else if(id.equals("MS 计算器")){
try{
String command = "calc.exe";
Process child = Runtime.getRuntime().exec(command);
}
catch (IOException ex){
}
}
else if(id.equals("修改注册表")){
try{
String command = "regedit.exe";
Process child = Runtime.getRuntime().exec(command);
}
catch(IOException ex){
}
}
else if(id.equals("About")){
about.setSize(250,150);
about.setVisible(true);
}
}
};
//-------------------------------------------------------------------------------
//保存文件
void saveFile()
{
try{
FileWriter fw = new FileWriter(file);
fw.write(text.getText());
fw.close();
}
catch(Exception e)
{
e.printStackTrace();
}
}
//---------------------------------------------------------------
//打开文件
void openFile()
{
try{
FileReader fr = new FileReader(file);
int len = (int) file.length();
char [] buffer = new char[len];
fr.read(buffer,0,len);
fr.close();
text.setText(new String(buffer));
}
catch(Exception e)
{
e.printStackTrace();
}
}
//--------------------------------------------------------------
//弹出对话框初始化
void initAboutDialog(){
about.setTitle("关于... ");
about.getContentPane().setBackground(Color.white );
about.getContentPane().add(new JLabel(" 简易文字编辑器!作者:了凡"));
about.setModal(true);
}
//---------------------------------------------------------------
//工具栏的定义以及初始化
JButton [] buttons = new JButton[]
{
new JButton("",new ImageIcon("copy.jpg")),
new JButton("",new ImageIcon("cut.jpg")),
new JButton("",new ImageIcon("paste.jpg")),
new JButton("",new ImageIcon("MS1.jpg")),
new JButton("",new ImageIcon("MS2.jpg")),
};
//
void initToolBar(){
for(int i=0; i<buttons.length;i++)
toolbar.add(buttons[i]);
buttons[0].setToolTipText("copy");
buttons[0].addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent e){
text.copy();
}
});
buttons[1].setToolTipText("cut");
buttons[1].addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent e){
text.cut();
}
});
buttons[2].setToolTipText("paste");
buttons[2].addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent e){
text.paste();
}
});
buttons[3].setToolTipText("MS 记事本");
buttons[3].addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent e){
try{
String command = "notepad.exe";
Process child = Runtime.getRuntime().exec(command);
}
catch (IOException ex){
}
}
});
buttons[4].setToolTipText("MS 计算器");
buttons[4].addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent e){
try{
String command = "calc.exe";
Process child = Runtime.getRuntime().exec(command);
}
catch (IOException ex){
}
}
});
this.getContentPane().add(toolbar,BorderLayout.NORTH);
}
public static void main(String s[]){
MyNotePad wff= new MyNotePad();
wff.setTitle("简易文字编辑器");
wff.setSize(600,400);
wff.setVisible(true);
wff.addWindowListener(new WindowAdapter(){ //监听窗体按钮
public void windowClosing(WindowEvent e){
System.exit(0);
}
});
}
}