aspose file tools*
The moose likes Applets and the fly likes click outside arc detector Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Soft Skills this week in the Jobs Discussion forum!
JavaRanch » Java Forums » Java » Applets
Bookmark "click outside arc detector" Watch "click outside arc detector" New topic
Author

click outside arc detector

George Taylor
Greenhorn

Joined: Apr 27, 2002
Posts: 3
I am currently trying to write an applet to model dragging an object around a track and counting the number of times the user inadvertently crosses over the track boundary - whilst this is ok for straight lines i am finding it very hard to write the code for the "arc" sections of a track that is roughly U-shaped).
Any help would be greatly appreciated
Dirk Schreckmann
Sheriff

Joined: Dec 10, 2001
Posts: 7023
earningstuff,
Welcome to JavaRanch!
We ain't got many rules 'round these parts, but we do got one. Please change your display name to comply with The JavaRanch Naming Policy.
Thank You
--------------------------
Concerning detecting the location of mouse events, it's a pretty straight-forward process (really). If you were to post some example code of what you are trying to accomplish, it'd probably be easier to help you figure things out.
Good Luck.


[How To Ask Good Questions] [JavaRanch FAQ Wiki] [JavaRanch Radio]
George Taylor
Greenhorn

Joined: Apr 27, 2002
Posts: 3
here is the code i am writing - i want to be able to drag the ball around the track! this i can do but i want to be able to count the number of times the user leaves the track. In the straight sections this is fine but the arcs are causing a few problems ! my current thinking to is try and redraw as aa roundrect and then use the mousedragged and mousexited methods - is this possible?
any help will be greatly appreciated
************************************
import java.awt.*;
import java.applet.Applet;
import java.awt.event.*;
import java.awt.Graphics;
public class Game extends Applet implements ActionListener {
int radius=50;
int BaseX=80;
int BaseY=100;
private Button start;
private Button stop;
int balld=10;
private int tw=20;
private TextField twField;
private TextField balldField;

public void init()
{
start=new Button("Start");
add(start);
start.addActionListener(this);
stop=new Button("Stop");
add(stop);
stop.addActionListener(this);
Label tws = new Label("TrackWidth:");
add(tws);
twField = new TextField(10);
add(twField);
twField.addActionListener(this);
balldField = new TextField(10);
add(balldField);
balldField.addActionListener(this);
}
public void paint(Graphics g)
{
g.setColor(Color.white);
g.fillRect(10,10,500,600);
g.setColor(Color.black);
displayTrack();
displayBall();
}
public void displayTrack()
{
Graphics g = getGraphics();
//OUTSIDE ARC
g.drawArc(BaseX,BaseY,((2*tw)+(2*radius)),((2*tw)+(2*radius)),90,180);
//INSIDE ARC
g.drawArc(BaseX+tw,BaseY+tw,(2*radius),(2*radius),90,180);

//BOTTOM straightlines
g.drawLine(BaseX+radius+tw,BaseY+(2*tw)+(2*radius),BaseX+(2*radius)+(2*tw),BaseY+(2*tw)+(2*radius));
g.drawLine(BaseX+radius+tw,BaseY+tw+(2*radius),BaseX+(2*radius)+(2*tw),BaseY+tw+(2*radius));

//TOP Straightlines
g.drawLine(BaseX+radius+tw,BaseY,BaseX+(2*radius)+(2*tw),BaseY);
g.drawLine(BaseX+radius+tw,BaseY+tw,BaseX+(2*radius)+(2*tw),BaseY+tw);
}
public void displayBall()
{
Graphics g = getGraphics();
g.setColor(Color.red);
g.fillOval(BaseX+(2*radius)+(3*tw),BaseY+tw+(2*radius), balld,balld);
}
public void actionPerformed(ActionEvent event)
{

if (event.getSource() == start)
{
Graphics g = getGraphics();
tw = Integer.parseInt(twField.getText());
balld = Integer.parseInt(balldField.getText());
if (balld >= tw)
{
balld=(tw/2);
}
displayTrack();
displayBall();
}
repaint();
}
}
Dirk Schreckmann
Sheriff

Joined: Dec 10, 2001
Posts: 7023
Your code doesn't actually do anything yet concerning moving a ball around a track. You'd mentioned that you had it working in the straight sections. It would seem to me, that would be a good place to start in figuring out the curves. So, what have you got so far?
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: click outside arc detector