|
-
Jul 26th, 2005, 04:58 PM
#1
Thread Starter
Dazed Member
Coordinate System?
I wanted to see if i could get some ideas on what would be the best way to create a floating coordinate system using two JSliders and a Canvas. Ive been having trouble figuring out how to sync up the JSliders and the drawing of the lines on the Canvas.
Last edited by Dilenger4; Jul 27th, 2005 at 03:52 PM.
Reason: Changed thread title
-
Jul 27th, 2005, 02:53 AM
#2
Re: Design Pattern Question
? I am a big confused here ? Doesn't the JSlider have an event? Can't you just use it?
- ØØ -
-
Jul 27th, 2005, 06:39 AM
#3
Frenzied Member
Re: Design Pattern Question
Hey, this is exaclty what I'm doing. I did something with an interest rate:
int value = interestRateSlider.getValue();
int rate = (double)(1+(.01*value));
First of all, I made my slider go from like 0 to 500 so that I would have plenty of room for decimals and stuff like that.
I got the value from the slider, then created a double out of it with 2 decimal places, and that was it. After that, mortgages were calculated and points were added to arraylists and then it was off to the canvas class to repaint.
-
Jul 27th, 2005, 02:39 PM
#4
Thread Starter
Dazed Member
Re: Design Pattern Question
Posted by NoteMe
? I am a big confused here ? Doesn't the JSlider have an event? Can't you just use it?
What i want to do is have a JSlider at the south portion of a JFrame and a JSlider to the east each with a line comming out spanning across a Canvas. So the lines are always going to be intersecting.
I guess what i need is two classes that extend JSlider and implement a ChangeListener interface and ask for a repaint when a ChangeEvent is fired off. The problem is that JSlider has a getValue() method and to draw a line i need to use g.drawLine(int x1, int y1, int x2, int y2). Also if the drawLine() method is shared by both JSlider classes how does the paint method within my class that extends canvas know which JSlider is being slid?
-
Jul 28th, 2005, 06:21 AM
#5
Frenzied Member
Re: Coordinate System?
You need to have variables or flags in the other class. I did the same thing except I drew intersecting lines with the mouse motion listener.
public void changeHappend(ChangeEvent ce)
{
int x = ce.getValue();
CanvasName.x = x;
CanvasName.repaint();
}
in canvas class:
if (x != 0 && y != 0)
{
g.drawLine(0,y,100,y);
g.drawLine(x,0,x,100);
}
-
Jul 28th, 2005, 03:16 PM
#6
Thread Starter
Dazed Member
Re: Coordinate System?
Thanks for the help System_Error. I will give that a try.
-
Aug 5th, 2005, 03:36 PM
#7
Frenzied Member
Re: Coordinate System?
Ever figure something out?
-
Aug 5th, 2005, 09:13 PM
#8
Thread Starter
Dazed Member
Re: Coordinate System?
I stared to make some changes then got sidetracked.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|