Win a copy of JDBC Workbook this week in the JDBC and Relational Databases forum
or A Day in Code in the A Day in Code forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Paul Clapham
  • Jeanne Boyarsky
  • Junilu Lacar
  • Henry Wong
Sheriffs:
  • Ron McLeod
  • Devaka Cooray
  • Tim Cooke
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Frits Walraven
  • Tim Holloway
  • Carey Brown
Bartenders:
  • Piet Souris
  • salvin francis
  • fred rosenberger

click outside arc detector

 
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
Sheriff
Posts: 7023
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
George Taylor
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 7023
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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?
 
No more fooling around. Read this tiny ad:
Devious Experiments for a Truly Passive Greenhouse!
https://www.kickstarter.com/projects/paulwheaton/greenhouse-1
    Bookmark Topic Watch Topic
  • New Topic