Oopr Prelim
Oopr Prelim
Oopr Prelim
JAVA Gui
- JAVA provides a rich set of libraries to create
Graphical User Interface in a platform
independent way.
- In Java, GUI-based programs are implemented
by using the classes from the standard
- Javax.swing (Swing classes) and - Java’s platform-independent windowing,
- java.awt (AWT classes) packages. graphics, and user-interface widget toolkit part of
- All GUI classes are based on the fundamental the Java Foundation Classes (JFC)
classes in the Application Windowing Toolkit or - The standard API (Application Program
AWT. Interface) for providing graphical user interfaces
for Java programs contains the fundamental
About the JFC and Swing classes used for constructing GUIs.
- JFC is short for Java Foundation Classes,
which encompasses a group of features for AWT Components and Containers
building graphical user interfaces (GUIs) and
adding rich graphics functionality and
interactivity to Java applications.
JFC Features
JOptionPane.showMessageDialog(null, “Hello!”);
Example 2:
Dialog displaying “Hello!” , with OK button, no
Graphical Input and Output with Option Panes ] standard icon, and title “Sample ONLY”.
Example 3:
Dialog with empty text field, “Enter value:”
prompt string, plus OK and CANCEL buttons.
showconfirmDialog[]
Drawing Lines
- Draw a line between point (x1,y1) to point
(x2,y2).
drawLine(x1,y1, x2,y2 );
Example:
g.drawLine (10, 30, 90, 30);
Color Constant
- RED
- GREEN
- BLUE
- ORANGE
- PINK Drawing rectangle
- CYAN - Draws a rectangle of the specified width and
- MAGENTA height. The top-left corner of the rectangle has
- YELLOW the coordinate (x,y).
- BLACK
- WHITE drawRect( x,y, width, height );
- GRAY
- LIGHT_GRAY Example:
- DARK_GRAY g.drawRect(10, 40, 40, 30);
Font Class
- Font objects can be created using the
constructor:
Public Font(String name, int style, int points)
And the constants:
Examples:
Example:
g.fillRect (10, 40, 40, 30);
DRAWING OVALS
Drawing Oval
- Draws an oval in the current color with the
specified width and height. The bounding
rectangle’s top-left corner is ate coordinates
(x , y). The oval touches all four sides of the
bounding rectangle at the center of each side.
Example:
g.drawRoundRect ( 10, 20, 60, 50, 20, 20 );
Example:
g.fillOval (10, 20, 30, 50);
Drawing rectangle
- Draws a solid rectangle with rounded corners in
the current color with the specified width and
height. The arcWidth and arcHeight determine
the rounding of the corners.
Example:
g.fillRoundRect( 10, 20, 60, 50, 20, 20 );
arcWidth and arcHeight determine the rounding
DRAWING ARCS of the corners. True means raised.
fill3DRect(x,y,width,height,[true,false]);
Drawing Arcs
- Draws an arc relative to the bounding Example:
rectangle’s top-left coordinates (x, y) with the g.fill3DRect(250,40,50,50,true);
specified width and height. The arc segment is
drawn starting at startAngle and sweeps
arcAngle degrees. CREATING POLYGONS
Drawing Arcs
- Draws a solid arc relative to the bounding
rectangle’s top- left coordinates (x,y) with the
specified width and height. The arc segment is
drawn starting at startAngle and sweeps
arcAngle degrees.
fillArc(x,y,width,height, startAngle, arcAngle); WEEK 5 Module 4: GUI with JAVA AWT (Abstract
Window Toolkit)
Example:
g.fillArc(30,20,40,40,0,-270) Java AWT
- A toolkit of classes in Java which helps a
programmer to develop Graphics and Graphical
User Interface components.
- It is a part of JFC (Java Foundation Classes)
developed by Sun Microsystems.
- It was developed for providing a common set of
tools for designing the cross-platform GUIs. One
of the important features of AWT is that it is
platform dependent.
Drawing 3D rectangle
- Draws a 3D rectangle in the current color with
the specified width and height. The arcWidth and
arcHeight determine the rounding of the corners.
True means raised.
draw3DRect(x,y,width,height,[true,false]);
Example:
g.draw3DRect(250,40,50,50,true);
- All the elements like buttons, labels, etc are Other Components and Containers
known as components.
- In AWT we have classes for each component as
shown in the above diagram.