Running applets in the browser

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.