Eclipse generates Swing app and published with Java Web Start

zhaozj2021-02-16  212

Eclipse generates the basic procedure and example of SWING application

First, SWING project

1. Create a new project

Project -> Java-> Java project, then click "Next" to name "SwingTest" for the project, click "Finish".

2, create a new package

On the project established, click Right click, create a new-> package, name "SRC", click "Finish".

3, create a new class

On the package you just created, click Right click, create a new-> class, named "Buttondemo", click "Finish".

code show as below:

/ *

* Copyright Intec Dalian Center, All Rights Reserved

*

* Fushan University Education Research Activities, etc.

* Results デ タ タ ベ ス ス シ テム テム

*

* パ パ ケ ケ ジ:

* ク ラ ス: Buttondemo.java

*

* Benevo: Industrial Systems Dept. 0B6167

*

* バ ジョ ジョ ジョ: 1.00 2004-7-14

*

* /

Package SRC;

Import javax.swing. *;

Import javax.swing.border. *;

Import javax.swing.event. *;

Import java.awt. *;

Import java.awt.event. *;

// the main program class

Public Class Buttondemo Extends Jframe Implements ActionListener {

// GUI Objects Displayed in the frame window

ButtonGroup Group; // Groups Radio Buttons

JRADIOBUTTON RedButton; // First Radio Button

Jradiobutton WhiteButton; // Second Radio Button

Jradiobutton Bluebutton; // Third Radio Button

JPanel Colorbox; // Displays Selected Color

JCheckBox showcolorsbutton; // first Check Box

JCheckbox EXITONCLOSEBUTTON; // Second Check Box

JButton EXITBUTTON; // Plain Button

// Constructor Initializes The Gui Objects and Panels

Public buttemo () {

// SELECT LOCAL SYSTEM LOOK AND Feel

Try {

UIManager.SetLookAndfeel (UIManager.getsystemLookandfeelclassName ());

// uimanager.getcrossplatformlookandfeelclassname ());

} catch (exception e) {

}

// end Program When Window Closes

AddWindowListener (New Windowadapter () {

Public void windowClosing (WindowEvent E) {

System.exit (0);

}

});

/ / =========================================================================================================================================================================================== ========== // Radio Button Panel and GUI Objects

/ / =========================================================================================================================================================================================== ==========

// Create Radio Button Panel and an inner Pane

// TO HELP Display The Gui Objects Neatly

JPanel Radiopane = new jPanel ();

JPanel InnerRadiopane = new jPanel ();

Radiopane.setBorder (BorderFactory.createBevelBorder (bevelborder.raised);

Innerradiopane.setLayout (New BoxLayout (InnerRadiopane, BoxLayout.y_AXIS);

InnerRadiopane.setBorder (BorderFactory.createemptyBorder (10, 10, 10, 10));

// Construct the Radio Group and ITS Buttons

// All Button Events Go to the Program ActionListener

Group = new buttonGroup ();

RedButton = New Jradiobutton ("red");

WhiteButton = New Jradiobutton ("White");

BlueButton = New Jradiobutton ("Blue");

WhiteButton.SetSelected (true); // select one button

RedButton.addActionListener (this); // see actionPerformed ()

WhiteButton.AddActionListener (this);

BlueButton.AddActionListener (this);

Group.add (redbutton); // the group ensures this one

Group.add (WhiteButton); // Button is SELECTED, THE Previously

Group.add (bluebutton); // SELECTED Button IS Turned Off

// Construct A Small Panel for Displaying The SELECTED Color

Colorbox = new jPanel ();

ColorBox.SetBackground; Color.White;

ColorBox.SetPreferredSize (New Dimension (50, 50));

// add the gui Objects to the inner radio pane

Innerradiopane.Add (RedButton);

InnerRadiopane.Add (WhiteButton);

InnerRadiopane.Add (BlueButton);

Innerradiopane.Add (Box.Createrigidarea (New Dimension (0, 25))); // Spacer

InnerRadiopane.Add (ColorBox);

// add the inner Pane to the raised radio panel (Left Side)

Radiopane.Add (InnerRadiopane);

/ / =========================================================================================================================================================================================== ==========

// Check Box Panel and GUI Objects

/ / =========================================================================================================================================================================================== ==========

// Create Check Box Panel and an inner panel

// for a neat Appearance

JPanel Checkpane = New jPanel ();

JPanel InnerCheckpane = New jPanel ();

Checkpane.SetBorder (BorderFactory.createBevelBorder (bevelborder.raised);

InnerCheckPane.setLayout (New BoxLayout (InnerCheckpane, BoxLayout.y_AXIS);

InnerCheckpane.setBorder (BorderFactory.createemptyBorder (10, 10, 10, 10));

// Create the "show colors" Check Box Object and

// enable or disable the color radio buttons

ShowcolorsButton = New JCheckbox ("Show Colors");

ShowcolorsButton.SetSelected (True);

ShowcolorsButton.addchangelistener (New ChangeListener () {

Public void statechanged (changingeevent e) {boolean t = showcolorsbutton.isselected ();

Redbutton.senabled (t); // enable or disable all

WhiteButton.setenabled (t); // Radio Buttons Depending On

Bluebutton.setenabled (T); // State of Check Box

}

});

// Create the "exit onclose" Check Box Object and

// enable or disable the exit program button

EXITONCLOSEBUTTON = New JCHECKBOX ("EXIT On Close");

EXITONCLOSEBUTTON.ADDCHANGELISTENER (NEW CHANGELISTENER () {

Public Void StateChanged (ChangeEvent E) {

Boolean t = exitonclosebutton.isselected ();

EXITBUTTON.SETENABLED (T);

}

});

// Create the Plain "EXIT Program" Button

// and ITS Action Event Listener

EXITBUTTON = New JButton ("exit program");

EXITBUTTON.SETENABED (FALSE); // Initially Disabled

EXITBUTTON.ADDACTIONLISTENER (NEW ActionListener () {

Public Void ActionPerformed (ActionEvent E) {

System.exit (0);

}

});

// add the buttons to the inner Pane

InnerCheckpane.Add (showcolorsbutton);

InnerCheckpane.Add (ExitonClosebutton);

InnerCheckpane.Add (Box.Createrigidarea (New Dimension (0, 50));

InnerCheckpane.Add (ExitButton);

// add the inner pane to the raised check box panel

Checkpane.Add (InnerCheckpane);

// add the panels and gui Objects to the frame's content pane

Container content = getContentPane ();

Content.setLayout (New GridLayout (1, 3, 2, 2));

Content.add (Radiopane);

Content.add (Checkpane);

}

// Change The Colorbox Background Color When User

// selects a radio button.

Public Void ActionPerformed (ActionEvent E) {

Color C;

RedButton.isSelected ())

C = color.red;

Else if (WhiteButton.isSelected ())

C = color.white;

Else

C = color.blue;

Colorbox.setBackground;

}

// main program simply constructs the button // Application Object, and the Sizes and shows the window

Public static void main (String [] args) {

Buttondemo App = New Buttondemo ();

App.SetTitle ("Button and Check Box Demo);

App.SetSize (320, 240);

app.show ();

}

}

4. Run new class

Run -> Run to -> 2.java app

If everything is normal, OK, you can pack it.

5, play jar package

Right click on the project -> Export -> JAR file, the next step, then select the storage path, as shown in Figure 1. Then continue the next step to select the class of the program entry point. Figure 2. Then complete it. JAR package is already good.

figure 1

figure 2

Second, configure Java Web Start

1. Under the Tomcat's WebApps folder, create a folder, name "SwingTest", then put our JAR package, put it in.

2, at the same time, built two files, one is index.html, one is index.jnlp

The content is as follows:

INDEX.HTML

Launch Application

Index.jnlp

helloworld </ title></p> <p><vendor> IBM - JWS EXAMPLE OF HelloWorld </ vendor></p> <p><Description> HelloWorld - Example of JWS </ Description></p> <p><Description Kind = "Short"> HelloWorld Example </ Description></p> <p></ information></p> <p><resources></p> <p><j2se version = "1.4" /></p> <p><jar href = "hello.jar" /></p> <p></ resources></p> <p><Application-Desc Main-Class = "src.Buttondemo" /></p> <p></ jnlp></p> <p>3. Under the Tomcat's conf folder, modify the server.xml file, add such words, and the specific path is modified according to the specific situation of the individual.</p> <p><Context path = "/ swingtest" reloadable = "true" docbase = "d: /jakarta-tomcat-4.1.30/webapps/swingtest" /></p> <p>OK, here we should be all configured, below, let us start Tomcat, and run the test. Enter http: // localhost: 8080 / swingtest / index.html in your browser, if there is no problem, the following figure should appear.</p> <p>If all this comes out, congratulations, a simple Java Web Start release Swing application has been completed successfully.</p></div><div class="text-center mt-3 text-grey"> 转载请注明原文地址:https://www.9cbs.com/read-7788.html</div><div class="plugin d-flex justify-content-center mt-3"></div><hr><div class="row"><div class="col-lg-12 text-muted mt-2"><i class="icon-tags mr-2"></i><span class="badge border border-secondary mr-2"><h2 class="h6 mb-0 small"><a class="text-secondary" href="tag-2.html">9cbs</a></h2></span></div></div></div></div><div class="card card-postlist border-white shadow"><div class="card-body"><div class="card-title"><div class="d-flex justify-content-between"><div><b>New Post</b>(<span class="posts">0</span>) </div><div></div></div></div><ul class="postlist list-unstyled"> </ul></div></div><div class="d-none threadlist"><input type="checkbox" name="modtid" value="7788" checked /></div></div></div></div></div><footer class="text-muted small bg-dark py-4 mt-3" id="footer"><div class="container"><div class="row"><div class="col">CopyRight © 2020 All Rights Reserved </div><div class="col text-right">Processed: <b>0.058</b>, SQL: <b>9</b></div></div></div></footer><script src="./lang/en-us/lang.js?2.2.0"></script><script src="view/js/jquery.min.js?2.2.0"></script><script src="view/js/popper.min.js?2.2.0"></script><script src="view/js/bootstrap.min.js?2.2.0"></script><script src="view/js/xiuno.js?2.2.0"></script><script src="view/js/bootstrap-plugin.js?2.2.0"></script><script src="view/js/async.min.js?2.2.0"></script><script src="view/js/form.js?2.2.0"></script><script> var debug = DEBUG = 0; var url_rewrite_on = 1; var url_path = './'; var forumarr = {"1":"Tech"}; var fid = 1; var uid = 0; var gid = 0; xn.options.water_image_url = 'view/img/water-small.png'; </script><script src="view/js/wellcms.js?2.2.0"></script><a class="scroll-to-top rounded" href="javascript:void(0);"><i class="icon-angle-up"></i></a><a class="scroll-to-bottom rounded" href="javascript:void(0);" style="display: inline;"><i class="icon-angle-down"></i></a></body></html><script> var forum_url = 'list-1.html'; var safe_token = 'JpsGYjvTSzS259QnAnzZY2354My9UlGklEl8brwihzkq9upheuPcbW_2Fjr5vI1izeizZv9yMxCtxgoHfsx6QXTw_3D_3D'; var body = $('body'); body.on('submit', '#form', function() { var jthis = $(this); var jsubmit = jthis.find('#submit'); jthis.reset(); jsubmit.button('loading'); var postdata = jthis.serializeObject(); $.xpost(jthis.attr('action'), postdata, function(code, message) { if(code == 0) { location.reload(); } else { $.alert(message); jsubmit.button('reset'); } }); return false; }); function resize_image() { var jmessagelist = $('div.message'); var first_width = jmessagelist.width(); jmessagelist.each(function() { var jdiv = $(this); var maxwidth = jdiv.attr('isfirst') ? first_width : jdiv.width(); var jmessage_width = Math.min(jdiv.width(), maxwidth); jdiv.find('img, embed, iframe, video').each(function() { var jimg = $(this); var img_width = this.org_width; var img_height = this.org_height; if(!img_width) { var img_width = jimg.attr('width'); var img_height = jimg.attr('height'); this.org_width = img_width; this.org_height = img_height; } if(img_width > jmessage_width) { if(this.tagName == 'IMG') { jimg.width(jmessage_width); jimg.css('height', 'auto'); jimg.css('cursor', 'pointer'); jimg.on('click', function() { }); } else { jimg.width(jmessage_width); var height = (img_height / img_width) * jimg.width(); jimg.height(height); } } }); }); } function resize_table() { $('div.message').each(function() { var jdiv = $(this); jdiv.find('table').addClass('table').wrap('<div class="table-responsive"></div>'); }); } $(function() { resize_image(); resize_table(); $(window).on('resize', resize_image); }); var jmessage = $('#message'); jmessage.on('focus', function() {if(jmessage.t) { clearTimeout(jmessage.t); jmessage.t = null; } jmessage.css('height', '6rem'); }); jmessage.on('blur', function() {jmessage.t = setTimeout(function() { jmessage.css('height', '2.5rem');}, 1000); }); $('#nav li[data-active="fid-1"]').addClass('active'); </script>