Presentation on theme: "Lecture 3 A First Graphic Program. Features of a simple graphic program."— Presentation transcript:
Lecture 3 A First Graphic Program
Features of a simple graphic program
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.
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).
simple graphic program – Main() Main() The main entry point for the system is in class Gapp.
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.
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.
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.
First Program - Running
Graphics Primitives A graphics primitive is a drawing function which the system makes available to the applications programmer. Example is the Java “drawLine()” method.