Professional Documents
Culture Documents
1OOMGUI2014
1OOMGUI2014
1OOMGUI2014
Afterwards..
By
OOM
Before Mid Semstudents have different
levels of background but now OK
OOM After Mid Sem..?
What will be covered now..?
Thanks for feedback and some constructive
suggestion..
Some of your suggestions are now part of
OOM course..!!
What Exactly !!
Database System Concepts
3.2
Event Handling
Delegation model
5
3.5
Delegation model
Event Source , Listener & Interface
Applets & Standalone applications
Writing Applet: Embedding in HTML
Life Cycle of Applet
11/9/2014
3.6
6
Silberschatz, Korth and Sudarshan
3.7
3.8
Mobile Software
A mobile application (or Mobile App) is software written for
9
Database System Concepts
3.9
3.10
Mobile Apps ..
Different Vendors, heterogeneous platforms but OOM
3.11
Web Apps
It can usually be
12
3.12
Native:
For native apps, the advent
different programming
Languages..
Web:
For mobile Web apps, notable
developer interest emerged only in
the last year or so after Googles
successful implementation of
HTML5-based apps.
HTML5 & Javascripts.
Web Apps useful for subscription
11/9/2014
Database System Concepts
13
3.13
Platforms
Language(s)
Remarks
Android
Java, C, C++
bada
C, C++
Blackberry
Java
iOS
Objective-C, C
MeeGo
Symbian
WebOS
HML, CSS,
JavaScript, C
Windows
Mobile
C#, C
Window
C#, VB.NET
Database
PhoneSystem Concepts
11/9/2014
Database System Concepts
15
3.15
Compile-time Environment
Class
Loader
Bytecode
Verifier
Java
Source
(.java)
Java
Compiler
Java
Class
Libraries
Java
Interpreter
Java
Bytecodes
move locally
or through
network
Just in
Time
Compiler
Java
Virtual
machine
Runtime System
Java
Bytecode
(.class )
Operating System
Hardware
Database System Concepts
3.16
Editor
Compiler
Source
code
Bytecodes
Hello.java
Hello.class
Interpreter
Hello,
World!
Interpreter
Hello,
World!
3.17
3-17
typically coded in a
browser-rendered
language such as HTML
combined with
JavaScript.
18
3.18
11/9/2014
Database System Concepts
19
3.19
similar platforms, such as the Mac App Store and Google Play
Database System Concepts
3.21
22
3.22
Creating Window
Components & Containers
Frame Classes
Layout Managers
Event Handling & Applets
Writing Applets
Sandbox Security
11/9/2014
Database System Concepts
24
3.24
Layout Managers
Event Handling & Applets
Sandbox Security
11/9/2014
25
3.25
User Interface
Sun had used a logical and object-oriented design for
: AWT.
AWT API contained classes like
3.26
3.27
Swing.
like JButton.
For the most part, an AWT program can be converted to a
11/9/2014
Database System Concepts
28
3.28
Applets
An applet is a special kind of Java program that a
class.
The Applet class provides the standard interface
called javax.swing.JApplet.
The JApplet class should be used for all applets that
3.30
Applets
There are some important differences between an applet and a
standalone Java application, including the following:
An applet is a Java class that extends the java.applet.Applet
class.
A main() method is not invoked on an applet, and an applet
31
Database System Concepts
3.31
32
3.32
Sandbox Security
Applets run in a Web browser restricted to a set of security
33
3.33
components.
35
3.35
Component
Container
JComponent
The Swing API uses many of the AWT classes and interfaces.
36
Database System Concepts
3.36
the JDK.
A Frame is a window with borders, a title bar, and buttons
"threads" of the GUI app when the user clicks on the exit
(close) button of the main GUI window.
11/9/2014
Database System Concepts
37
3.37
Creating Window
The basic starting point of a GUI is the container because
you need a container before you can start laying out your
components.
The java.awt.Frame and javax.swing.JFrame classes are
11/9/2014
Database System Concepts
38
3.38
GUI Coordinates
All components and containers have a size and
11/9/2014
Database System Concepts
39
3.39
Using Frame
For example, the point (100,100) is 100 pixels over and 100
11/9/2014
Database System Concepts
40
3.40
assign it bounds (20, 200, 60, 40). The Button is then added
to the Frame object instantiated earlier:
Button ok = new Button(OK);
ok.setBounds(20, 200, 60, 40);
f.add(ok); //Add the Button to a Frame
11/9/2014
Database System Concepts
41
3.41
Coordinates
The upper-left corner of the OK button appears 20 pixels over and
200 pixels down from the upper-left corner of the Frame. The
size of the Button is 60 pixels wide and 40 pixels high.
Assuming that Frame f has not been moved, this puts the Button
120 pixels over and 300 pixels down from the upper-left corner of
the screen. This point changes if the Frame is moved. However,
the relative location of the Button within the Frame does not
move, even if the Frame moves. This is the desired result of GUI
containers and components.
When we move a window, we expect all the components within
42
3.42
java.awt.Frame Class
When working with Frame objects, there are basically
11/9/2014
Database System Concepts
43
3.43
I.
II.
III.
IV.
11/9/2014
Database System Concepts
44
3.44
11/9/2014
Database System Concepts
45
3.45
Windows
This Frame is not displayed on the screen, and it has an
initial size of 0 by 0.
We need to give our Frame a size before displaying it, which
the Frame to the same width and height as the given Dimension
object.
public void setBounds(int x, int y, int width, int height). Sets
3.46
46
Create Window
After we have
instantiated a Frame,
given it a size, and
11/9/2014
Database System Concepts
47
3.47
FrameDemo program
The following FrameDemo program creates a Frame object,
import java.awt.*;
public class FrameDemo
{
public static void main(String [] args)
{
Frame f = new Frame(My first window);
48
3.48
Window
We can move, resize, minimize, and maximize
the Frame window.
However, we cant close the window because closing
a window often implies ending the program.
If the user needs to save a
document or other settings before ending, your program needs a chance
to do this.
The closing involves handling the WindowEvent generated by a user attempting
to
close the window.
11/9/2014
Database System Concepts
49
3.49
50
Database System Concepts
3.50
Creating Window
The constructors are similar to those in the Frame class, and the
11/9/2014
Database System Concepts
51
3.51
Creating Window
The following JFrameDemo program demonstrates creating and
import javax.swing.*;
public class JFrameDemo
{
public static void main(String [] args)
{
JFrame f = new JFrame(My first JFrame);
f.setSize(400, 300);
f.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOS
E);
f.setVisible(true);
}
} 11/9/2014
Database System Concepts
52
3.52
Using Swing
Clicking the X in the title bar of a JFrame causes the window to be hidden
by default, but this does not cause your program to stop executing.
We need to press Ctrl+c at the command prompt to stop the JVM, even though
our JFrame is no longer visible on the screen.
11/9/2014
Database System Concepts
53
3.53
Overview
There are two types of GUI elements:
11/9/2014
Database System Concepts
54
3.54
components.
56
3.56
GUI
Component is an abstract class that is the
11/9/2014
3.57
58
3.58
Components
To demonstrate using the add() method, the following
import java.awt.*;
public class AddDemo
{
public static void main(String [] args)
{
Frame f = new Frame(A simple window);
Button cancel = new Button(Cancel);
11/9/2014
59
3.59
60
3.60
Using Jframe
Components are added to a JFrame differently from the way they
are added to a Frame. When using a Frame, you invoke the add()
method directly on the Frame object, adding the components
directly to the Frame.
When using a JFrame, we still invoke the add() method, but not on
11/9/2014
Database System Concepts
62
3.62
Layout mangaer
Notice that the return value of getContentPane() is
presentation purposes.
You can use the layout managers for basic layout capabilities
3.63
Absolute positioning:
Layout managers:
Visual programming in an IDE:
64
Database System Concepts
3.64
Absolute positioning
This provides the greatest level of control over a
GUIs appearance.
3.65
Layout Managers
Using layout managers to position elements
can be simpler and faster than creating a
GUI with absolute positioning, but you lose
some control over the size and the precise
positioning of GUI components.
There are following types of Layout managers:
1)
2)
3)
3.67
These IDEs have GUI editors that let you place components exactly
where you want them. You can also organize components by
assigning a null layout manager to your container and specifying the
exact location and size of each component added.
Q: So why would you ever use one of the layout managers? Why
not just use the IDE or lay out the components exactly where you
want them?
A: Two reasons: First, you might not have an IDE, and if you do,
your GUI more portable. You might be surprised to see that a GUI
that you created using an IDE looks great on Windows, but not so
great
on a Unix or Macintosh platform.
The same problem
can
occur
Database System
Concepts
3.68
Silberschatz,
Korth
and Sudarshan
to look?
A: You need to understand the way each type of layout manager
have great control over the look of the GUI, while at the same time
letting the layout managers determine the exact location and size of
your GUI components.
3.69
An AWT Applet (in package java.applet) is the top-level container for an applet,
which is a Java program running inside a browser. Applet will be discussed
11/9/2014
Database System Concepts
70
3.70
AWT Containers
Secondary containers are placed inside a top-level container
AWT has Panel and ScrollPane as these secondary containers:
11/9/2014
Database System Concepts
71
3.71
Layout Managers
A container uses a layout manager to determine both the
11/9/2014
Database System Concepts
72
3.72
Layout Managers
We can use one of the many layout managers of the AWT and
flow, with each component given its preferred size. A Panel has
FlowLayout by default.
java.awt.BorderLayout. Divides a container into five regions,
3.73
Layout Managers
java.awt.CardLayout. Each component added to the
11/9/2014
Database System Concepts
74
3.74
Layout Manager
Any container can use any layout manager. Notice
3.75
75
FlowLayout Manager
The java.awt.FlowLayout class represents a layout manager that
justified, or right-justified.
You can control the vertical and horizontal gap between
components.
11/9/2014
Database System Concepts
76
3.76
77
3.77
Layout Manager
For example, the following statement instantiates a new
f.setLayout(new FlowLayout(FlowLayout.RIGHT));
The FlowLayoutDemo program creates a Frame and assigns it
is shown.
11/9/2014
Database System Concepts
78
3.78
import java.awt.*;
public class FlowLayoutDemo
{ list.add(args[i]);
}
f.add(list);
f.add(new Checkbox(Pick me, true));
79
3.79
Flowlayout demo
The FlowLayoutDemo demonstrates using some of the AWT
components.
Three Button components are added to the Frame first. Then, a
11/9/2014
Database System Concepts
80
3.80
82
3.82
Swing Look
The javax.swing.UIManager class maintains the current look and
feel for a Java program using Swing.
In particular, the UIManager class contains methods for
Motif look and feel, which is the user interface for many Unix
operating systems.
com.sun.java.swing.plaf.windows.WindowsLookAndFeel.
3.83
83
import java.awt.*;
BorderLayoutDemo
program demonstrates
both how to add
components to a container
with BorderLayout and
how the five regions look.
{ super(title);
north = new Button(North);
south = new Button(South);
east = new Button(East);
west = new Button(West);
center = new Button(Center);
this.add(north, BorderLayout.NORTH);
this.add(south, BorderLayout.SOUTH);
this.add(east, BorderLayout.EAST);
this.add(west, BorderLayout.WEST);
this.add(center, BorderLayout.CENTER);
}
public static void main(String [] args)
{ Frame f = new
BorderLayoutDemo(BorderLayout demo);
f.pack();
f.setVisible(true);
11/9/2014
}}
Database System Concepts
84
3.84
Output..
The north and south buttons have their preferred height, but are as wide as
the window.
The east and west buttons have their preferred width, but run the
height of the window. The center button fills in the remaining space, getting
neither its preferred width nor height.
11/9/2014
Database System Concepts
85
3.85
Panels
A panel is a simple container used for holding components.
3.86
86
You might be wondering what the purpose of panels is, so lets look
at an
example that illustrates when a panel is useful.
Suppose that you are using a
Frame with BorderLayout and you want three buttons displayed in
the south.
However, you cannot add three components to the south of a
BorderLayout,
so how can this be done?
import java.awt.*;
southPanel.add(next);
this.add(southPanel, BorderLayout.SOUTH);
Panel northPanel = new Panel();
northPanel.add(new Label(Make a selection));
this.add(northPanel, BorderLayout.NORTH);
list = new List();
for(int i = 1; i <= 10; i++)
{ list.add(Selection + i); }
this.add(list, BorderLayout.CENTER); }
f.setVisible(true);} }
3.88
Output of PanelDemo
11/9/2014
Database System Concepts
89
3.89
Dialog Windows
A dialog window is used to interact with the user, either to share
3.91
Dialog Window
A dialog window often has an owner window that is either
Creates a Dialog with the given Frame as its owner. The String
appears in the title bar, and if the boolean is true, the Dialog will
be modal.
public Dialog(Dialog owner, String title, boolean modal).
92
3.92
GUI in Java
Recent Advances
94
3.94
JavaFX 2.2 and later releases are fully integrated with the Java SE
95
3.95
Component
Container
JComponent
The Swing API uses many of the AWT classes and interfaces.
96
Database System Concepts
3.96
JavaFX Hierarchy..
java.lang.Object
java.awt.Component
java.awt.Container
javax.swing.JComponent
javafx.embed.swing.JFXPane
11/9/2014
Database System Concepts
97
3.97
11/9/2014
Database System Concepts
99
3.99