Title: Applet
1Applet
- contains GUI components such as
- buttons
- text fields
- labels
- check boxes
- choices
2GUI Components
- when GUI components are clicked, dragged, or
manipulated, events are triggered
3Panel
a container for related GUI components
4Button
component that triggers a specific action
button
5Button
import java.awt. import java.applet. public
class SampleButton extends Applet public
void init() Panel pnlName new
Panel() //change color of
panel pnlName.setBackground(Color.
green) //command button
Button cmdDeposit new
Button("Deposit") //add command
button to panel
pnlName.add(cmdDeposit)
//command button Button
cmdWithdraw new Button("Withdraw")
continuation
pnlName.add(cmdWithdraw) add(pnlName)
6TextField
- A component that allows input into the program or
to display information
textfield
7TextField
import java.awt. import java.applet. public
class SampleTextField extends Applet
public void init() Panel pnlName new
Panel() //change color of panel pnlName.setBackg
round(Color.green) TextField txtName new
TextField (20) pnlName.add(txtName) Panel
pnlButtons new Panel() pnlButtons.setBackground
(Color.black) //command button Button
cmdDeposit new Button("Deposit") //add command
button to panel pnlButtons.add(cmdDeposit)
Button cmdWithdraw new Button("Withdraw") //ad
d command button to panel pnlButtons.add(cmdWithdr
aw) add(pnlName) add(pnlButtons)
8Label
- a component that provides information
- it is read only
label
9Label
import java.awt. import java.applet. public
class SampleLabel extends Applet public void
init() Panel pnlLogin new Panel() //change
color of panel pnlLogin.setBackground(Color.green)
Label lblLogin new Label("Login
") pnlLogin.add(lblLogin) TextField txtLogin
new TextField (10) pnlLogin.add(txtLogin) Panel
pnlPassWord new Panel() pnlPassWord.setBackgro
und(Color.red) Label lblPassWord new
Label("Pass word ") pnlPassWord.add(lblPassWord)
TextField txtPassWord new TextField(10) pnlPass
Word.add(txtPassWord) Panel pnlButtons new
Panel() pnlButtons.setBackground(Color.black) B
utton cmdSubmit new Button("Submit") pnlButtons
.add(cmdSubmit) add(pnlLogin)
add(pnlPassWord) add(pnlButtons)
10Check Box
Check box
- offers a set of choices
- any number of check boxes can be selected
check box
11Options
Check box
- offers a set of exclusive choices
- only one option can be selected
option
12Check Boxes / Options
import java.awt. import java.applet. public
class CheckOptions extends Applet public void
init() Panel pnlCheck new Panel() //change
color of panel pnlCheck.setBackground(Color.green)
Checkbox chkApples new Checkbox
("Apples") pnlCheck.add(chkApples) Checkbox
chkOranges new Checkbox ("Oranges") pnlCheck.ad
d(chkOranges) Checkbox chkPears new Checkbox
("pears") pnlCheck.add(chkPears)
Panel pnlOption new Panel() pnlOption.setBackgr
ound(Color.red) Choice optGender new
Choice() optGender.add("Female") optGender.add("
Male") pnlOption.add(optGender) add(pnlCheck
) add(pnlOption)
option
check box