|
 
 

Tutorial 8 - Applet and Swings

An applet is a program written in the Java programming language that can be included in an HTML page, much in the same way an image is included in a page. When you use a Java technology-enabled browser to view a page that contains an applet, the applet's code is transferred to your system and executed by the browser's Java Virtual Machine (JVM).

This lesson discusses the basics of applets, how to develop applets that interact richly with their environment, and how to deploy applets. An applet is a special kind of Java program that a browser enabled with Java technology can download from the internet and run. An applet is typically embedded inside a web page and runs in the context of a browser. An applet must be a subclass of the java.applet.Applet class. The Applet class provides the standard interface between the applet and the browser environment.

To create a Java program with a graphical user interface (GUI), you need to learn about Swing. The Swing toolkit includes a rich set of components for building GUIs and adding interactivity to Java applications. Swing includes all the components you would expect from a modern toolkit: table controls, list controls, tree controls, buttons, and labels. .An applet that will be using GUI components from Swing (Java's GUI toolkit) should extend the javax.swing.JApplet base class, which provides the best integration with Swing's GUI facilities.

   Most usage is the same as with Applet

  • JApplet inherits from Applet
  • init, start, stop, etc. unchanged.

   Main differences in use

  • Components go in the "content pane", not directly in the frame. Changing other properties (layout manager, background color, etc.) also apply to the content pane. Access content pane via getContentPane, or if you want to replace it with your container (e.g. a JPanel), use setContentPane.
  • Default layout manager is Border Layout (like Frame and JFrame), not Flow Layout (like Applet). This is really the layout manager of the content pane.
  • You get Java (Metal) look by default, so you have to explicitly switch if you want native look.
  • Do drawing in paint Component, not paint.
  • Double buffering turned on by default.
Watch the Video Tutorial on the Link Below



Download Source of Applet and Swings

   





 
Download Java In Easy Steps Video Tutorials