I was programming applets but the first applet worked whereas my second applet which asks the user to input two numbers and then prints their sum isn't working and the second problem is that even the JNLP file isn't working for any file. It says Invalid Path.
Here is my applet code:
import java.awt.Graphics;
import javax.swing.JOptionPane;
import javax.swing.JApplet;
public class AdditionApplet extends JApplet
{
private float sum;
public void init()
{
String s1 = JOptionPane.showInputDialog("Enter first Number");
String s2 = JOptionPane.showInputDialog("Enter second number");
float num1 = Float.parseFloat(s1);
float num2 = Float.parseFloat(s2);
sum = num1 + num2;
}
public void paint( Graphics g){
super.paint(g);
g.drawRect(25, 25, 250, 40);
g.drawString("The sum is: " + sum, 50, 50);
}
}
And here is my JNLP file:
<?xml version="1.0" encoding="UTF-8"?>
<jnlp codebase=.
href="AdditionApplet.jnlp"
>
<information>
<title>Addition Applet</title>
<vendor>Oracle Corporation</vendor>
<shortcut>
<desktop/>
</shortcut>
<offline-allowed/>
</information>
<resources>
<java version="1.6+"/>
<jar href="Addition.jar" main="true"/>
</resources>
<applet-desc name="AdditionApplet"
main-class="AdditionApplet"
width="400"
height="400">
</applet-desc>
</jnlp>