Presentation is loading. Please wait.

Presentation is loading. Please wait.

GUI AND GRAPHICS.

Similar presentations


Presentation on theme: "GUI AND GRAPHICS."— Presentation transcript:

1 GUI AND GRAPHICS

2 CLASS LIBRARIES import java.awt.Graphics; import javax.swing.JPanel; import javax.swing.JFrame;

3 HOW DO WE DRAW? Graphics: reference for shapes, contains the paintComponent JPanel: provides an area to draw JFrame: Holds and displays the panel

4 A Simple Application Window
A stand-alone GUI (Graphical User Interface) application runs in a window. Code for application window exists in class ‘JFrame’

5 Main Class JFrame Create a window Set the frame to exit
Add panel to frame Set the size of the frame Make the frame visible

6 Code for Application Window

7 Displaying ‘MyClass’ Panel
This happens in the main class Create a window (JFrame) with an object to call ‘MyClass’ Window has specifications

8 ‘MyClass’ extends JPanel
Create a new class – Panel to be displayed MyClass for drawing must extend JPanel Inheritance relationship, ‘MyClass’ will begin with existing members of class JPanel JPanel is the superclass ; MyClass is the subclass

9 paintComponent Method
Every JPanel contains a paintComponent method Used to display panel Syntax: public void paintComponent( Graphics g) Requires one argument, a Graphics object: super.paintComponent(g);

10 Create a New Class to hold Panel

11 Add Panel to Frame


Download ppt "GUI AND GRAPHICS."

Similar presentations


Ads by Google