Presentation is loading. Please wait.

Presentation is loading. Please wait.

Lecture 3 A First Graphic Program. Features of a simple graphic program.

Similar presentations


Presentation on theme: "Lecture 3 A First Graphic Program. Features of a simple graphic program."— Presentation transcript:

1 Lecture 3 A First Graphic Program

2 Features of a simple graphic program

3 Gapp and Gcanvas are ours – Are New Developed. Inherited from JFrame and panel which are part of the Java Foundation Classes - in particular they are part of the swing” GUI components. when a Gapp object is created, a new GUI window appears on the screen.

4 Features of a simple graphic program A Gcanvas/JPanel is simply something we can draw on, but it isn’t allowed to be on screen by itself, it must be part of a JFrame. So what we actually need is an instance of Gapp with an instance of Gcanvas “inside” it (Figure 23).

5 simple graphic program – Main() Main() The main entry point for the system is in class Gapp.

6 simple graphic program- initComponents() sets the window’s screen position and size (lines 22,23), sets up some Java apparatus to allow the program to shut down cleanly. (lines 27-31) and creates an instance of a Gcanvas (graphics canvas). line 25. This GCanvas object is “added” to the Gapp object and hence becomes part of that window.

7 simple graphic program- Paintcomponent() it is passed a Graphics object (“g”) - line 12. drawLine() which is a member of the Graphics class. The Graphics class is part of the standard Java class library and its member functions are termed “graphics primitives”. There exist a whole range of methods for drawing and coloring in a variety of shapes (boxes, polygons, ovals etc.) Take a look at the Java API documentation for full details.

8 simple graphic program- Paintcomponent() The drawLine() method takes 4 parameters, x1, y1, x2, y2 which represent the start and end points of the line you wish to draw.

9 First Program

10

11

12

13 First Program - Running

14 Graphics Primitives A graphics primitive is a drawing function which the system makes available to the applications programmer. Example is the Java “drawLine()” method.

15 Graphics Primitives

16

17

18

19


Download ppt "Lecture 3 A First Graphic Program. Features of a simple graphic program."

Similar presentations


Ads by Google