Results 1 to 11 of 11
Thread: how to make a simple panel??
- 05-16-2011, 01:39 PM #1
Member
- Join Date
- Mar 2011
- Posts
- 20
- Rep Power
- 0
how to make a simple panel??
hey hey everyone... im sitting here following a book on how to build java programs... and i have reached a point where im learning how to make a panel and draw lines inside... but i have a problem that eclipse that im using is telling me that the exampel from the book is wrong and i cant find out how to make it work.... this is the small class that should give me a panel to work with:
import java.awt.*;
public class DrawLine {
public static void main(String[] args) {
DrawingPanel panel = new DrawingPanel(200, 100);
Graphics g = panel.getGraphics();
g.drawLine(25, 75, 175, 25);
}
}
but when i try to run this and get my panel it sayes :
Exception in thread "main" java.lang.Error: Unresolved compilation problems:
DrawingPanel cannot be resolved to a type
DrawingPanel cannot be resolved to a type
at DrawLine2.main(DrawLine2.java:6)
can anyone pleas help me get this example to work???
- 05-16-2011, 02:24 PM #2
- Join Date
- Sep 2008
- Location
- Voorschoten, the Netherlands
- Posts
- 14,422
- Blog Entries
- 7
- Rep Power
- 29
Did you read what the compiler had to say? It can't find a definition of a type DrawingPanel. Have you defined it anywhere?
kind regards,
JosBuild a wall around Donald Trump; I'll pay for it.
- 05-16-2011, 02:30 PM #3
Member
- Join Date
- Mar 2011
- Posts
- 20
- Rep Power
- 0
not that i know of... but im only following what my book is telling me...
how would the line look if i had to define it???
- 05-16-2011, 02:37 PM #4
- Join Date
- Sep 2008
- Location
- Voorschoten, the Netherlands
- Posts
- 14,422
- Blog Entries
- 7
- Rep Power
- 29
Build a wall around Donald Trump; I'll pay for it.
- 05-16-2011, 03:50 PM #5
@ the OP.
What book is it? And (like Jos asked) how is the DrawingPanel defined?
I'm curious, but (or because) I just don't think it works that way. Normally you paint inside a paintComponent() method: that way "Swing" has the code at its disposal to repaint the image every time that's needed. Your method suggests painting a line once and then "the system" remembering "magically" how to do that again when needed.
So: provide all the code to convince me/us.
- 05-16-2011, 06:07 PM #6
Never use getGraphics() of a component. Learn how to correctly Perform Custom Painting.
db
- 05-17-2011, 01:45 PM #7
Member
- Join Date
- Mar 2011
- Posts
- 20
- Rep Power
- 0
the book im reading is : Building Java Programs
by: Stuart Reges & Marty Stepp
page.213.
and i cant provide you with any more code since that all the book says is what i wrote to begin with... i cant understand it my self so that is why im seeking help in here
- 05-17-2011, 01:53 PM #8
- Join Date
- Sep 2008
- Location
- Voorschoten, the Netherlands
- Posts
- 14,422
- Blog Entries
- 7
- Rep Power
- 29
- 05-17-2011, 02:41 PM #9
I'm flabbergasted!
I found the code for DrawingPanel on this page: Building Java Programs: A Back to Basics Approach, by Stuart Reges and Marty Stepp
ready for download.
It works, but it is nothing like a standard DrawingPanel, and in my first impression not something to confront a beginner with. It is hundreds of lines of code, with timers, Buffered Images and other tricks I'll need the rest of the week to study.
Not for normal mortals!Last edited by Jodokus; 05-17-2011 at 02:45 PM. Reason: spelling
- 05-17-2011, 02:51 PM #10
Member
- Join Date
- Mar 2011
- Posts
- 20
- Rep Power
- 0
cool that you found it... can you then tell me what i am doing wrong since mine issent working??
- 05-17-2011, 03:12 PM #11
I don't know. I did nothing special. Just dump your code and their DrawingPanel in a package.
I only just don't understand anyone using this kind of code in a beginnersbook. To speek with Jos, I can't imagine this book being worth the tree it's made of, but I didn't see the rest of course ;>)
Let me know when you get it working (and your opinion of the book's approach?).
By the way, the link of DarrylBurke is very good and tells most you need to know about painting!Last edited by Jodokus; 05-17-2011 at 03:33 PM. Reason: curious
Similar Threads
-
Can it be that hard to make simple chat?
By Ruuhkis in forum NetworkingReplies: 2Last Post: 02-25-2011, 06:13 PM -
panel on a panel not visible
By warchieflll in forum Advanced JavaReplies: 2Last Post: 01-29-2011, 09:29 PM -
Can't make static reference to non-static method -> huh?! Simple car prgm
By enerj in forum New To JavaReplies: 7Last Post: 09-24-2010, 06:09 AM -
How to make simple dicitonary J2ME
By batosai_fk in forum CLDC and MIDPReplies: 5Last Post: 06-15-2010, 07:16 AM -
make simple web service
By BigBear in forum Java ServletReplies: 2Last Post: 06-13-2010, 01:53 PM
Bookmarks