O'Reilly logo

Java™ How To Program (Early Objects), Tenth Edition by Harvey Deitel, Paul Deitel

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

First Drawing Application

Our first drawing application simply draws two lines. Class DrawPanel (Fig. 4.18) performs the actual drawing, while class DrawPanelTest (Fig. 4.19) creates a window to display the drawing. In class DrawPanel, the import statements in lines 3–4 allow us to use class Graphics (from package java.awt), which provides various methods for drawing text and shapes onto the screen, and class JPanel (from package javax.swing), which provides an area on which we can draw.

 1   // Fig. 4.18: DrawPanel.java 2   // Using drawLine to connect the corners of a panel. 3   import java.awt.Graphics;  4   import javax.swing.JPanel; 5  6   public class DrawPanel extends JPanel 7   { 8      // draws an X from ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required