<s>
Swing	B-Language
is	O
a	O
GUI	B-Application
widget	B-Library
toolkit	I-Library
for	O
Java	B-Language
.	O
</s>
<s>
It	O
is	O
part	O
of	O
Oracle	B-Application
's	O
Java	B-Language
Foundation	I-Language
Classes	I-Language
(	O
JFC	O
)	O
an	O
API	B-Application
for	O
providing	O
a	O
graphical	B-Application
user	I-Application
interface	I-Application
(	O
GUI	B-Application
)	O
for	O
Java	B-Language
programs	O
.	O
</s>
<s>
Swing	B-Language
was	O
developed	O
to	O
provide	O
a	O
more	O
sophisticated	O
set	O
of	O
GUI	B-Application
components	O
than	O
the	O
earlier	O
Abstract	B-Language
Window	I-Language
Toolkit	I-Language
(	O
AWT	B-Language
)	O
.	O
</s>
<s>
Swing	B-Language
provides	O
a	O
look	B-Application
and	I-Application
feel	I-Application
that	O
emulates	O
the	O
look	B-Application
and	I-Application
feel	I-Application
of	O
several	O
platforms	B-Device
,	O
and	O
also	O
supports	O
a	O
pluggable	B-Language
look	I-Language
and	I-Language
feel	I-Language
that	O
allows	O
applications	O
to	O
have	O
a	O
look	B-Application
and	I-Application
feel	I-Application
unrelated	O
to	O
the	O
underlying	O
platform	O
.	O
</s>
<s>
It	O
has	O
more	O
powerful	O
and	O
flexible	O
components	O
than	O
AWT	B-Language
.	O
</s>
<s>
In	O
addition	O
to	O
familiar	O
components	O
such	O
as	O
buttons	O
,	O
check	O
boxes	O
and	O
labels	O
,	O
Swing	B-Language
provides	O
several	O
advanced	O
components	O
such	O
as	O
tabbed	O
panel	O
,	O
scroll	O
panes	O
,	O
trees	O
,	O
tables	O
,	O
and	O
lists	O
.	O
</s>
<s>
Unlike	O
AWT	B-Language
components	O
,	O
Swing	B-Language
components	O
are	O
not	O
implemented	O
by	O
platform-specific	O
code	O
.	O
</s>
<s>
Instead	O
,	O
they	O
are	O
written	O
entirely	O
in	O
Java	B-Language
and	O
therefore	O
are	O
platform-independent	O
.	O
</s>
<s>
In	O
December	O
2008	O
,	O
Sun	O
Microsystems	O
(	O
Oracle	B-Application
's	O
predecessor	O
)	O
released	O
the	O
CSS	B-Language
/	O
FXML	B-Language
based	O
framework	O
that	O
it	O
intended	O
to	O
be	O
the	O
successor	O
to	O
Swing	B-Language
,	O
called	O
JavaFX	B-Application
.	O
</s>
<s>
The	B-Language
Internet	I-Language
Foundation	I-Language
Classes	I-Language
(	O
IFC	O
)	O
were	O
a	O
graphics	B-Library
library	I-Library
for	O
Java	B-Language
originally	O
developed	O
by	O
Netscape	O
Communications	O
Corporation	O
and	O
first	O
released	O
on	O
December	O
16	O
,	O
1996	O
.	O
</s>
<s>
On	O
April	O
2	O
,	O
1997	O
,	O
Sun	O
Microsystems	O
and	O
Netscape	O
Communications	O
Corporation	O
announced	O
their	O
intention	O
to	O
incorporate	O
IFC	O
with	O
other	O
technologies	O
to	O
form	O
the	O
Java	B-Language
Foundation	I-Language
Classes	I-Language
.	O
</s>
<s>
The	O
"	O
Java	B-Language
Foundation	I-Language
Classes	I-Language
"	O
were	O
later	O
renamed	O
"	O
Swing.	O
"	O
</s>
<s>
Swing	B-Language
introduced	O
a	O
mechanism	O
that	O
allowed	O
the	O
look	B-Application
and	I-Application
feel	I-Application
of	O
every	O
component	O
in	O
an	O
application	O
to	O
be	O
altered	O
without	O
making	O
substantial	O
changes	O
to	O
the	O
application	O
code	O
.	O
</s>
<s>
The	O
introduction	O
of	O
support	O
for	O
a	O
pluggable	B-Language
look	I-Language
and	I-Language
feel	I-Language
allows	O
Swing	B-Language
components	O
to	O
emulate	O
the	O
appearance	O
of	O
native	O
components	O
while	O
still	O
retaining	O
the	O
benefits	O
of	O
platform	O
independence	O
.	O
</s>
<s>
Originally	O
distributed	O
as	O
a	O
separately	O
downloadable	O
library	O
,	O
Swing	B-Language
has	O
been	O
included	O
as	O
part	O
of	O
the	O
Java	B-Language
Standard	I-Language
Edition	I-Language
since	O
release	O
1.2	O
.	O
</s>
<s>
The	O
Swing	B-Language
classes	O
and	O
components	O
are	O
contained	O
in	O
the	O
package	B-Language
hierarchy	O
.	O
</s>
<s>
Development	O
of	O
Swing	B-Language
's	O
successor	O
,	O
JavaFX	B-Application
,	O
started	O
in	O
2005	O
,	O
and	O
it	O
was	O
officially	O
introduced	O
two	O
years	O
later	O
at	O
JavaOne	O
2007	O
.	O
</s>
<s>
JavaFX	B-Application
was	O
open-sourced	O
in	O
2011	O
and	O
,	O
in	O
2012	O
,	O
it	O
became	O
part	O
of	O
the	O
Oracle	B-Application
JDK	O
download	O
.	O
</s>
<s>
JavaFX	B-Application
is	O
replacing	O
Swing	B-Language
owing	O
to	O
several	O
advantages	O
,	O
including	O
being	O
more	O
lightweight	O
,	O
having	O
CSS	B-Language
styling	I-Language
,	O
sleek	O
design	O
controls	O
,	O
and	O
the	O
use	O
of	O
FXML	B-Language
and	O
Scene	O
Builder	O
.	O
</s>
<s>
In	O
2018	O
,	O
JavaFX	B-Application
was	O
made	O
a	O
part	O
of	O
the	O
OpenJDK	O
under	O
the	O
OpenJFX	B-Application
project	O
to	O
increase	O
the	O
pace	O
of	O
its	O
development	O
.	O
</s>
<s>
Members	O
of	O
the	O
Java	B-Language
Client	O
team	O
that	O
was	O
responsible	O
for	O
Swing	B-Language
included	O
James	O
Gosling	O
(	O
Architect	O
)	O
,	O
Rick	O
Levenson	O
(	O
manager	O
)	O
,	O
Amy	O
Fowler	O
&	O
Hans	O
Muller	O
(	O
co-technical	O
leads	O
)	O
,	O
Tom	O
Ball	O
,	O
Jeff	O
Dinkins	O
,	O
Georges	O
Saab	O
,	O
Tim	O
Prinzing	O
,	O
Jonni	O
Kanerva	O
,	O
and	O
Jeannette	O
Hung	O
&	O
Jim	O
Graham	O
(	O
2D	O
Graphics	O
)	O
.	O
</s>
<s>
Swing	B-Language
is	O
a	O
platform-independent	O
,	O
"	O
model	O
–	O
view	O
–	O
controller	O
"	O
GUI	B-Library
framework	I-Library
for	O
Java	B-Language
,	O
which	O
follows	O
a	O
single-threaded	B-Operating_System
programming	O
model	O
.	O
</s>
<s>
Additionally	O
,	O
this	O
framework	O
provides	O
a	O
layer	O
of	O
abstraction	O
between	O
the	O
code	O
structure	O
and	O
graphic	O
presentation	O
of	O
a	O
Swing-based	O
GUI	B-Application
.	O
</s>
<s>
Swing	B-Language
is	O
platform-independent	O
because	O
it	O
is	O
completely	O
written	O
in	O
Java	B-Language
.	O
</s>
<s>
Complete	O
documentation	O
for	O
all	O
Swing	B-Language
classes	O
can	O
be	O
found	O
in	O
the	O
for	O
Version	O
6	O
or	O
the	O
for	O
Version	O
8	O
.	O
</s>
<s>
Swing	B-Language
is	O
a	O
highly	O
modular-based	O
architecture	O
,	O
which	O
allows	O
for	O
the	O
"	O
plugging	O
"	O
of	O
various	O
custom	O
implementations	O
of	O
specified	O
framework	O
interfaces	B-Application
:	O
Users	O
can	O
provide	O
their	O
own	O
custom	O
implementation(s )	O
of	O
these	O
components	O
to	O
override	O
the	O
default	O
implementations	O
using	O
Java	B-Language
's	O
inheritance	O
mechanism	O
via	O
.	O
</s>
<s>
Swing	B-Language
is	O
a	O
component-based	O
framework	O
,	O
whose	O
components	O
are	O
all	O
ultimately	O
derived	O
from	O
the	O
class	O
.	O
</s>
<s>
Swing	B-Language
objects	O
asynchronously	O
fire	O
events	O
,	O
have	O
bound	O
properties	O
,	O
and	O
respond	O
to	O
a	O
documented	O
set	O
of	O
methods	O
specific	O
to	O
the	O
component	O
.	O
</s>
<s>
Swing	B-Language
components	O
are	O
JavaBeans	O
components	O
,	O
compliant	O
with	O
the	O
.	O
</s>
<s>
Swing	B-Language
's	O
heavy	O
reliance	O
on	O
runtime	O
mechanisms	O
and	O
indirect	O
composition	O
patterns	O
allows	O
it	O
to	O
respond	O
at	O
run	O
time	O
to	O
fundamental	O
changes	O
in	O
its	O
settings	O
.	O
</s>
<s>
For	O
example	O
,	O
a	O
Swing-based	O
application	O
is	O
capable	O
of	O
hot	B-Device
swapping	I-Device
its	O
user-interface	O
during	O
runtime	O
.	O
</s>
<s>
Furthermore	O
,	O
users	O
can	O
provide	O
their	O
own	O
look	B-Application
and	I-Application
feel	I-Application
implementation	O
,	O
which	O
allows	O
for	O
uniform	O
changes	O
in	O
the	O
look	B-Application
and	I-Application
feel	I-Application
of	O
existing	O
Swing	B-Language
applications	O
without	O
any	O
programmatic	O
change	O
to	O
the	O
application	O
code	O
.	O
</s>
<s>
Swing	B-Language
's	O
high	O
level	O
of	O
flexibility	O
is	O
reflected	O
in	O
its	O
inherent	O
ability	O
to	O
override	O
the	O
native	O
host	O
operating	B-General_Concept
system	I-General_Concept
(	O
OS	O
)	O
'	O
s	O
GUI	B-Application
controls	O
for	O
displaying	O
itself	O
.	O
</s>
<s>
Swing	B-Language
"	O
paints	O
"	O
its	O
controls	O
using	O
the	O
Java	B-Language
2D	I-Language
APIs	B-Application
,	O
rather	O
than	O
calling	O
a	O
native	O
user	O
interface	O
toolkit	O
.	O
</s>
<s>
Thus	O
,	O
a	O
Swing	B-Language
component	O
does	O
not	O
have	O
a	O
corresponding	O
native	O
OS	O
GUI	B-Application
component	O
,	O
and	O
is	O
free	O
to	O
render	O
itself	O
in	O
any	O
way	O
that	O
is	O
possible	O
with	O
the	O
underlying	O
graphics	O
GUIs	B-Application
.	O
</s>
<s>
However	O
,	O
at	O
its	O
core	O
,	O
every	O
Swing	B-Language
component	O
relies	O
on	O
an	O
AWT	B-Language
container	O
,	O
since	O
(	O
Swing	B-Language
's	O
)	O
extends	O
(	O
AWT	B-Language
's	O
)	O
Container	O
.	O
</s>
<s>
This	O
allows	O
Swing	B-Language
to	O
plug	O
into	O
the	O
host	O
OS	O
's	O
GUI	B-Application
management	O
framework	O
,	O
including	O
the	O
crucial	O
device/screen	O
mappings	O
and	O
user	O
interactions	O
,	O
such	O
as	O
key	O
presses	O
or	O
mouse	O
movements	O
.	O
</s>
<s>
Swing	B-Language
simply	O
"	O
transposes	O
"	O
its	O
own	O
(	O
OS-agnostic	O
)	O
semantics	O
over	O
the	O
underlying	O
(	O
OS-specific	O
)	O
components	O
.	O
</s>
<s>
So	O
,	O
for	O
example	O
,	O
every	O
Swing	B-Language
component	O
paints	O
its	O
rendition	O
on	O
the	O
graphic	O
device	O
in	O
response	O
to	O
a	O
call	O
to	O
component.paint( )	O
,	O
which	O
is	O
defined	O
in	O
(	O
AWT	B-Language
)	O
Container	O
.	O
</s>
<s>
But	O
unlike	O
AWT	B-Language
components	O
,	O
which	O
delegated	O
the	O
painting	O
to	O
their	O
OS-native	O
"	O
heavyweight	O
"	O
widget	O
,	O
Swing	B-Language
components	O
are	O
responsible	O
for	O
their	O
own	O
rendering	O
.	O
</s>
<s>
This	O
transposition	O
and	O
decoupling	O
is	O
not	O
merely	O
visual	O
,	O
and	O
extends	O
to	O
Swing	B-Language
's	O
management	O
and	O
application	O
of	O
its	O
own	O
OS-independent	O
semantics	O
for	O
events	O
fired	O
within	O
its	O
component	O
containment	O
hierarchies	O
.	O
</s>
<s>
Generally	O
speaking	O
,	O
the	O
Swing	B-Language
architecture	O
delegates	O
the	O
task	O
of	O
mapping	O
the	O
various	O
flavors	O
of	O
OS	O
GUI	B-Application
semantics	O
onto	O
a	O
simple	O
,	O
but	O
generalized	O
,	O
pattern	O
to	O
the	O
AWT	B-Language
container	O
.	O
</s>
<s>
Building	O
on	O
that	O
generalized	O
platform	O
,	O
it	O
establishes	O
its	O
own	O
rich	O
and	O
complex	O
GUI	B-Application
semantics	O
in	O
the	O
form	O
of	O
the	O
model	O
.	O
</s>
<s>
The	O
Swing	B-Language
library	O
makes	O
heavy	O
use	O
of	O
the	O
model	O
–	O
view	O
–	O
controller	O
software	O
design	O
pattern	O
,	O
which	O
conceptually	O
decouples	O
the	O
data	O
being	O
viewed	O
from	O
the	O
user	O
interface	O
controls	O
through	O
which	O
it	O
is	O
viewed	O
.	O
</s>
<s>
Because	O
of	O
this	O
,	O
most	O
Swing	B-Language
components	O
have	O
associated	O
models	O
(	O
which	O
are	O
specified	O
in	O
terms	O
of	O
Java	B-Language
interfaces	B-Application
)	O
,	O
and	O
the	O
programmers	O
can	O
use	O
various	O
default	O
implementations	O
or	O
provide	O
their	O
own	O
.	O
</s>
<s>
The	O
framework	O
provides	O
default	O
implementations	O
of	O
model	O
interfaces	B-Application
for	O
all	O
of	O
its	O
concrete	O
components	O
.	O
</s>
<s>
The	O
typical	O
use	O
of	O
the	O
Swing	B-Language
framework	O
does	O
not	O
require	O
the	O
creation	O
of	O
custom	O
models	O
,	O
as	O
the	O
framework	O
provides	O
a	O
set	O
of	O
default	O
implementations	O
that	O
are	O
transparently	O
,	O
by	O
default	O
,	O
associated	O
with	O
the	O
corresponding	O
child	O
class	O
in	O
the	O
Swing	B-Language
library	O
.	O
</s>
<s>
To	O
get	O
a	O
good	O
sense	O
of	O
the	O
potential	O
that	O
the	O
Swing	B-Language
architecture	O
makes	O
possible	O
,	O
consider	O
the	O
hypothetical	O
situation	O
where	O
custom	O
models	O
for	O
tables	O
and	O
lists	O
are	O
wrappers	O
over	O
DAO	O
and/or	O
EJB	B-Language
services	O
.	O
</s>
<s>
Typically	O
,	O
Swing	B-Language
component	O
model	O
objects	O
are	O
responsible	O
for	O
providing	O
a	O
concise	O
interface	O
defining	O
events	O
fired	O
,	O
and	O
accessible	O
properties	O
for	O
the	O
(	O
conceptual	O
)	O
data	O
model	O
for	O
use	O
by	O
the	O
associated	O
JComponent	O
.	O
</s>
<s>
Typically	O
,	O
these	O
events	O
are	O
model	O
centric	O
(	O
ex	O
:	O
a	O
"	O
row	O
inserted	O
"	O
event	O
in	O
a	O
table	O
model	O
)	O
and	O
are	O
mapped	O
by	O
the	O
JComponent	O
specialization	O
into	O
a	O
meaningful	O
event	O
for	O
the	O
GUI	B-Application
component	O
.	O
</s>
<s>
A	O
default	O
implementation	O
of	O
this	O
operates	O
on	O
a	O
two-dimensional	O
array	B-Data_Structure
.	O
</s>
<s>
The	O
view	O
component	O
of	O
a	O
Swing	B-Language
JComponent	O
is	O
the	O
object	O
used	O
to	O
graphically	O
represent	O
the	O
conceptual	O
GUI	B-Application
control	O
.	O
</s>
<s>
A	O
distinction	O
of	O
Swing	B-Language
,	O
as	O
a	O
GUI	B-Library
framework	I-Library
,	O
is	O
in	O
its	O
reliance	O
on	O
programmatically	O
rendered	O
GUI	B-Application
controls	O
(	O
as	O
opposed	O
to	O
the	O
use	O
of	O
the	O
native	O
host	O
OS	O
's	O
GUI	B-Application
controls	O
)	O
.	O
</s>
<s>
Prior	O
to	O
Java	B-Language
6	O
Update	O
10	O
,	O
this	O
distinction	O
was	O
a	O
source	O
of	O
complications	O
when	O
mixing	O
AWT	B-Language
controls	O
,	O
which	O
use	O
native	O
controls	O
,	O
with	O
Swing	B-Language
controls	O
in	O
a	O
GUI	B-Application
(	O
see	O
Mixing	O
AWT	B-Language
and	O
Swing	B-Language
components	O
)	O
.	O
</s>
<s>
Finally	O
,	O
in	O
terms	O
of	O
visual	O
composition	O
and	O
management	O
,	O
Swing	B-Language
favors	O
relative	B-Library
layouts	I-Library
(	O
which	O
specify	O
the	O
positional	O
relationships	O
between	O
components	O
)	O
as	O
opposed	O
to	O
absolute	O
layouts	O
(	O
which	O
specify	O
the	O
exact	O
location	O
and	O
size	O
of	O
components	O
)	O
.	O
</s>
<s>
This	O
bias	O
towards	O
"	O
fluid	O
"	O
 '	O
