http://www.blogjava.net/rethink/archive/2009/02/04/253265.html

Recently, I came across a lot of articles about javafx, javafx that previously developed for the inconvenience to the client that there are some procedures improve, so also try to develop a small application to see whether javafx job in the future use.

First, the development of the purpose of

Based on the b / s structure, search the client list of available serial port.

Second, development environment

NetBeans IDE 6.5 for JavaFX 1.0, tomcat5, rxtx 2.1-7r2

Third, related resources

1, java framework serial, download rxtx 2.1-7r2.

2, know the serial operation, the reference http://rxtx.qbang.org/wiki/index.php/Examples

3, development tools, download NetBeans IDE 6.5 for JavaFX 1.0

4, know javafx, reference http://developers.sun.com.cn/javafx/docs/tutorials/

Other resources a little

Four, coding

1, first of all, the development of operational procedures DiscoveringAvailablePorts.java serial

public static List getAvailableSerialPortsName () (
List result = new ArrayList ();
Enumeration thePorts = CommPortIdentifier.getPortIdentifiers ();
while (thePorts.hasMoreElements ()) (
CommPortIdentifier com = (CommPortIdentifier) thePorts.nextElement ();
switch (com.getPortType ()) (
case CommPortIdentifier.PORT_SERIAL:
try (
CommPort thePort = com.open ( "CommUtil", 50);
thePort.close ();
result.add (com.getName ());
) Catch (PortInUseException e) (
System.out.println ( "Port," + com.getName () + ", is in use.");
) Catch (Exception e) (
System.err.println ( "Failed to open port" + com.getName ());
e.printStackTrace ();
)
)
)
return result;
)
Note: RXTXcomm.jar copy to:% JAVA_HOME% "jre" lib "ext
rxtxSerial.dll copy to:% JAVA_HOME% "jre" bin

And in the development of the introduction of the project RXTXcomm.jar

2, then the development of interface procedures SerialConfig.fx

var portNames =
new DiscoveringAvailablePorts (). getAvailableSerialPortsName ();

var label = SwingLabel (text: "serial port:");

var combobox = SwingComboBox (
width: 100
items: [
SwingComboBoxItem (
text: "Please select"),
for (idx in portNames) (
SwingComboBoxItem (
text: idx.toString ())
)
]
selectedIndex: 0);

var button = SwingButton (text: "Save");

Stage (
title: "Components"
width: 344
height: 240
visible: true
scene: Scene (
fill: Color.CORNSILK
content: VBox (
translateX: 10
translateY: 30
spacing: 20
content: [
HBox (
spacing: 10
content: [label, combobox, HBox (translateX: 40 content: [button])]
)
]
)
)
)

Note: The development of the above procedures, the set up at javafx project in NB, the name of javafxTutorial.

3, the final one of the most simple set up web projects and procedures for the preparation of the page index.jsp.

<body>
This is my JSP page. <br>
<script Src="http://dl.javafx.com/dtfx.js"> </ script>
<script>
javafx (
(
archive: "<% = path%> / javafxTutorial.jar",
width: 400,
height: 200,
code: "com.howelltech.SerialConfig",
name: "javafxTutorial"
)
);
</ Script>
</ Body>

Friday, the deployment of

1, NB property in the project, select the Run configuration Run in Browser; at select Application Configuration Self Signed Jar, other optional.

2, NB project directory, in the dist directory, there javafxTutorial.html, javafxTutorial.jar, javafxTutorial_browser.jnlp three documents and the lib directory includes a file RXTXcomm.jar. Put all the files in this directory are copied to the web works just well set up with the same path index.jsp.

Six test

1, the server side, if we do not start tomcat can directly see the effect of the implementation of both javafxTutorial.html. If you start tomcat, it must be amended in javafxTutorial_browser.jnlp the port number, and want to use the same tomcat.

2, the client must be rxtxSerial.dll copy to% JRE_HOME% "bin under the direct access to the server then you can link.

Development is completed, the overall feel than the applet to facilitate javafx, whether coding or deployment. However, when the development of javafx have a lot of inconvenient places, such as the IDE does not support current graphical development, although support for the occasional drag some controls, but not enough, after all, the visual code; In addition, javafx procedures after the run on the client or some slow. After all, is a new technology, also need to slowly adapt to ah.

In addition, the questions left over from the two to see what everyone has a good way.

1, about the need to copy the client rxtxSerial.dll problem, there is no more convenient way.

2, javafx project packing problem, there is no better way to make a package such as, other pages can be called directly.