Raschin Ghanad

+ Follow
since Jul 28, 2004
Merit badge: grant badges
For More
Cows and Likes
Total received
In last 30 days
Total given
Total received
Received in last 30 days
Total given
Given in last 30 days
Forums and Threads
Scavenger Hunt
expand Ranch Hand Scavenger Hunt
expand Greenhorn Scavenger Hunt

Recent posts by Raschin Ghanad

I have a scollpane and a Panel in it.
Without the scollpane, I can resize my Panel as I want, it repaints always correctly.

I don't use any Layout manager, I ask how much size does my frame gives me to draw and then calculate all relative corrdinates from this numbers.

Why does it display wrong when scrolling in the scrollpane?
Is it possible to catch all the events, that my scollpane sends to my Panel?

Maybe that would be a way to see what really happens/what goes wrong...
19 years ago

I have some principal question to this Graphics2D class:

It seems, that the use of this class transforms my drawing in some way.
Could this be possible?

I was reading a little around in the API-documentation and there was something about this AffineTransform class and that my Graphcis2D context
uses a default instance of that.

I would like to draw 1 : 1, so , like I give the coordiantes to my function.

Does somebody knows something about this?
[ August 11, 2004: Message edited by: Raschin Ghanad ]
19 years ago
sorry, I forgot to write it correctly...
I did it with g2.drawString(...)

the real code was:

I tried to write it in an easy, understanding way...
19 years ago
can anyone help me, I am trying to rotate the text for the scale of my x-axis, but when I use the Graphics2D rotate-method, everything disappears...

I did it the following way:


Why don't I see anything?
Maybe I have to use other coordinates?
I tried many variants, but non worked...

Maybe theres another way to rotate a text?
19 years ago
thanks, but I think this is not exactly what I need...

To the first answer from Ryan Smith :

The second post from you could maybe work, if I alter it.

I have already a curve that connects the Points together with
lines. So far is everything fine.

The problem is that you have to switch in the program how to display the curve.
So I have also to display the curve with rounded lines, and also as stairs.

To the answer from Craig Wood :

This seems to be a better idea (to work with a Path and the quadTo/curveTo- method) , but your code does not round the lines in the way I need it.
As I said, the problem is to connect the points in a way, that there is a bended line, that displays the increase/decrease of the data.

I think your curves are something like the Bezier-curves....

If I would know how to get the right control-points for my curve, the problem would be solved, I think...
[ August 02, 2004: Message edited by: Raschin Ghanad ]
19 years ago
I have used the GeneralPath Class to draw a path, but nothing appears on the screen...
If I draw with the Line2D Class everythings seems to be fine...
Does anyone sees some failure in my Code ? :

class CurvePanel extends JPanel {

GeneralPath path = new GeneralPath();

public CurvePanel() {

protected void paintComponent(Graphics g) {
Graphics2D g2 = (Graphics2D)g;

public void addCurve(Vector v) {
int[] x = new int[v.size()+1];
int[] y = new int[v.size()+1];
int i = 0;

for (Iterator iter = v.iterator(); iter.hasNext() {
Point p = (Point) iter.next();
x[i] = (int) p.getX();
y[i] = (int) p.getY();

for(int u=1;u<i;u++) {
path.moveTo(x[u], y[u]);

Even if I close the Path, there is no effect.
DoI have to close my Path?
[ July 30, 2004: Message edited by: Raschin Ghanad ]
19 years ago
I have a basic question about painting.
When I want to add dynamically lines,
is it possible to append everytime one line to my Graphic Context?

I tried so, but everytime it repaints(), all previouse lines got lost.
So I stored them all in a Vector, and each time the Panel repaints,
it gets the whole data from the Vector to draw.

The Problem is now,that I sometimes get a NullPointer Exception, but I don't know exactly why.
So, I think it's not a good solution for my Problem.

I have to cast each Element of my Vector to a Basic type, that I've defined in as an extra Interface. This Basic-Type just has the method paint().

Otherwise it was'nt possible to draw the elements of my Vector.
The elements were just Line-Objects (I also wrote a class Line, that implements Basic)

I did it like this:

and got java.lang.NullPointerException

This appears only sometimes, I don'tknow exactly why...It seems there is a rerference to an object that does not exists?

The Code how I build this Vector:
(The function gets a Vector filled with Point-Objects)

and for completion, here is the "Line" Class I've defined:

[ July 29, 2004: Message edited by: Raschin Ghanad ]
[ July 29, 2004: Message edited by: Raschin Ghanad ]
19 years ago
yes, thats what I was thinking about, too.
But how can I override it without creating a new class that extends a JPanel and then adding it?

Can't I use my actual paint-Method to write into the Graphic-Context of the the component using the getGraphcis() method?

Sorry, I haven't time to read the tut, but I will do so in a while.

thanx for fast response
[ July 29, 2004: Message edited by: Raschin Ghanad ]
19 years ago
I have a Panel that has a Panel inside (to get some inset in my Panel.)
The problem is, that it just works, if I draw into the main Panel.
If I try to get the Graphic context of my other JPanel and write into it,
I just see my drawing for breaks of seconds when I rezise the Frame (where the JPanelis inside).
If I don't resize, I see nothing, if I finish resizing, the same.

Here ist my Code.
Maybe the paint-Method is just called when resizing now?

Can anyone help ?
Is there another possibility to get some inset for my drawing Area?

Here is my Code:

[ July 29, 2004: Message edited by: Raschin Ghanad ]
19 years ago
I have a little question about how to make curves out of points.

My function has many points and I have to get them to one curve.
At the moment, it is just necessary to put a line(/path) from point to point.

I thought about using the GeneralPath - class, but I don't know how to use it.

Maybe someone can tell me which class to use is the best for this problem?

19 years ago