Hi guys,
My name is Jay Sun and I am new this this Forums. I am told by my professor to migrate from this Java application to Java Web Start.
I read all about it but I'm still struggling. I have an example program called Traffic Light. From the TrafficLight class,
I created a .jar file from .java file. The jar file runs perfectly fine and I created a .jnlp file using this.
<?xml version="1.0" encoding="UTF-8"?>
<jnlp spec="1.0+"
codebase="file:///C:/Documents and Settings/HP_Administrator/Desktop/TrafficLight" href="TrafficLight.jnlp">
<information>
<title>Traffic Light</title>
<vendor>Java Developer Connection</vendor>
<homepage href="/jdc" />
<description>Demonstration of JNLP</description>
</information>
<offline-allowed/>
<resources>
<j2se version="1.6+" />
<jar href="TraffcLight.jar"/>
</resources>
<application-desc main-class="Traffic Light" />
</jnlp>
That's my .jnlp file.
My .java file is below it.
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import javax.swing.event.*;
public class TrafficLightFrame extends JFrame {
// These are the window's components
private JRadioButton[] buttons = new JRadioButton[3];
private JButton advButton;
private JProgressBar progressBar;
private JSlider slider;
private JComboBox actionList;
private JCheckBox autoButton;
public TrafficLightFrame(String title) {
super(title);
buildWindow();
setDefaultCloseOperation(EXIT_ON_CLOSE);
setSize(400, 250);
}
// Add all components to the frame's panel
private void buildWindow() {
GridBagLayout layout = new GridBagLayout();
GridBagConstraints constraints = new GridBagConstraints();
setLayout(layout);
// Add all the labels
JLabel label = new JLabel("Manual");
constraints.gridx = 0;
constraints.gridy = 0;
constraints.gridwidth = 1;
constraints.gridheight = 1;
constraints.weightx = 0;
constraints.weighty = 0;
constraints.fill = GridBagConstraints.NONE;
constraints.anchor = GridBagConstraints.NORTHWEST;
constraints.insets = new Insets(5, 5, 0, 0);
layout.setConstraints(label, constraints);
add(label);
label = new JLabel("Action");
constraints.gridx = 1;
layout.setConstraints(label, constraints);
add(label);
label = new JLabel("Advance");
constraints.gridx = 2;
layout.setConstraints(label, constraints);
add(label);
label = new JLabel("Timer Progress");
constraints.gridx = 0;
constraints.gridy = 4;
layout.setConstraints(label, constraints);
add(label);
// Add the Radio Buttons
ButtonGroup lights = new ButtonGroup();
JPanel aPanel = new JPanel();
aPanel.setLayout(new BoxLayout(aPanel, BoxLayout.Y_AXIS));
aPanel.setBackground(Color.black);
for (int i=0; i<3; i++) {
buttons[i] = new JRadioButton("", false);
buttons
.setBackground(Color.black);
lights.add(buttons[i]);
aPanel.add(buttons[i]);
}
buttons[0].setText("Red");
buttons[1].setText("Yellow");
buttons[2].setText("Green");
buttons[0].setForeground(Color.red);
buttons[1].setForeground(Color.yellow);
buttons[2].setForeground(Color.green);
constraints.gridx = 0;
constraints.gridy = 1;
constraints.gridheight = 3;
constraints.fill = GridBagConstraints.BOTH;
layout.setConstraints(aPanel, constraints);
add(aPanel);
// Make the Actions List
String[] actions = {"Stop", "Yield", "Go"};
actionList = new JComboBox(actions);
constraints.gridx = 1;
constraints.gridy = 1;
constraints.gridheight = 1;
constraints.weightx = 1;
constraints.fill = GridBagConstraints.HORIZONTAL;
layout.setConstraints(actionList, constraints);
add(actionList);
// Make the Slider
slider = new JSlider(JSlider.HORIZONTAL, 0, 20, 1);
slider.setMajorTickSpacing(5);
slider.setMinorTickSpacing(1);
slider.setPaintTicks(true);
slider.setPaintLabels(true);
constraints.gridx = 1;
constraints.gridy = 3;
layout.setConstraints(slider, constraints);
add(slider);
// Add the auto checkbox button
autoButton = new JCheckBox("Auto Advance");
constraints.gridx = 1;
constraints.gridy = 2;
constraints.fill = GridBagConstraints.BOTH;
layout.setConstraints(autoButton, constraints);
add(autoButton);
// Add the Advance Picture button
advButton = new JButton(new ImageIcon("RedLight.jpg"));
constraints.gridx = 2;
constraints.gridy = 1;
constraints.gridheight = 3;
constraints.weightx = 0;
constraints.weighty = 1;
constraints.fill = GridBagConstraints.BOTH;
constraints.insets = new Insets(5, 5, 0, 5);
layout.setConstraints(advButton, constraints);
add(advButton);
// Add the progress bar
progressBar = new JProgressBar(JProgressBar.HORIZONTAL, 0, 8);
constraints.gridx = 0;
constraints.gridy = 5;
constraints.gridwidth = 3;
constraints.gridheight = 1;
constraints.weightx = 1;
constraints.weighty = 2;
constraints.fill = GridBagConstraints.BOTH;
constraints.insets = new Insets(5, 5, 5, 5);
layout.setConstraints(progressBar, constraints);
add(progressBar);
}
public static void main(String args[]) {
TrafficLightFrame frame = new TrafficLightFrame("Traffic Light");
frame.setVisible(true);
}
}When I launch the Java appliation, I get the dialog box error saying "Application Error - Unable to launch the application"
Exception:
com.sun.deploy.net.FailedDownloadException: Unable to load resource: file:/C:/Documents and Settings/HP_Administrator/Desktop/TrafficLight/TrafficLight.jnlp
at com.sun.deploy.net.DownloadEngine.actionDownload(Unknown Source)
at com.sun.deploy.net.DownloadEngine.getCacheEntry(Unknown Source)
at com.sun.deploy.net.DownloadEngine.getResourceCacheEntry(Unknown Source)
at com.sun.deploy.net.DownloadEngine.getResourceCacheEntry(Unknown Source)
at com.sun.deploy.net.DownloadEngine.getResource(Unknown Source)
at com.sun.deploy.net.DownloadEngine.getResource(Unknown Source)
at com.sun.javaws.Launcher.updateFinalLaunchDesc(Unknown Source)
at com.sun.javaws.Launcher.prepareToLaunch(Unknown Source)
at com.sun.javaws.Launcher.launch(Unknown Source)
at com.sun.javaws.Main.launchApp(Unknown Source)
at com.sun.javaws.Main.continueInSecureThread(Unknown Source)
at com.sun.javaws.Main$1.run(Unknown Source)
at java.lang.Thread.run(Unknown Source)
Wrapped Exception
java.io.FileNotFoundException: C:\Documents and Settings\HP_Administrator\Desktop\TrafficLight\TrafficLight.jnlp (The system cannot find the path specified)
at java.io.FileInputStream.open(Native Method)
at java.io.FileInputStream.<init>(Unknown Source)
at java.io.FileInputStream.<init>(Unknown Source)
at sun.net.www.protocol.file.FileURLConnection.connect(Unknown Source)
at com.sun.deploy.net.BasicHttpRequest.doRequest(Unknown Source)
at com.sun.deploy.net.BasicHttpRequest.doRequest(Unknown Source)
at com.sun.deploy.net.BasicHttpRequest.doGetRequest(Unknown Source)
at com.sun.deploy.net.DownloadEngine.actionDownload(Unknown Source)
at com.sun.deploy.net.DownloadEngine.getCacheEntry(Unknown Source)
at com.sun.deploy.net.DownloadEngine.getResourceCacheEntry(Unknown Source)
at com.sun.deploy.net.DownloadEngine.getResourceCacheEntry(Unknown Source)
at com.sun.deploy.net.DownloadEngine.getResource(Unknown Source)
at com.sun.deploy.net.DownloadEngine.getResource(Unknown Source)
at com.sun.javaws.Launcher.updateFinalLaunchDesc(Unknown Source)
at com.sun.javaws.Launcher.prepareToLaunch(Unknown Source)
at com.sun.javaws.Launcher.launch(Unknown Source)
at com.sun.javaws.Main.launchApp(Unknown Source)
at com.sun.javaws.Main.continueInSecureThread(Unknown Source)
at com.sun.javaws.Main$1.run(Unknown Source)
at java.lang.Thread.run(Unknown Source)