DevX Home    Today's Headlines   Articles Archive   Tip Bank   Forums   

+ Reply to Thread
Results 1 to 2 of 2
  1. #1
    Join Date
    Mar 2005
    Posts
    3

    Exclamation Compiler and Program Error


    4. import java.awt.Graphics;
    5. import javax.swing.JPanel;
    6.
    7. public class MyLines extends JPanel
    8. {
    9. // Declare variables
    10. int startingx;
    11. int startingy;
    12. int startingl;
    13.
    14. // Contruct values to work in the JPanel
    15. public MyLines (int x, int y, int l)
    16. {
    17. startingx = x;
    18. startingy = y;
    19. startingl = l;
    20. }
    21.
    22. // Start of the paint componet
    23. public void paintComponet ( Graphics g )
    24. {
    25. super.paintComponet (g);
    26. int v1;
    27. int v2;
    28. v1 = startingx;
    29. v2 = startingy;
    30.
    31. while ( v1 <= getWidth() )
    32. {
    33. g.drawLine( v1, v2, v1 + startingl, v2 );
    34. v1 += startingl;
    35.
    36. g.drawLine( v1, v2, v1, v2 + startingl );
    37. v2 += startingl;
    38. }
    39. }
    40. }


    I got the following error in my compiler for this driver code:

    .\MyLines.java:25: cannot find symbol
    symbol : method paintComponet(java.awt.Graphics)
    location: class javax.swing.JPanel
    super.paintComponet (g);
    ^
    1 error
    Need Help With Java

  2. #2
    Join Date
    Nov 2004
    Location
    Norway
    Posts
    1,560
    Its paintComponent(...).

    Having said that I would advise you to use this strategy instead,
    (and forget about super methods invokation):

    Code:
    public void update (Graphics g) {
      Color c=g.getColor();  // remember context color
      g.setColor(Color.lightGray);
      g.fillRect(0,0,getSize().width, getSize().height);
      int v1;
      int v2;
      v1 = startingx;
      v2 = startingy;
      g.setColor(Color.red); // or any other color,  except lightGray
      while (v1 <= getWidth()) {
        g.drawLine(v1, v2, v1 + startingl, v2);
        v1 += startingl;
        g.drawLine(v1, v2, v1, v2 + startingl);
        v2 += startingl;
      }
      g.setColor(c); // restore context color
    }
    public void paint(Graphics g) {
      update(g);
    }
    PS: never invoke the paint() method from the update() method, it will never finish....
    eschew obfuscation

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
HTML5 Development Center
 
 
FAQ
Latest Articles
Java
.NET
XML
Database
Enterprise
Questions? Contact us.
C++
Web Development
Wireless
Latest Tips
Open Source


Top DevX Stories

Easy Web Services with SQL Server 2005 HTTP Endpoints
JavaOne 2005: Java Platform Roadmap Focuses on Ease of Development, Sun Focuses on the "Free" in F.O.S.S.
Wed Yourself to UML with the Power of Associations
Microsoft to Add AJAX Capabilities to ASP.NET
IBM's Cloudscape Versus MySQL


Sponsored Links