Discussion point. Oracle Java documentation. PDF

Title Discussion point. Oracle Java documentation.
Author Rupam Tagore
Course Programming 2
Institution University of the People
Pages 2
File Size 55.8 KB
File Type PDF
Total Downloads 31
Total Views 131

Summary

Discussion assignment. Read it carefully to get the full insight....


Description

According to java documentation, “the architecture of Swing is designed so that you may change the "look and feel" (L&F) of your application's GUI (see A Swing Architecture Overview). "Look" refers to the appearance of GUI widgets (more formally, JComponents) and "feel" refers to the way the widgets behave.

Swing's architecture enables multiple L&Fs by separating every component into two distinct classes: a JComponent subclass and a corresponding ComponentUI subclass. For example, every JList instance has a concrete implementation of ListUI (ListUI extends ComponentUI). The ComponentUI subclass is referred to by various names in Swing's documentation—"the UI," "component UI," "UI delegate," and "look and feel delegate" are all used to identify the ComponentUI subclass.

Most developers never need to interact with the UI delegate directly. For the most part, the UI delegate is used internally by the JComponent subclass for crucial functionality, with cover methods provided by the JComponent subclass for all access to the UI delegate. For example, all painting in JComponent subclasses is delegated to the UI delegate. By delegating painting, the 'look' can vary depending upon the L&F.

It is the responsibility of each L&F to provide a concrete implementation for each of the ComponentUI subclasses defined by Swing. For example, the Java Look and Feel creates an instance of MetalTabbedPaneUI to provide the L&F for JTabbedPane. The actual creation of the UI delegate is handled by Swing for you—for the most part you never need to interact directly with the UI delegate.”

There is a beautiful below to the that in action. In the following example, LookAndFeelDemo.java, you can experiment with different Look and Feels. The program creates a simple GUI with a button and a label. Every time you click the button, the label increments.

You can change the L&F by changing the LOOKANDFEEL constant on line 18. The comments on the preceding lines tell you what values are acceptable:

// Specify the look and feel to use by defining the LOOKANDFEEL constant // Valid values are: null (use the default), "Metal", "System", "Motif", // and "GTK" final static String LOOKANDFEEL = "Motif";

Here the constant is set to "Motif", which is a L&F that will run on any platform (as will the default, "Metal"). "GTK+" will not run on Windows, and "Windows" will run only on Windows. If you choose a L&F that will not run, you will get the Java, or Metal, L&F.

In the section of the code where the L&F is actually set, you will see several different ways to set it, as discussed above:

if (LOOKANDFEEL.equals("Metal")) { lookAndFeel = UIManager.getCrossPlatformLookAndFeelClassName(); // an alternative way to set the Metal L&F is to replace the // previous line with: // lookAndFeel = "javax.swing.plaf.metal.MetalLookAndFeel"; You can verify that both arguments work by commenting/un-commenting the two alternatives.

The benefits of using java are:     

It provides the user friendly interface. Java GUI provides the nice set of tools for the programmer to develop GUI and easy to map the program. programs become intuitive. Attractive GUI capture much attention. Better GUI provides the immediate effect of the program to the user.

References How to Se the look and feel. Oracle Java documentation. Retrieved from https://docs.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html...


Similar Free PDFs