Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
0% found this document useful (0 votes)
6 views

Lec 10- Introduction to JAVA GUI Programming and Database Connection

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

Lec 10- Introduction to JAVA GUI Programming and Database Connection

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

CS SE 1209 & IT 1210

Lecture 09 & 10
Introduction to JAVA GUI Programming and Database
Connection
30/07/2024
Bachelor of Science (Hons) in Computer Science | Software Engineering | Information Technology
Department of Computing
Faculty of Computing and Technology
Saegis Campus
Nugegoda

1
T.L.Navodi Sithara Saegis Campus
Graphical User Interface
Many Java application use a graphical user interface or GUI.
• A GUI is a graphical window or windows that provide interaction with the
user.
• GUI’s accept input from:
– the keyboard
– a mouse.
• A window in a GUI consists of components that:
– present data to the user
– allow interaction with the application.

2
T.L.Navodi Sithara Saegis Campus
Introduction
• Some common GUI components are:
– buttons, labels, text fields, check boxes, radio buttons, combo boxes, and sliders.

3
T.L.Navodi Sithara Saegis Campus
GUI Programming

• Basic types of GUI Programs


– Stand-alone applications
– Applets

• Stranded GUI library


– AWT
– SWINIG

4
T.L.Navodi Sithara Saegis Campus
Abstract Windowing Toolkit(AWT)

• IS a Original Java GUI API


• Very limited in capability
– Few components
– API not well structured, particularly event handling for user
actions
– Not entirely portable (used native widgets)

5
T.L.Navodi Sithara Saegis Campus
JFC/Swing
• Java Foundation Classes (or “Swing”)
– Replacement for AWT (although does share some classes)
– Also provide basis for developing new GUI features (which are being continually added)

• What does Swing include?


– 100% Java
– Swing components (more, and more sophisticated)
– Pluggable Look and Feel Support
– Accessibility API
– Better graphics support (Java 2D)
– Drag and Drop

Important to use Swing and not AWT

– Swing is the recommended way to build Java GUIs

6
T.L.Navodi Sithara Saegis Campus
Design Stages of the GUI
1. Design the user interface
– Organising pre-built GUI components to build windows,dialogs
– E.g buttons, tables, menus, etc

2. Writing the application logic


– What does the application do?

3. Writing event-handling code to tie the GUI


components to the application logic

7
T.L.Navodi Sithara Saegis Campus
User interface
• A GUI is built in layers.

• Bottom most layer is the window (Container)


– Contains all other components
– Can provide basic features like maximise/minimise buttons,title bar, menu bar, etc

• On top of this are layered (Component)


– Components, e.g. buttons, text fields
– or intermediate containers, e.g. panels

• Arrangement of components in a contained is handled by a layout manager


– Its job is to instruct components on how to arrange themselves so the GUI is drawn
correctly.

8
T.L.Navodi Sithara Saegis Campus
GUI Programming

• This layered GUI can be viewed as a hierarchy of components

– NOT an inheritance hierarchy,


– It just describes how components are nested one within another

9
T.L.Navodi Sithara Saegis Campus
GUI Application

10
T.L.Navodi Sithara Saegis Campus
The containment hierarchy

11
T.L.Navodi Sithara Saegis Campus
Swing Top level containers
• JWindow
– Basic no frills window, just a square on the screen

• JFrame
– The basic Swing window. Offers basic window controls,resizable

• JDialog
– For building dialog boxes, e.g. File open/save

• JApplet
– For building applets, embedded into a web page

12
T.L.Navodi Sithara Saegis Campus
SWING containers
• Panel
• Scroll Pane
• Tool Bar etc

13
T.L.Navodi Sithara Saegis Campus
Controls

14
T.L.Navodi Sithara Saegis Campus
Working with JFrames
• Many different possibilities, but the basics include:

– Setting window title


– Setting location on screen
– Setting size of window
– Restricting resizes
– Set close operation (exit the program), as by default it does nothing.

15
T.L.Navodi Sithara Saegis Campus
GUI Programming

16
T.L.Navodi Sithara Saegis Campus
Simple GUI Application

17
T.L.Navodi Sithara Saegis Campus
Database Connection

18
T.L.Navodi Sithara Saegis Campus
Connecting With Database
In order to connect Java program with the MySQL database, we need to
include MySQL JDBC driver which is a JAR file, namely mysql-connector-
java-8.0.13-bin.jar.

Make sure that you have installed the MySQL server on your machine.

19
T.L.Navodi Sithara Saegis Campus
20
T.L.Navodi Sithara Saegis Campus
21
T.L.Navodi Sithara Saegis Campus
22
T.L.Navodi Sithara Saegis Campus
23
T.L.Navodi Sithara Saegis Campus
24
Lecturer Name Saegis Campus

You might also like