• Tidak ada hasil yang ditemukan

Programming in Java

N/A
N/A
Protected

Academic year: 2024

Membagikan "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)

IntroducEon

•  Swing is a framework that provides more

powerful and flexible GUI components than does the AWT

•  As a result, it is the GUI that has been widely used by Java programmers

•  Introduced in 1997, Swing was included as part of the Java FoundaEon Classes (JFC)

•  Beginning with Java 1.2, Swing (and the rest of the JFC) was fully integrated into Java

•  Swing is built on the foundaEon of AWT

(4)

AWT vs Swing

•  Swing was a response to deficiencies present in Java’s original GUI subsystem: the Abstract

Window Toolkit.

•  The AWT defines a basic set of controls,

windows, and dialog boxes that support a usable, but limited graphical interface

•  One reason for the limited nature of the AWT is that it translates its various visual components into their corresponding, plaZorm-specific

equivalents, or peers

•  This means that the look and feel of a component is defined by the plaZorm, not by Java

•  Because the AWT components use naEve code

resources, they are referred to as heavyweight.

(5)

AWT – Problems

•  The use of naEve peers led to several problems

– Because of variaEons between operaEng systems, a component might look, or even act, differently on different plaZorms. This threatens the

philosophy of Java: write once, run anywhere – The look and feel of each component was fixed

(because it is defined by the plaZorm) and could not be (easily) changed

– The use of heavyweight components caused some frustraEng restricEons. For example, a

heavyweight component was always opaque.

(6)

Key Swing Features

•  Swing Components Are Lightweight

– With very few excepEons, Swing components are lightweight

– This means that they are wri_en enErely in Java and do not map directly to plaZorm-specific peers – They are more efficient and more flexible

– The look and feel of each component is

determined by Swing, not by the underlying operaEng system

– Each component will work in a consistent manner across all plaZorms.

(7)

Key Swing Features

•  Swing Supports a Pluggable Look and Feel

Swing supports a pluggable look and feel (PLAF)

– Because each Swing component is rendered by Java code, it is possible to separate the look and feel of a component from the logic of the component

It becomes possible to change the way that a

component is rendered without affecEng any of its other aspects

•  Advantages

– Define a look and feel that is consistent across all plaZorms and it can be changed dynamically at run Eme.

Referensi

Dokumen terkait

This means that the financial statements of cash waqf funds issued by LAZISMU Pamekasan and KSPPS Nuri East Java are still lacking from the financial

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

• This is done by using addMouseListener and addMouseMo4onListener , which, as menFoned, are members of Component • They are shown here: void addMouseListenerMouseListener ml

A Better Way As observant Java programmers, the minute we set our eyes on this code we’d quickly turn it into something more concise and easier to read, like this:

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

H Computer Science, Semester II Lab Exercises BHCS03 – Programming in JAVA Attempt the following questions as part of JAVA Lab class today: 1.. Write a program that will count

Explain how SQL statements are written and executed in JAVA write the basic steps of JDBC.. 13 What is an