Graphical components in Java form an inheritance hierarchy javalangObject javaawtComponent javaawtContainer javaxswingJComponent ID: 812007
Download The PPT/PDF document "Java Swing, continued Swing component hi..." is the property of its rightful owner. Permission is granted to download and print the materials on this web site for personal, non-commercial use only, and to display it on your personal computer provided you do not modify the materials and that you retain all copyright notices contained in the materials. By downloading content from our website, you accept the terms of this agreement.
Slide1
Java Swing, continued
Slide2Swing component hierarchy
Graphical components in Java form an inheritance hierarchy:
java.lang.Object
+--
java.awt.Component
+--
java.awt.Container
|
+--
javax.swing.JComponent
| +--
javax.swing.
JButton
| +--
javax.swing.
JLabel
| +--
javax.swing.
JMenuBar
| +--
javax.swing.
JOptionPane
| +--
javax.swing.
JPanel
| +--
javax.swing.
JTextArea
| +--
javax.swing.
JTextField
|
+--
java.awt.Window
+--
java.awt.Frame
+--
javax.swing.
JFrame
When doing GUI programming, always import these packages:
import
java.awt
.*;
import
javax.swing
.*;
Slide3What Can be Summarized?
Derived a new container class from, say,
JFrame
In the derived class
Define a
constructor
that sets up the title and size of the windowSet up the proper lay out of the outer containerCreate inner containers (using JPanel or other containers)Set up the proper lay out of each inner containersAdd the interface objects, such as buttons and others, to the corresponding containersRemember to associate a listener object for each interface objectAdd the containers to the Frame object in order
Define listener classes to handle possible events fired by the interface objects added in the window
In the main function
Create the object of the derived window class
Launch the interface by setting it as visible
Slide4text field and text area and scroll bars
Slide5Text Field and Text Area Examples
Slide6Text Fields
A
text field
is an object of the class
JTextField
It is displayed as a field that allows the user to enter a
single line of textprivate JTextField name;. . .name = new JTextField(NUMBER_OF_CHAR);In the text field above, at least
NUMBER_OF_CHAR characters can be visible
Slide7Text Fields
There is also a constructor with one additional
String
parameter for displaying
an initial
String
in the text fieldJTextField name = new JTextField( "Enter name here.", 30);A Swing GUI can read the text in a text field using the
getText methodString
inputString
=
name.getText
();
The method
setText
can be used to
display
a new text string in a text field
name.setText
("This is some output");
Slide8A Text Field (Part 6 of 7)
Slide9A Text Field (Part 7 of 7)
What layout is it used?
Slide10A Text Field (Part 1 of 7)
Slide11A Text Field (Part 2 of 7)
Slide12A Text Field (Part 3 of 7)
Slide13A Text Field (Part 4 of 7)
Slide14A Text Field (Part 5 of 7)
Slide15Text Areas
A
text area
is an object of the class
JTextArea
It is the same as a text field,
except that it allows multiple linesTwo parameters to the JTextArea constructor specify the minimum number of lines, and the minimum number of characters per line that are guaranteed to be visibleJTextArea theText
= new JTextArea(5,20);Another constructor has one addition
String
parameter for the string initially displayed in the text area
JTextArea
theText
= new
JTextArea
(
"Enter\
ntext
here." 5, 20);
Slide16Text Areas
The
line-wrapping
policy for a
JTextArea
can be set using the method
setLineWrapThe method takes one boolean type argumentIf the argument is true, then any additional characters at the end of a line will appear on the following line of the text areaIf the argument is false, the extra characters will remain on the same line and not be visibletheText.setLineWrap
(true);
Slide17Text Fields and Text Areas
A
JTextField
or
JTextArea
can be set so that it can not be changed by the user
theText.setEditable(false);This will set theText so that it can only be edited by the GUI program, not the userTo reverse this, use true instead (this is the default)theText.setEditable(true);
Slide18Tip: Labeling a Text Field
In order to label one or more text fields:
Use an object of the class
JLabel
Place the text field(s) and label(s) in a
JPanel
Treat the JPanel as a single component
Slide19Numbers of Characters Per Line
The number of characters per line for a
JTextField
or
JTextArea
object is the number of
em spacesAn em space is the space needed to hold one uppercase letter MThe letter M is the widest letter in the alphabetA line specified to hold 20 M 's will almost always be able to hold more than 20 characters
Slide20Tip: Inputting and Outputting Numbers
When attempting to input numbers from any Swing GUI, input text must be converted to numbers
If the user enters the number
42
in a
JTextField
, the program receives the string "42" and must convert it to the integer 42String input = name.getText();int
num
=
Integer.parseInt
(input);
The same thing is true when attempting to output a number
In order to output the number
42
, it must first be converted to the string
"42"
Integer.toString
(
num
);
Slide21Scroll Bar
When a text area is created, the number of lines that are visible and the number of characters per line are specified as follows:
JTextArea
memoDisplay
= new
JTextArea(15, 30);However, it would often be better not to have to set a firm limit on the number of lines or the number of char-acters per lineThis can be done by using scroll bars with the text area
Slide22Scroll Bar
Scroll
bars can be added to text areas using the
JScrollPane
class
–The JScrollPane class is in the javax.swing package–An object of the class JScrollPane is like a view port with scroll bars
Slide23View Port for a Text Area
Slide24Scroll Bar
When
a
JScrollPane
is
created, the text area to be viewed is given as an argumentJTextArea memoDisplay = new JTextArea(15, 30);
JScrollPane
scrolledText
=
new
JScrollPane
(
memoDisplay
);
The
JScrollPane
can
then be added to a container, such as a
JPanel
or
JFrame
textPanel.add
(
scrolledText
);
Slide25Scroll Bar
The
scroll bar policies can be set as follows:
scrolledText.setHorizontalScrollBarPolicy
(
JScrollPane.HORIZONTAL_SCROLLBAR_ALWAYS
);scrolledText.setVerticalScrollBarPolicy(JscrollPane.VERTICAL_SCROLLBAR_ALWAYS);
If invocations of these methods are omitted, then the scroll bars will be visible only when neededIf all the text fits in the view port, then no scroll bars will be visible
If
enough text is added, the scroll bars will appear automatically
Slide26A Text Area with Scroll Bar
What layout is it used?
Slide27A Text Area with Scroll Bar
Slide28A Text Area with Scroll Bar
Slide29A Text Area with Scroll Bar
Slide30A Text Area with Scroll Bar
Slide31A Text Area with Scroll Bar
Slide32A Text Area with Scroll Bar
Slide33A Text Area with Scroll Bar
Slide34icons
Slide35Icons
JLabels
,
JButtons
, and
JMenuItems
can have iconsAn icon is just a small picture (usually)It is not required to be smallAn icon is an object of the ImageIcon classIt is based on a digital picture file such as .gif,
.jpg, or .tiffLabels, buttons, and menu items may display a string, an icon, a string and an icon, or nothing
Slide36Icons
The class
ImageIcon
is used to convert a picture file to a Swing icon
ImageIcon
dukeIcon = new ImageIcon("duke_waving.gif");The picture file must be in the same directory as the class in which this code appears, unless a complete or relative path name is givenNote that the name of the picture file is given as a string
Slide37Icons
An icon can be added to a label using the
setIcon
method as follows:
JLabel
dukeLabel = new JLabel("Mood check");dukeLabel.setIcon(dukeIcon);
Instead, an icon can be given as an argument to the JLabel constructor:
JLabel
dukeLabel
= new
JLabel
(
dukeIcon
);
Text can be added to the label as well using the
setText
method:
dukeLabel.setText
("Mood check");
Slide38Icons
Icons and text may be added to
JButtons
and
JMenuItems
in the same way as they are added to a
JLabelJButton happyButton = new JButton
("Happy");ImageIcon
happyIcon
= new
ImageIcon
("smiley.gif");
happyButton.setIcon
(
happyIcon
);
Slide39Icons
Button or menu items can be created with just an icon by giving the
ImageIcon
object as an argument to the
JButton
or
JMenuItem constructorImageIcon happyIcon = new ImageIcon("smiley.gif");
JButton smileButton
= new
JButton
(
happyIcon
);
JMenuItem
happyChoice
= new
JMenuItem
(
happyIcon
);
A button or menu item created without text should use the
setActionCommand
method to explicitly set the action command, since there is no string
Slide40Using Icons
What layout is it used?
Slide41Using Icons (Part 1 of 5)
Slide42Using Icons (Part 2 of 5)
Slide43Using Icons (Part 3 of 5)
Slide44Using Icons (Part 4 of 5)
Slide45Using Icons
(Part 5 of 5)
Slide46window listeners
Slide47Window Listeners
Clicking the close-window button on a
JFrame
fires a
window event
Window events are objects of the class
WindowEventThe setWindowListener method can register a window listener for a window eventA window listener can be programmed to respond to this type of eventA window listener is any class that satisfies the WindowListener interface
Slide48Window Listeners
A class that implements the
WindowListener
interface must have definitions for all
seven method headers
in this interface
Should a method not be needed, it is defined with an empty body public void windowDeiconified(WindowEvent e){ }
Slide49Methods in the
WindowListener
Interface (Part 1 of 2)
Slide50Methods in the
WindowListener
Interface (Part 2 of 2)
Slide51A Window Listener Inner Class
An inner class often serves as a window listener for a
JFrame
The following example uses a window listener inner class named
CheckOnExit
addWindowListener
(new CheckOnExit());When the close-window button of the main window is clicked, it fires a window event
This is received by the anonymous window listener objectThis causes the windowClosing
method to be invoked
Slide52A Window Listener Inner Class
The method
windowClosing
creates and displays a
ConfirmWindow
class object
It contains the message "Are you sure you want to exit?" as well as "Yes" and "No" buttonsIf the user clicks "Yes," the action event fired is received by the
actionPerformed methodIt ends the program with a call to System.exit
If the user clicks
"No
,
"
the
actionPerformed
method invokes the dispose method
This makes the calling object go away (i.e., the small window of the
ConfirmWindow
class), but does not affect the main window
Slide53A Window Listener (Part 8 of 8)
Slide54A Window Listener (Part 1 of 8)
Slide55A Window Listener (Part 2 of 8)
Slide56A Window Listener (Part 3 of 8)
Slide57A Window Listener (Part 4 of 8)
Slide58A Window Listener (Part 5 of 8)
Slide59A Window Listener (Part 6 of 8)
Slide60A Window Listener (Part 7 of 8)
Slide61The
dispose
Method
The
dispose()
method
of the JFrame class is used to eliminate the invoking JFrame without ending the programThe resources consumed by this JFrame and its components are returned for reuseUnless all the elements are eliminated (i.e., in a one window program), this does not end the programd
ispose is often used in a program with multiple windows to eliminate one window without ending the program
Slide62graphics objects
Slide63Screen Coordinate System
Slide64The Method
paint
and the Class
Graphics
Almost all Swing and Swing-related components and
containers
have a method called paint(Graphics g)The method paint draws the component or container on the screenIt is already defined, and is called automatically when the figure is displayed on the screenHowever, it must be redefined in order to draw geometric figures like circles and boxesWhen redefined, always include the following:super.paint
(g);
Slide65The Method
paint
and the Class
Graphics
Every container and component that can be drawn on the screen has an associated
Graphics
objectThe Graphics class is an abstract class found in the java.awt packageThis object has data specifying what area of the screen the component or container coversThe Graphics object for a JFrame specifies that drawing takes place inside the borders of the
JFrame object
Slide66The Method
paint
and the Class
Graphics
The object
g
of the class Graphics can be used as the calling object for a drawing methodThe drawing will then take place inside the area of the screen specified by gThe method paint has a parameter g of type Graphics
When the paint method is invoked, g is replaced by the
Graphics
object associated with the
JFrame
Therefore,
the figures are drawn inside the
JFrame
Slide67Happy Face Example
Slide68Happy Face Example
Slide69Drawing inside JPanel
Many times, it is recommended to draw inside a panel rather than the
JFrame
object.
In this case, the
paintComponent
(Graphics g) should be overridden.
Slide70Drawing and Mouse Click Example
Slide71Some useful methods
void
setColor
(
Color
color)
void setFont(Font font) void drawString(String text, int x, int y) void drawLine(int x1, int y1, int x2, int y2) void drawRect
(int x, int y, int width, int height)
void
drawRoundRect
(
int
x,
int
y,
int
width,
int
height,
int
arcWidth
,
int
arcHeight
)
void
drawOval
(
int
x,
int
y,
int
width,
int
height)
void
drawArc
(
int
x,
int
y,
int
width,
int
height,
int
startAngle
,
int
angularExtent
)
void
fillRect
(
int
x,
int
y,
int
width,
int
height)
void
fillRoundRect
(
int
x,
int
y,
int
width,
int
height,
int
arcWidth
,
int
arcHeight
)
void
fillOval
(
int
x,
int
y,
int
width,
int
height)
void
fillArc
(
int
x,
int
y,
int
width,
int
height,
int
startAngle
,
int
angularExtent
)
Using OpenGL with Java!
http://jogamp.org/jogl/www
/
http://
en.wikipedia.org/wiki/Java_OpenGL
http://
jogamp.org/wiki/index.php/Jogl_Tutorial
What is OpenGL?
It is
NOT
a
programming language
.
It is a Graphics Rendering API consisting of a set of functions with a well defined interface.Whenever we say that a program is OpenGL-based or OpenGL applications, we mean that it is written in some programming language (such as C/C++ or Java) that makes calls to one or more of OpenGL libraries.
Slide74OpenGL & Alternative
Based on GL (graphics library) by Silicon Graphics Inc. (SGI) (
www.
opengl
.org
)
Advantages:Runs on everything, including smart phones (OpenGL/ES)Alternatives:Microsoft’s Direct3D – limited to MS-Windows (http://windows.microsoft.com/en-us/windows7/products/features/directx-11) Sun’s Java3D – slower, implemented on top of OpenGL (http://www.java3d.org/)
Slide75Useful Websites and Books
Official Site
http
://
www.opengl.org
Non official sites http://nehe.gamedev.net/ http://google.com/BOOKS OpenGL Red Book (http://www.glprogramming.com/red/)& OpenGL Blue Book (http://www.glprogramming.com/blue/)
Slide76APP
GLUT
Library Layers
OpenGL = GL + GLU
Basic low-level GL routines
implemented using OS graphics routines
Time-saving higher-level GLU routines implemented using GL routinesGLUT opens and manages OpenGL windows and adds helper functionsOpenGL Extensions provide direct device-dependent access to hardware
GL
GLU
OS
Driver
HW
EXT
Slide77OpenGL API Functions
OpenGL contains
over 200 functions
Primitive functions
:
define the elements (
e.g. points, lines, polygons, etc.)Attribute functions: control the appearance of primitives (e.g. colors, line types, light source, textures, etc.)Viewing functions: determine the properties of camera. Handle transformations.Windowing functions: not part of core OpenGL (in GLUT)Other functions
Slide78Graphics Pipeline of OpenGL
Homogeneous Divide
Model
Coords
Model
Xform
World
Coords
Viewing
Xform
Still
Clip
Coords
Clipping
Window
Coordinates
Window
to
Viewport
Viewport
Coordinates
Clip
Coords
Viewing
Coords
Perspective
Distortion
Slide79Viewport Coordinates
Physical per-pixel integer coordinates
Also called screen or device coordinates
glViewport
(
x,y,w,h
)x,y – lower left pixel (integers)w – widthh – heightSometimes (0,0) is in the upper left corner (e.g. for mouse input)
(0,0)(HRES-1,0)
(HRES-1,
VRES-1)
(0,VRES-1)
Slide80Window Coordinates
Logical, mathematical
floating-point coordinates
glOrtho
(
l,r,b,t,n,f
) (for 3D)left, right, bottom, topnear, far: limits depthFor 2D use gluOrtho2D(l,r,b,t
) calls glOrtho(l,r,b,t,-1,1)
To use per-pixel coordinates, call:
gluOrtho2D(-.5,-.5,w-.5,h-.5);
(-1,-1)
(1,-1)
(1,1)
(-1,1)
Slide812D Geometric Primitives
Primitives – fundamental entities such as point and polygons
Basic
types of geometric primitives
Points
Line segments
Polygons
Slide82GL_POINTS
GL_LINES
GL_LINE_STRIP
GL_POLYGON
GL_QUADS
GL_TRIANGLES
GL_TRIANGLE_FAN
All geometric primitives are specified by
vertices
2D Geometric Primitives
GL_LINE_LOOP
Slide83glBegin
( type );
glVertex
*(…);
……
glVertex*(…);
glEnd
();
type
determines how vertices are combined
Specifying Geometric Primitives
Slide84An Example
void
drawSquare
(
GLfloat
*color)
{
glColor3fv( color ); // sets the color of the square
glBegin
(GL_POLYGON);
glVertex2f ( 0.0, 0.0 );
glVertex2f ( 1.0, 0.0 );
glVertex2f ( 1.1, 1.1 );
glVertex2f ( 0.0, 1.0 );
glEnd
();
glFlush
(); // force the renderer to output the results
}
Slide85Points
glBegin
(
GL_POINTS
);
glVertex2f(-.6,1.);
glVertex2f(-.6,.6); glVertex2f(-.2,.6); glVertex2f(-.2,-.6); glVertex2f(-.6,-.6); glVertex2f(-.6,-1.); glVertex2f(.6,-1.);
glVertex2f(.6,-.6); glVertex2f(.2,-.6); glVertex2f(.2,.6); glVertex2f(.6,.6);
glVertex2f(.6,1.);
glEnd
();
(-1,-1)
(1,-1)
(1,1)
(-1,1)
Slide86Lines
glBegin
(
GL_LINES
);
glVertex2f(-.6,1.);
glVertex2f(-.6,.6); glVertex2f(-.2,.6); glVertex2f(-.2,-.6); glVertex2f(-.6,-.6); glVertex2f(-.6,-1.); glVertex2f(.6,-1.);
glVertex2f(.6,-.6); glVertex2f(.2,-.6); glVertex2f(.2,.6); glVertex2f(.6,.6);
glVertex2f(.6,1.);
glEnd
();
(-1,-1)
(1,-1)
(1,1)
(-1,1)
Slide87Line Strip
glBegin
(
GL_LINE_STRIP
);
glVertex2f(-.6,1.);
glVertex2f(-.6,.6); glVertex2f(-.2,.6); glVertex2f(-.2,-.6); glVertex2f(-.6,-.6); glVertex2f(-.6,-1.); glVertex2f(.6,-1.);
glVertex2f(.6,-.6); glVertex2f(.2,-.6); glVertex2f(.2,.6); glVertex2f(.6,.6);
glVertex2f(.6,1.);
glEnd
();
(-1,-1)
(1,-1)
(1,1)
(-1,1)
Slide88Line Loop
glBegin
(
GL_LINE_LOOP
);
glVertex2f(-.6,1.);
glVertex2f(-.6,.6); glVertex2f(-.2,.6); glVertex2f(-.2,-.6); glVertex2f(-.6,-.6); glVertex2f(-.6,-1.); glVertex2f(.6,-1.);
glVertex2f(.6,-.6); glVertex2f(.2,-.6); glVertex2f(.2,.6); glVertex2f(.6,.6);
glVertex2f(.6,1.);
glEnd
();
(-1,-1)
(1,-1)
(1,1)
(-1,1)
Slide89Polygon
glBegin
(
GL_POLYGON
);
glVertex2f(-.6,1.);
glVertex2f(-.6,.6); glVertex2f(-.2,.6); glVertex2f(-.2,-.6); glVertex2f(-.6,-.6); glVertex2f(-.6,-1.); glVertex2f(.6,-1.);
glVertex2f(.6,-.6); glVertex2f(.2,-.6); glVertex2f(.2,.6);
glVertex2f(.6,.6);
glVertex2f(.6,1.);
glEnd
();
(-1,-1)
(1,-1)
(1,1)
(-1,1)
OpenGL only supports
convex polygons
(and really only triangles)
Slide90Quads
glBegin
(
GL_QUADS
);
glVertex2f(-.6,1.);
glVertex2f(-.6,.6); glVertex2f(-.2,.6);
glVertex2f(-.2,-.6); glVertex2f(-.6,-.6); glVertex2f(-.6,-1.);
glVertex2f(.6,-1.);
glVertex2f(.6,-.6);
glVertex2f(.2,-.6);
glVertex2f(.2,.6);
glVertex2f(.6,.6);
glVertex2f(.6,1.);
glEnd
();
(-1,-1)
(1,-1)
(1,1)
(-1,1)
Slide91Quads
glBegin
(
GL_QUADS
);
glVertex2f(-.6,1.);
glVertex2f(-.6,.6); glVertex2f(-.6,-.6); glVertex2f(-.6,-1.); glVertex2f(.6,-1.);
glVertex2f(.6,-.6);
glEnd
();
glVertex2f(-.2,.6);
glVertex2f(-.2,-.6);
glVertex2f(.2,-.6);
glVertex2f(.2,.6);
glVertex2f(.6,.6);
glVertex2f(.6,1.);
Slide92Quads
glBegin
(
GL_QUADS
);
glVertex2f(-.6,1.);
glVertex2f(-.6,.6); glVertex2f(.6,.6); glVertex2f(.6,1.); glVertex2f(-.6,-.6); glVertex2f(-.6,-1.);
glVertex2f(.6,-1.); glVertex2f(.6,-.6);
glVertex2f(-.2,.6);
glVertex2f(-.2,-.6);
glVertex2f(.2,-.6);
glVertex2f(.2,.6);
glEnd
();
(-1,1)
(-1,-1)
(1,-1)
(1,1)
(-1,1)
Slide93Triangles
glBegin
(
GL_TRIANGLES
);
glVertex2f(-.6,1.);
glVertex2f(-.6,.6); glVertex2f(-.2,.6); glVertex2f(-.2,-.6); glVertex2f(-.6,-.6); glVertex2f(-.6,-1.); glVertex2f(.6,-1.); glVertex2f(.6,-.6); glVertex2f(.2,-.6); glVertex2f(.2,.6);
glVertex2f(.6,.6); glVertex2f(.6,1.);glEnd();
(-1,-1)
(1,-1)
(1,1)
(-1,1)
Slide94Triangles
glBegin
(
GL_TRIANGLES
);
glVertex2f(-.6,1.);
glVertex2f(-.6,.6); glVertex2f(-.2,.6); glVertex2f(-.6,1.); glVertex2f(-.2,.6); glVertex2f(.6,1.); glVertex2f(-.2,.6); glVertex2f(.2,.6); glVertex2f(.6,1.); glVertex2f(.2,.6);
glVertex2f(.6,.6); glVertex2f(.6,1.); …glEnd
();
(-1,-1)
(1,-1)
(1,1)
(-1,1)
Slide95Triangle Strip
glBegin
(
GL_TRIANGLE_STRIP
);
glVertex2f(-.6,1.);
glVertex2f(-.6,.6); glVertex2f(-.2,.6); glVertex2f(-.2,-.6); glVertex2f(-.6,-.6); glVertex2f(-.6,-1.); glVertex2f(.6,-1.);
glVertex2f(.6,-.6); glVertex2f(.2,-.6); glVertex2f(.2,.6); glVertex2f(.6,.6);
glVertex2f(.6,1.);
glEnd
();
(-1,-1)
(1,-1)
(1,1)
(-1,1)
Slide96Triangle Strip
glBegin
(
GL_TRIANGLE_STRIP
);
glVertex2f(-.6,1.);
glVertex2f(.6,1.); glVertex2f(-.2,.6); glVertex2f(.2,.6); glVertex2f(-.2,-.6); glVertex2f(.2,-.6); glVertex2f(.6,-1.);
glVertex2f(.6,-.6);glEnd();…
(-1,-1)
(1,-1)
(1,1)
(-1,1)
First two vertices prime the pump,
then every new vertex creates a triangle
connecting it to the previous two vertices
Slide97Triangle Fan
glBegin
(
GL_TRIANGLE_FAN
);
glVertex2f(-.2,.6);
glVertex2f(-.6,.6); glVertex2f(-.6,1.); glVertex2f(.6,1.); glVertex2f(.2,.6); glVertex2f(.2,-.6); glVertex2f(-.2,-.6);glEnd();…
(-1,-1)
(1,-1)
(1,1)
(-1,1)
First two vertices prime the pump,
then every new vertex creates a triangle
connecting it to the previous vertex and
the first vertex
Slide98Assigning Color
glColor3f(0,0,1);
glBegin
(GL_POLYGON);
glVertex2f(-1,1);
glVertex2f(-1,-1);
glVertex2f(1,-1);glEnd();
glColor3f(1,0,0);
glBegin
(GL_POLYGON);
glVertex2f(-1,1);
glVertex2f(-1,-1);
glVertex2f(1,-1);
glEnd
();
glColor3f(0,0,0);
glBegin
(GL_LINE_LOOP);
glVertex2f(-1,1);
glVertex2f(-1,-1);
glVertex2f(1,-1);
glEnd
();
glBegin
(GL_POLYGON);
glColor3f(0,1,0);
glVertex2f(-1,1);
glColor3f(0,0,1);
glVertex2f(-1,-1);
glColor3f(1,0,0);
glVertex2f(1,-1);
glEnd
();
Slide99Other Graphics Functionality in OpenGL
- Viewport projection and transformation
gl
u
Perspective
( fovy, aspect, zNear, zFar ) gluLookAt (eyex, eye
y, eyez, at
x
,
at
y
,
at
z
,
up
x
,
up
y
,
up
z
)
glFrustum
( left, right, bottom, top,
zNear
,
zFar
)
- Model transformation
glTranslate
{
fd
} (TYPE
x
, TYPE
y
, TYPE
z
)
glScale
{
fd
} (TYPE
x
, TYPE
y
, TYPE
z
)
glRotate
{
fd
} (TYPE
angle
,
TYPE
x
, TYPE
y
, TYPE
z
)
- Texturing
- Lighting
Slide100How to Convert a String to an integer?
String input =
name.getText
();
int
num = Integer.parseInt(input);You may want to catch the exception if input is not an integer or number string