Results 1 to 3 of 3
  1. #1
    Nes_java is offline Member
    Join Date
    Apr 2011
    Posts
    5
    Rep Power
    0

    Default problem in DrawingPanel

    I have written code like my textbook into jgrasp, as below:

    import java.awt.*;
    public class DrawLine2 {
    public static void main(String[] args) {
    DrawingPanel panel = new DrawingPanel(200, 100);
    Graphics g = panel.getGraphics();
    g.drawLine(25, 75, 100, 25);
    g.drawLine(100, 25, 175, 75);
    g.drawLine(25, 75, 175, 75);
    }
    }

    but when I compile this code, there are some errors from jgrasp:

    DrawLine2.java:4: cannot find symbol
    symbol : class DrawingPanel
    location: class DrawLine2
    DrawingPanel panel = new DrawingPanel(200, 100);

    So, can you help me solve this problem?
    How should I do to draw the panel?
    thanks all

  2. #2
    DarrylBurke's Avatar
    DarrylBurke is offline Member
    Join Date
    Sep 2008
    Location
    Madgaon, Goa, India
    Posts
    11,197
    Rep Power
    19

    Default

    Do you have a class named DrawingPanel?

    Also, never use getGraphics() of a component. Learn how to correctly perform custom painting:
    Lesson: Performing Custom Painting (The Java™ Tutorials > Creating a GUI With JFC/Swing)

    If your textbook recommends using getGraphics() of a component, consign it to the trash can and get a real book.

    db

  3. #3
    Nes_java is offline Member
    Join Date
    Apr 2011
    Posts
    5
    Rep Power
    0

    Default

    I've download an example of drawingLine.java from the internet, and execute it by jgrasp. I got the expected result.
    but, I don't relize the different between two programs.

    I tried to test again by copying the code from the program that I downloaded to make new program respectly.
    and, I get the same error above :(

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •