pemrograman lanjut - universitas brawijaya filelayout manager layout manager automatically decides...

28
Pemrograman Lanjut PTIIK - 2014 GUI (Graphical User Interface)

Upload: dinhnhu

Post on 04-Aug-2019

217 views

Category:

Documents


0 download

TRANSCRIPT

Pemrograman Lanjut

PTIIK - 2014

GUI (Graphical User Interface)

Objectives

Mampu mengimplementasikan komponen-komponen GUI

2

Buttons and Actions

Adding a button to a frame

Layout managers

Action listeners

Registering a listener with a GUI component

The actionPerformed() method

The content pane of a frame

Changing the background color of a frame

3

Swing Components

4

Program with a Button

Run the Program!

5

Layout Manager

Layout Manager automatically

decides what components size will

be and where they will go

You can add components without

worrying about the details

There are several kinds of layout

managers, each layout manager

has a different style of positioning

components

6

FlowLayout Manager

FlowLayout manager puts components into the

frame row by row in the order they are added

7

Setting the Layout Manager

8

Event Listener Object

When a GUI program is running, the user

generates an event by interacting with a GUI

component.

For a program to respond to an event there must

be an event listener object for it.

A event listener object contains a listener

method for a specific type of event.

Programs ignore events if there is no listener for

them.

9

Event Object

An event listener is an object that

"listens" for events from a GUI

component, like a button

An event, like a button click, is

represented as an object

When the user generates an

event, the system creates an

event object which is then sent

to the listener that has been

registered for the GUI

component. Then, a method in

the listener object is invoked.

10

ActionListener

11

ActionListener

12

Complete Program

13

Relations and Program's Output

14

New Program

15

Buttons and Action Events

Components that make up the Graphical User

Interface. we've done this

Listener methods that receive events and

respond to them. we've done this

Application methods that do useful work for the

user. we've not done this, yet.

16

Two Buttons

17

Not Quite Correct Program

18

Corrected actionPerformed()

19

JTextFields

JTextField is a box that contains a line of text.

The user can type text into the box and the

program can get it and then use it as data, and

can write the results of a calculation to it

20

JTextField Class Hierarchy

21

Application with a JTextField

22

JLabel

23

JLabel

Listener for JTextField

24

25

Task 1

Buatlah Aplikasi GUI tentang kalkulator

sederhana

26

Task 2

Buatlah Aplikasi dengan GUI untuk menghitung

gaji bersih karyawan dengan komponen berikut:

Pendapatan

• Gaji Kotor

• Tunjangan Keluarga

• Uang Makan Jumlah Kehadiran * Rp. 9.000,-

• Uang Lembur Jumlah Jam * Rp. 5.000,-

Pengeluaran

• PPh (5% dari Gaji Kotor)

• Iuran Kematian (Rp. 5.000,-)

• Iuran Koperasi (Rp. 10.000,-)

Gaji Bersih = Pendapatan - Pengeluaran

27

[email protected]

081 331 834 734 / 088 160 127 40