ITeye博客

javawebstart 开发实例

chenhua_1984 · 2010-11-30 16:42 · java · 编程语言 · 应用服务器 · 中间件 · Tomcat · Swing · J2SE · Markdown

1环境要求

 

 个人电脑上需安装JRE1.4以上版本。

 服务端用TOMCAT等中间件服务器用来发布javawebstart应用。

 

2开发方法

示例JAVA程序。

/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package lwj;

import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPasswordField;
import javax.swing.JTextField;

/**
 *
 * @author lwj
 */
public class FirstSwing extends JFrame{
    private JLabel jLabelUserName;
    private JLabel jLabelPassword;
    private JTextField jTextFieldUserName;
    private JPasswordField jpfPassword;
    private JButton jBUttonEnter;
    private JButton jButtonCancel;
    public FirstSwing(){
        this.setLayout(null);
        this.jLabelUserName=new JLabel("用户名:");
        this.jLabelPassword=new JLabel("密码:");
        this.jTextFieldUserName=new JTextField();
        this.jpfPassword=new JPasswordField();
        this.jBUttonEnter=new JButton("确定");
        this.jButtonCancel=new JButton("取消");
        this.jLabelUserName.setBounds(10,20,80,20);
        this.jLabelPassword.setBounds(10,50,80,20);
        this.jTextFieldUserName.setBounds(100,20,150,20);
        this.jpfPassword.setBounds(100,50,150,20);
        this.jBUttonEnter.setBounds(80,90,60,20);
        this.jButtonCancel.setBounds(160,90,60,20);
        this.add(this.jLabelUserName);
        this.add(this.jLabelPassword);
        this.add(this.jTextFieldUserName);
        this.add(this.jpfPassword);
        this.add(this.jBUttonEnter);
        this.add(this.jButtonCancel);
        this.setBounds(330,250,300,150);
        this.setTitle("第一个Swing程序");
        this.setVisible(true);
        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);

        jBUttonEnter.setText("确认");
        jBUttonEnter.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jBUttonEnterActionPerformed(evt);
            }
        });
    }

    private void jBUttonEnterActionPerformed(java.awt.event.ActionEvent evt) {
        // TODO add your handling code here:
        this.jLabelUserName.setText("你单击了确认按钮");
    }

    public static void main(String args[]){
        FirstSwing mySwing=new FirstSwing();
    }

}

 

3打包成一个可执行的JAR

4编写JNLP文件

JNLP文件 写道

<?xml version="1.0" encoding="UTF-8"?>
<jnlp
spec="1.0+"
codebase="http://172.16.4.221:8080/ET299/"
href="calculator.jnlp"
>
<information>
<title>Calculator</title>
<vendor>Luo wenjie</vendor>
<homepage href=""/>
<description>A Calculator Powered JBCL</description>
<icon href="http://java.sun.com/images/getjava_med.gif"/>
<offline-allowed/>
</information>
<resources>
<j2se version="1.4+"/>
<jar href="JavaLibrary1.jar"/>
</resources>
<application-desc main-class="lwj.FirstSwing"/>
</jnlp>

 

 5把做好的JAR和JNLP文件整理成一个WEB目录,然后放入TOMCAT的WEBAPPS里面。

 6启动TOMCAT

 7访问JNLP文件

 

注意:如果有多个JAR,那么可以配置<jar href="JavaLibrary1.jar"/> 多个这样的JAR节点。还需要使用文件的签名,不然不能正常启动访问。。。。参考:

 

http://lopica.sourceforge.net/ref.html

评论(0)

暂无评论。

评论功能维护中,当前仅展示历史评论。