An applet is defined with the following two classes:
Import Javax.swing.japplet;public class Videoapplet extends japplet{public void init () {Add (New Videopanel ());}}
Import Java.awt.dimension;import Java.awt.gridlayout;import Java.awt.event.itemevent;import Java.awt.event.itemlistener;import Javax.swing.jcombobox;import Javax.swing.jlabel;import Javax.swing.JPanel; Import Javax.swing.jtextfield;public class Videopanel extends JPanel implements itemlistener{private static final int DEF Ault_width = 300;private static final int default_height = 200;private jcombobox<object> JCB1 = null;private JTextFi Eld JTF = Null;private double price[] = {0.0, 2.5, 2.0, 2.0, 2.0};p rivate int num = 0;public Videopanel () {setlayout (new GridLayout (10, 1)); JLabel jl1 = new JLabel ("Movie List:"); String videos[] = {"None", "Flying Around", "by My Side", "My Love", "Apple Dream",};JCB1 = new jcombobox<object> (videos); j tf = new JTextField (); jtf.seteditable (false); Jtf.settext ("Movie Price $" + price[num]); add (jl1); add (JCB1); add (JTF); Jcb1.additemlistener (this);} public void itemstatechanged (ItemEvent e) {num = Jcb1.getselectedindex (); Jtf.settext ("Movie Price $" + price[NUM]);} Public Dimension getPreferredSize () {return new Dimension (Default_width, default_height);}}
After compiling, you get two class files:
There is also a test.html file that reads as follows:
The next step is to run the applet in the browser.
Running applets in the browser requires the appropriate plugins to be installed, just follow the prompts to install them. However, in general, you can still not run applets, then you need to run the applet's URL into the "List of operational URLs," the operation is as follows:
Go to "Control Panel", click "Program (Programs)", double click "Java":
In the run-out Java Control Panel, select Security, and then click:
Click on "Edit Site list" to put the URL to run the applet, the result is as follows:
Then access the http://localhost:8080/test.html in the browser, there will be the following prompt:
When you click "Run", the applet will function as follows:
Running applets in the browser