Java Units
Java Units
EXAM REVIEW
Important concepts
Give the difference between awt and swing? Or give the
features of swing?
Explain the following?
Japplet
Jframe
Explain different layout managers in detail?
What is event delegation model or event handling explain
it?
Write short notes on inner classes and adapter classes?
All the dialogs of joptionpane, jdialog?
Give the table of event, its listener, its event, its event
source? 8.Handle mouse events?
difference between awt and swing
AWT
SWING
AWT is called 'peer component Swing components do not
based' model. depend on native methods. SO
no portability issues.
The look-and-feel change
depending on the platform. same look-and-feel'on all
platforms.
heavy-weight. light-weight
user interface designs tended Model-View-Controller is a
to lump objects together. model used in swing
wont provide any pluggable components.
look and feel feature. Swing offers 'pluggable look-
and-feel' feature
Japplet is equivalent to applet already studied.
JFrame
Frames : A frame is a container which is used for displaying the
components in separate window.
A frame containing the following features :
i. The frame contains title bar, minimize, maximum, buttons.
ii. Contains resizable borders.
iii. Contains a menu bar.
To create a Jframe, create a class that extends the Jframe class.
Constructors :
Jframe ( ) : Creates a frame.
Jframe ( String title ) :
Methods :
void setTitle( String newTitle ) :
String getTitle( ) :
example
class MyFrame extends Frame
{
MyFrame()
{
setTitle("Sample Frame 4");
setSize(300,200);
setBackground(Color.pink);
addWindowListener(new MyWindowAdapter());
}
class frametest4
{
public static void main(String args[])
{
MyFrame f = new MyFrame();
f.setVisible(true); // show the frame
}
}
output
different layout managers
useful to arrange components in a particular
manner in a frame or container.
Different layouts
FlowLayout
BorderLayout
CardLayout
GridLayout
GridBagLayout
BoxLayout
Flow layout
arrange the components in a line one after
the other.
Syntax:
FlowLayout obj = new FlowLayout();
FlowLayout obj = new FlowLayout(int
alignment);//alignment is LEFT,
RIGHT,CENTER,LEADING,TRAILING
FlowLayout obj = new FlowLayout(int
alignment,int hgap, int vgap);
example
setLayout(new FlowLayout(FlowLayout.LEFT));
w = new JButton(one);
a = new JButton(Two");
s = new JButton(Three");
m = new JButton(Four");
j = new JButton(Five");
add(w);
add(a);
add(s);
add(m);
add(j);
output
BorderLayout