活学活用,打开/重启Tomcat的小程序~

来源:互联网 发布:四维设计软件 编辑:程序博客网 时间:2024/05/20 05:06

无论是.bat文件还是快捷方式都无法拖到任务栏,每次要打开或重启Tomcat都要回到桌面,真是太麻烦啦!活学活用,用swing做一个桌面小程序!使用命令行时发现直接打开原文件打不开,但是快捷方式可以。

package StartTomcat;import java.awt.event.ActionEvent;import java.awt.event.ActionListener;import java.io.IOException;import javax.swing.ImageIcon;import javax.swing.JButton;import javax.swing.JFrame;public class StartTomcat extends JFrame {JButton start, restart;public StartTomcat() {setSize(240, 180);setLocationRelativeTo(null);setResizable(false);setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);setLayout(null);start = new JButton("start Tomcat", new ImageIcon("d:/Java/tomcat/start.png"));restart = new JButton("restart Tomcat", new ImageIcon("d:/Java/tomcat/restart.png"));start.setBounds(40, 20, 160, 50);restart.setBounds(40, 80, 160, 50);add(start);add(restart);start.addActionListener(new ActionListener() {public void actionPerformed(ActionEvent e) {try {Runtime.getRuntime().exec("rundll32 url.dll FileProtocolHandler file://"+ "d:/Java/tomcat/startupbyCMD");} catch (IOException ex) {ex.printStackTrace();}}});restart.addActionListener(new ActionListener() {public void actionPerformed(ActionEvent e) {try {Runtime.getRuntime().exec("rundll32 url.dll FileProtocolHandler file://"+ "d:/Java/tomcat/restartbyCMD");} catch (IOException ex) {ex.printStackTrace();}}});setVisible(true);}public static void main(String[] args) {new StartTomcat();}}


完成后打包为jar文件。图标太丑,但是只能先创建快捷方式再改自定义图标,然而并没有卵用,因为任务栏的图标还是原来的,看着更容易混淆啦~~

tomcat和我的程序分不清。。。

0 0
原创粉丝点击