0% found this document useful (0 votes)
32 views

GUI Notes

Uploaded by

segunelijah2010
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
32 views

GUI Notes

Uploaded by

segunelijah2010
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 5

CHAPTER SIX

GUI (GRAPHIC USER INTERFACE)

Graphic User Interface:- It is a mechanism that allows user to interact with

applications. In java, we have two major libraries;

i. Swing Library:- It is the latest and platform independence

ii. AwT library :- (Abstract Windows Toolkit) former platform dependence for

swing library, there is uniformity in the ‘Look and Feel’ of GUI

component across all platform but AWT on the other hand, the look

and feel perspective of the component depends on the platform on

which the program is being run. To use any of this library simply code

Javax.swing.(name of the component); or

Javax.swing.(name of the component);

e.g. javax.swing.joptionpane;

javax.awt.flowlayout

however where the name of the component to be use is not known or

in case you intend to use all component available in that library,

simply code

javax.swing.*

javax.awt.*

Overview of swing component

1. J label (=) Label box is used for uneditable text

2. J text field (=) Text box is used for entering and accepting data

3. J button (=) command button is used to trigger an event or action

26
4. J combobox (=) combobox is used to drop down list

5. J Radio button (=) Radio button is used to select single item from a

list

6. J checkbox (=) check box is used to select multiple items from a

list

7. JUST (=) list box is used to list items from where selection is made

8. J password field (-) password textbox is used to provide box for

security code

9. J panel :- container / frame. It provides an arena / environment

where other component reside.

Review on the use of Joption pane

Joption pane is used for inputting and outputting

Import.javax.swing.joptionpane;

Public class illustration

Public static void main (string arg [J] )

Int num 1, num 2, sum

String no 1, no 2;

No 1 = Joption pane.show input dialog (“Enter 1st number”)

No 2 = Joption pane.show input dialog (“Enter 2nd number”)

Num 1 = integer. Parse Int (1st number)

Num 2 = integer. Parse Int (2nd number)

27
Sum = num 1 + num 2;

Joption pane. Showmessage Dialog (null, “The sum is =”, + sum)

Joption pane message Dialogue

We have five difference joption pane message dialogue boxes.

Type Icon Description

1. Error_message it indicate error message to user

2. Information_ ¿ it displays an information message

to a user

3. Warning_message ! it specifies warning message to a

user

4. Question_message ? it posses a question to a user

5. Plain_message no icon it displays just a message to a

user e.g. operational or computational message e.g.

Joptionpane. Showmessage Dialogue

(null, “the sum is =”, +sum, “AJ Application”,

joptionpane.PLAIN_MESSAGE);

28
Example

A program that allows a users intension to be made known during input

operation by inputting [1-5] where

1. Outputs – ‘you want to input data’

2. Outputs – ‘you are about deleting a data’

3. Outputs – ‘are you sure you want to delete’

4. Outputs – ‘you are performing an operation’

5. Outputs – ‘Exit application’

6. Outputs – ‘data out of range’

Solution

Import.javax.swing.joptionpane

Import.java.util.scanner

Public

Public

Scanner my data = new scanner (system.in)

Int user input = my data.nextint( );

Switch (user input)

Case 1: joptionpane.showmessage dialog (null, ‘you want to input data’,

joption. INFORMATION_MESSAGE)

29
Case 2: joptionpane.showmessage dialog (null, ‘you are about deleting a data’,

joption. WARNING_MESSAGE)

Break;

Case 3: joptionpane.showmessage dialog (null, ‘are you sure you want to

delete’, joption. QUESTION_MESSAGE)

Break;

Case 4: joptionpane.showmessage dialog (null, ‘you are performing an

operation’, joption. INFORMATION_MESSAGE)

Break;

Case 5: joptionpane.showmessage dialog (null, ‘data out of range’, joption.

ERROR_MESSAGE)

30

You might also like