Академический Документы
Профессиональный Документы
Культура Документы
Object java.lang
+--
Component java.awt
+--Container java.awt
+--Window java.awt
| +--Frame java.awt
+--Panel java.awt
+--
Window Fundamentals
Component
An abstract class that encapsulate all of
the attributes of a visual component.
All the user interface element that are
displayed on the screen and that interact
with the user are subclasses of
Component
Defines method for managing
events,such as mouse and keyboard
inputs ,positioning and sizing of window..
Responsible for remembering the
foreground and background colors
Window Fundamentals
Container
◦ Subclass of component.
◦ Allows other component objects to be
nested within it
Panel
◦ Subclass of Container and superclass of
applet
◦ Screen output directed to applet , it is
drawn on the surface of a Panel object
◦ A panel is a window that does not contain
a title bar, menu bar and border
◦ Other components can be added by add()
method
Window
Window
◦ Wont create window objects directly
◦ Instead we use a subclass of Window
called Frame
Frame
◦ Has a title bar, menu bar, borders
and resizing corners
◦ Creating a frame object within an
applet, it will contain a warning
message(“A applet window”) to the
user.
Window Fundamentals
Canvas
◦ Encapsulates a blank window upon
which we can draw.
Buttons
list.add("Seattle");
list.add("Washington");
list.add("New York");
list.add("Chicago");
list.add("Miami"); list.add("San Jose");
list.add("Denver");
add(list);
}
Type of event generated-
Item Event (when the item is
selected or deselected)
Action Event(when an item is
double clicked)
TextField
Container ContainerListener
Window WindowListener
Semantic Events
Button
List
MenuItem
TextField ActionListener
Choice
Checkbox
MenuItem
List ItemListener
Scrollbar
AdjustmentListener
TextArea
TextField TextListener
Canvas
A Canvas is a graphical
component representing a region
where you can draw things such
as rectangles, circles, and text
strings.
You subclass Canvas to override
its default paint() method to
define your own components.
import java.awt.*;
class DrawingRegion extends Canvas
{
public DrawingRegion()
{
setSize(100, 50);
}
public void paint(Graphics g)
{
g.drawRect(0, 0, 99, 49);
// draw border
g.drawString("A Canvas", 20,20); }
}
import java.applet.*;
public class CanvasPaintTest extends
Applet {
public void init()
{
DrawingRegion region = new
DrawingRegion();
add(region);
}
}