Agenda For March 26 - PowerPoint PPT Presentation

1 / 10
About This Presentation
Title:

Agenda For March 26

Description:

Agenda For March 26. 2. PowerPoint Presentation on Graphical User ... 1. Reminder: QUIZ #3 (Variables) on Monday. 5. Mastery Questions Section 6.3 (page 51) ... – PowerPoint PPT presentation

Number of Views:50
Avg rating:3.0/5.0
Slides: 11
Provided by: member7
Category:
Tags: agenda | march | reminder

less

Transcript and Presenter's Notes

Title: Agenda For March 26


1
Agenda For March 26
1. Reminder QUIZ 3 (Variables) on Monday.
2. PowerPoint Presentation on Graphical User
Interface Components. http//members.shaw.ca/
rzamar/IT11/GUI_Components.ppt
3. PowerPoint Presentation on Variables
(Snowboarding Example). http//members.shaw.c
a/rzamar/IT11/Variables3.ppt
http//members.shaw.ca/rzamar/IT11/JavaComponents.
java
4. Mastery Questions Section 6.2 (page 47).
5. Mastery Questions Section 6.3 (page 51).
2
Graphical User Interface Components
What is a graphical user interface?
A graphical user interface (GUI) refers to the
various pieces that a program has which allows
a user to interact with the program. Each
individual type of piece is called a component.
Examples of some commonly used components are
buttons, labels, text fields and text areas.
The three basic steps for creating components in
your program are
1. Declaring the component.
2. Initializing the component.
3. Adding the component to the applet display
3
How Components Will Appear To The User
4
Step 1 Declaring The Component
A component should always be declared in the
variable declaration section (above the init
method).
For example
import java.awt. import java.applet. public
class myGui extends Applet Label myLabel
// label declarations Button myButton
// button declaration TextField
myTextField // text field declaration
TextArea myTextArea // text area
declaration public void init()
5
Step 2 Initializing The Component
Each component should be initialized in the
init() function of an applet. For example, the
init() function for the previous example might
contain the following code.
public void init() myLabel new Label("some
label") myButton new Button("button")
myTextField new TextField() myTextArea
new TextArea()
6
Step 2 Initializing The Component Continued
In order to complete the initialization of a java
component we must tell Java where to place this
component on screen and specify its size.
The setBounds(int x, int y, int w, int h) method
is used for this.
The following slide shows an example.
7
Example of the setBounds() Method
public void init() myLabel new Label("some
label") myButton new Button("button")
myTextField new TextField() myTextArea
new TextArea() myLabel.setBounds(10,10,100,20
) myButton.setBounds(120,10,100,20)
myTextField.setBounds(10, 50, 100, 20)
myTextArea.setBounds(10, 80, 210,210)
8
Adding the Component To The Applet Display
In order to display a component on the applet
display, we must use the add(Component) method.
For example
public void init() myLabel new Label("some
label") myButton new Button("button")
myTextField new TextField() myTextArea
new TextArea() myLabel.setBounds(10,10,100,20
) myButton.setBounds(120,10,100,20)
myTextField.setBounds(10, 50, 100, 20)
myTextArea.setBounds(10, 80, 210,210)
add(myLabel) add(myButton)
add(myTextField) add(myTextArea)
9
public class Gui extends Applet Label
myLabel Button myButton TextField
myTextField TextArea myTextArea public
void init() setLayout(null)
myLabel new Label("some label")
myButton new Button("button")
myTextField new TextField() myTextArea
new TextArea() myLabel.setBounds(10,10,100
,20) myButton.setBounds(120,10,100,20)
myTextField.setBounds(10, 50, 100, 20)
myTextArea.setBounds(10, 80, 210,210)
add(myLabel) add(myButton)
add(myTextField) add(myTextArea)

10
(No Transcript)
Write a Comment
User Comments (0)
About PowerShow.com