1 / 19

Exploring Simple Graphic Program Features in Java

This lecture discusses the key features of a simple graphic program using Java, including Gapp and Gcanvas components inherited from Java Foundation Classes. Learn about creating GUI windows, drawing on Gcanvas inside a JFrame, and utilizing graphics primitives for shapes. Dive into the main method, initComponents, and Paintcomponent functions to understand how to develop your first graphic program in Java effectively.

eavan
Download Presentation

Exploring Simple Graphic Program Features in Java

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

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. Features of a simple graphic program

  4. 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). Features of a simple graphic program

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

  6. 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- initComponents()

  7. 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()

  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. First Program

  11. First Program

  12. First Program

  13. First Program - Running

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

  15. Graphics Primitives

  16. Graphics Primitives

  17. Graphics Primitives

  18. Graphics Primitives

More Related