The difference between swing and AWT small applications

Source: Internet
Author: User

Perhaps you used to use AWT to design a graphical user interface (GUI), how do you feel? Now that JAVA2 offers a swing pack that shows you a richer set of features, the interface you use to design it will be friendlier, so let's take a look.

Before you designed a small application to expand the applet (Java.applet.Applet); Now to use swing packs, you want to extend JApplet (Javax.swing.JApplet) Let's look at an example of an extended JApplet applet and then analyze the difference.

Cheng? as follows:

(JAppletTest.java)
import javax.swing.*;
import java.awt.*;
import java.event.*;
public class JAppletTest extends JApplet {
 public void init() {
  Container contentPane = getContentPane();
  Icon icon = new ImageIcon("swing.gif", "A GIF on a swing");
  JLabel label = new JLabel("Swing!", icon, SwingConstants.CENTER);
  contentPane.add(label, BorderLayout.CENTER);
 }
}

There are a few things to note:

1, the last line of the program is not necessary, because the JApplet class uses an instance of BorderLayout as the layout Manager for its content pane, The default constraint for BorderLayout is Borderlayout.center, so the last line of the program is not required.

2, the default layout manager of the applet is FlowLayout, and flowlayout default constraint is Flowlayout.left, which is one of the most significant differences.

3, JApplet is a container containing only one component, this component is an instance of JRootPane, and JRootPane contains a container called the content pane.

4, the content pane, which contains all the content related to a particular small application. That is, small applications must add all components to the content pane, rather than adding them directly to a small application.

5, we should not directly set the layout manager for small applications.

6, japplet instance can have a menu bar, it is specified by the Setjmenubar method, but the AWT small application can not.

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.