visual	O
ordering	O
is	O
due	O
to	O
its	O
origins	O
in	O
the	O
applet	B-Application
operating	O
environment	O
that	O
framed	O
the	O
design	O
and	O
development	O
of	O
the	O
original	O
Java	B-Language
GUI	B-Library
toolkit	I-Library
.	O
</s>
<s>
Since	O
early	O
versions	O
of	O
Java	B-Language
,	O
a	O
portion	O
of	O
the	O
Abstract	B-Language
Window	I-Language
Toolkit	I-Language
(	O
AWT	B-Language
)	O
has	O
provided	O
platform-independent	O
APIs	B-Application
for	O
user	O
interface	O
components	O
.	O
</s>
<s>
In	O
AWT	B-Language
,	O
each	O
component	O
is	O
rendered	O
and	O
controlled	O
by	O
a	O
native	O
peer	O
component	O
specific	O
to	O
the	O
underlying	O
windowing	O
system	O
.	O
</s>
<s>
By	O
contrast	O
,	O
Swing	B-Language
components	O
are	O
often	O
described	O
as	O
lightweight	O
because	O
they	O
do	O
not	O
require	O
allocation	O
of	O
native	O
resources	O
in	O
the	O
operating	B-General_Concept
system	I-General_Concept
's	O
windowing	B-Library
toolkit	I-Library
.	O
</s>
<s>
The	O
AWT	B-Language
components	O
are	O
referred	O
to	O
as	O
heavyweight	O
components	O
.	O
</s>
<s>
Much	O
of	O
the	O
Swing	B-Language
API	B-Application
is	O
generally	O
a	O
complementary	O
extension	O
of	O
the	O
AWT	B-Language
rather	O
than	O
a	O
direct	O
replacement	O
.	O
</s>
<s>
In	O
fact	O
,	O
every	O
Swing	B-Language
lightweight	O
interface	O
ultimately	O
exists	O
within	O
an	O
AWT	B-Language
heavyweight	O
component	O
because	O
all	O
of	O
the	O
top-level	O
components	O
in	O
Swing	B-Language
(	O
,	O
,	O
,	O
and	O
)	O
extend	O
an	O
AWT	B-Language
top-level	O
container	O
.	O
</s>
<s>
Prior	O
to	O
Java	B-Language
6	O
Update	O
10	O
,	O
the	O
use	O
of	O
both	O
lightweight	O
and	O
heavyweight	O
components	O
within	O
the	O
same	O
window	O
was	O
generally	O
discouraged	O
due	O
to	O
Z-order	B-Algorithm
incompatibilities	O
.	O
</s>
<s>
However	O
,	O
later	O
versions	O
of	O
Java	B-Language
have	O
fixed	O
these	O
issues	O
,	O
and	O
both	O
Swing	B-Language
and	O
AWT	B-Language
components	O
can	O
now	O
be	O
used	O
in	O
one	O
GUI	B-Application
without	O
Z-order	B-Algorithm
issues	O
.	O
</s>
<s>
The	O
core	O
rendering	O
functionality	O
used	O
by	O
Swing	B-Language
to	O
draw	O
its	O
lightweight	O
components	O
is	O
provided	O
by	O
Java	B-Language
2D	I-Language
,	O
another	O
part	O
of	O
JFC	O
.	O
</s>
<s>
The	O
Standard	B-Application
Widget	I-Application
Toolkit	I-Application
(	O
SWT	O
)	O
is	O
a	O
competing	O
toolkit	O
originally	O
developed	O
by	O
IBM	O
and	O
now	O
maintained	O
by	O
the	O
Eclipse	B-Application
community	O
.	O
</s>
<s>
SWT	O
's	O
implementation	O
has	O
more	O
in	O
common	O
with	O
the	O
heavyweight	O
components	O
of	O
AWT	B-Language
.	O
</s>
<s>
This	O
confers	O
benefits	O
such	O
as	O
more	O
accurate	O
fidelity	O
with	O
the	O
underlying	O
native	O
windowing	B-Library
toolkit	I-Library
,	O
at	O
the	O
cost	O
of	O
an	O
increased	O
exposure	O
to	O
the	O
native	O
platform	O
in	O
the	O
programming	O
model	O
.	O
</s>
<s>
There	O
has	O
been	O
significant	O
debate	O
and	O
speculation	O
about	O
the	O
performance	O
of	O
SWT	O
versus	O
Swing	B-Language
;	O
some	O
hinted	O
that	O
SWT	O
's	O
heavy	O
dependence	O
on	O
JNI	B-Language
would	O
make	O
it	O
slower	O
when	O
the	O
GUI	B-Application
component	O
and	O
Java	B-Language
need	O
to	O
communicate	O
data	O
,	O
but	O
faster	O
at	O
rendering	O
when	O
the	O
data	O
model	O
has	O
been	O
loaded	O
into	O
the	O
GUI	B-Application
,	O
but	O
this	O
has	O
not	O
been	O
confirmed	O
either	O
way	O
.	O
</s>
<s>
A	O
fairly	O
thorough	O
set	O
of	O
benchmarks	O
in	O
2005	O
concluded	O
that	O
neither	O
Swing	B-Language
nor	O
SWT	O
clearly	O
outperformed	O
the	O
other	O
in	O
the	O
general	O
case	O
.	O
</s>
<s>
This	O
example	O
Swing	B-Language
application	O
creates	O
a	O
single	O
window	O
with	O
"	O
Hello	O
,	O
world	O
!	O
"	O
</s>
<s>
The	O
first	O
import	O
includes	O
all	O
the	O
public	O
classes	O
and	O
interfaces	B-Application
from	O
the	O
package	B-Language
.	O
</s>
<s>
The	O
Hello	O
class	O
extends	O
the	O
class	O
;	O
the	O
JFrame	B-Language
class	O
implements	O
a	O
window	O
with	O
a	O
title	O
bar	O
and	O
a	O
close	O
control	O
.	O
</s>
<s>
It	O
then	O
calls	O
the	O
method	O
inherited	O
from	O
JFrame	B-Language
to	O
set	O
the	O
default	O
operation	O
when	O
the	O
close	O
control	O
on	O
the	O
title	O
bar	O
is	O
selected	O
to	O
this	O
causes	O
the	O
JFrame	B-Language
to	O
be	O
disposed	O
of	O
when	O
the	O
frame	O
is	O
closed	O
(	O
as	O
opposed	O
to	O
merely	O
hidden	O
)	O
,	O
which	O
allows	O
the	O
Java	B-Language
virtual	O
machine	O
to	O
exit	O
and	O
the	O
program	O
to	O
terminate	O
.	O
</s>
<s>
The	O
main( )	O
method	O
is	O
called	O
by	O
the	O
Java	B-Language
virtual	O
machine	O
when	O
the	O
program	O
starts	O
.	O
</s>
<s>
The	O
code	O
uses	O
the	O
method	O
to	O
invoke	O
the	O
constructor	O
from	O
the	O
AWT	B-Language
event	B-Language
dispatching	I-Language
thread	I-Language
in	O
order	O
to	O
ensure	O
the	O
code	O
is	O
executed	O
in	O
a	O
thread-safe	B-Operating_System
manner	O
.	O
</s>
<s>
Once	O
the	O
frame	O
is	O
displayed	O
,	O
exiting	O
the	O
main	O
method	O
does	O
not	O
cause	O
the	O
program	O
to	O
terminate	O
because	O
the	O
event	B-Language
dispatching	I-Language
thread	I-Language
remains	O
active	O
until	O
all	O
of	O
the	O
Swing	B-Language
top-level	O
windows	O
have	O
been	O
disposed	O
.	O
</s>
<s>
The	O
following	O
is	O
a	O
rather	O
simple	O
Swing-based	O
program	O
.	O
</s>
<s>
Notice	O
how	O
all	O
instantiation	O
and	O
handling	O
of	O
Swing	B-Language
components	O
are	O
done	O
by	O
creating	O
an	O
instance	O
of	O
the	O
class	O
,	O
</s>
<s>
This	O
is	O
then	O
run	O
on	O
the	O
Event	B-Language
Dispatch	I-Language
Thread	I-Language
by	O
use	O
of	O
the	O
method	O
)	O
,	O
created	O
in	O
the	O
main	O
method	O
(	O
see	O
Swing	B-Language
and	O
thread	B-Operating_System
safety	I-Operating_System
)	O
.	O
</s>
<s>
Although	O
Swing	B-Language
code	O
can	O
be	O
run	O
without	O
using	O
this	O
technique	O
(	O
for	O
instance	O
,	O
by	O
not	O
implementing	O
Runnable	O
and	O
moving	O
all	O
commands	O
from	O
the	O
run	O
method	O
to	O
the	O
main	O
method	O
)	O
,	O
it	O
is	O
considered	O
to	O
be	O
good	O
form	O
,	O
as	O
Swing	B-Language
is	O
not	O
thread-safe	B-Operating_System
,	O
meaning	O
that	O
invoking	O
resources	O
from	O
multiple	O
threads	B-Operating_System
can	O
result	O
in	O
thread	B-Operating_System
interference	O
and	O
memory	O
consistency	O
errors	O
.	O
</s>
<s>
In	O
this	O
example	O
let	O
javax.swing.JFrame	O
be	O
super	O
class	O
and	O
add	O
our	O
own	O
widget(s )	O
to	O
it	O
(	O
in	O
this	O
case	O
,	O
a	O
JButton	O
)	O
.	O
</s>
<s>
The	O
layout	O
is	O
set	O
to	O
null	O
using	O
the	O
method	O
since	O
JFrame	B-Language
uses	O
java.awt.BorderLayout	O
as	O
its	O
default	O
layout-manager	O
.	O
</s>
<s>
With	O
BorderLayout	B-Library
anything	O
which	O
is	O
added	O
to	O
the	O
container	O
is	O
placed	O
in	O
the	O
center	O
and	O
stretched	O
to	O
accommodate	O
any	O
other	O
widgets	O
.	O
</s>
<s>
Of	O
course	O
,	O
most	O
real	O
world	O
GUI	B-Application
applications	O
would	O
prefer	O
to	O
use	O
a	O
layout-manager	O
instead	O
of	O
placing	O
everything	O
on	O
absolute	O
co-ordinates	O
.	O
</s>
