• Tidak ada hasil yang ditemukan

PDF Programming in Java

N/A
N/A
Protected

Academic year: 2024

Membagikan "PDF Programming in Java"

Copied!
7
0
0

Teks penuh

(1)

Programming in Java

CBCS BHCS03

By Parul Chachra

(2)

Chapter 31

Introducing Swing

Reference: Schildt, H. Java: The Complete Reference. 7th ediEon. McGraw-

Hill EducaEon

(3)

Top – Level Containers

•  The first are top-level containers:

–  JFrame –  JApplet –  JWindow –  JDialog.

•  These containers do not inherit JComponent

•  They do, however, inherit the AWT classes Component and Container

•  Most commonly used top-level container for applicaEons is JFrame

•  The one used for applets is JApplet.

(4)

Top – Level Containers

•  Features of Top-level containers

•  The top-level containers are heavyweight which makes these containers a special case in the Swing component library

•  A top-level container must be at the top of a containment hierarchy

•  A top-level container is not contained within any other container

•  Furthermore, every containment hierarchy must begin with a top-level container

(5)

Top – Level Containers

•  Each top-level container defines a set of panes

•  At the top of the hierarchy is an instance of JRootPane.

•  JRootPane is a lightweight container whose purpose is to manage the other panes

•  The panes that comprise the root pane are called the glass pane, the content pane, and the layered pane

•  The glass pane is the top-level pane. By default, it is a transparent instance of JPanel.

•  The glass pane enables you to manage mouse events that affect the enEre container (rather than an individual control) or to paint over any other component, for example

(6)

Top – Level Containers

•  The layered pane is an instance of JLayeredPane

•  The layered pane allows components to be given a depth value

•  The layered pane holds the content pane and the (opEonal) menu bar

•  The pane with which your applicaEon will interact the most is the content pane, because this is the pane to which you will add visual components

•  In other words, when you add a component, such as a buVon, to a top-level container, you will add it to the content pane

•  By default, the content pane is an opaque instance of

JPanel.

(7)

Swing Packages

Referensi

Dokumen terkait

After reading and working through the code in this book, you'll have a deep understanding of Java 9 modularity, its features, the impact on the platform, and how you can use this

JLabel and ImageIcon • NoFce that icons are specified by objects of type Icon, which is an interface defined by Swing • The easiest way to obtain an icon is to use the ImageIcon class

A Simple Swing ApplicaEon • Swing programs differ from both the console-based programs and the AWT-based programs, for example, – They use a different set of components and a different

AdjustmentEvent Class • There is an integer constant, ADJUSTMENT_VALUE_CHANGED, that indicates that a change has occurred • Here is one AdjustmentEvent constructor:

Responding to Controls • Except for labels, which are passive, all controls generate events when they are accessed by the user • For example, when the user clicks on a push buQon,

Color Methods • You can obtain the red, green, and blue components of a color independently using getRed , getGreen , and getBlue , shown here: int getRed int getGreen int

Adapter Classes • MyMouseAdapter extends MouseAdapter and overrides the mouseClicked method • The other mouse events are silently ignored by code inherited from the MouseAdapter

Keyword What It Does abstract Indicates that the details of a class, a method, or an interface are given elsewhere in the code.. assert Tests the truth of a condition that the