how to move a figure around

Hello

I would like your advice on my new hobby project.

I would like to draw a gif image on the screen and then move a crosshair over the picture.

The gif is a geografical map.

The crossHair will be positioned by the data from my gps reciever.

So when I move my laptop around the city the crossHair will always be on my current position.

What library shall I use?

Java 2D seems the obvious choice but is it?

Thanks

[470 byte] By [gerarddoetsa] at [2007-11-26 23:53:35]
# 1

> The crossHair will be positioned by the data from my

> gps reciever.

So it will not be moved by the user? Then you should draw the crosshair on using an image and Graphics.drawImage(...)

> So when I move my laptop around the city the

> crossHair will always be on my current position.

Do you know how to get your GPS data into your java app? This is what I'd be most concerned about to start with.

> What library shall I use?

> Java 2D seems the obvious choice but is it?

I'd go with Java 2D unless/until you have a problem with it.

tjacobs01a at 2007-7-11 15:34:42 > top of Java-index,Security,Cryptography...
# 2
on before hand I have no problem using Java 2D. It's just I only find examples on foto editing.This is about constantly redrawing a crossHair on top of an image.Ok, thanks for your reaction.I read myself into the documentation on java 2D
gerarddoetsa at 2007-7-11 15:34:42 > top of Java-index,Security,Cryptography...
# 3

Here is a simple example, you just call label.setXMarkLocation to update the X location on the map:

import java.awt.Color;

import java.awt.Graphics;

import java.awt.Point;

import java.awt.image.BufferedImage;

import java.net.URL;

import javax.imageio.ImageIO;

import javax.swing.ImageIcon;

import javax.swing.JFrame;

import javax.swing.JLabel;

public class XMarksTheSpotExample {

public static void main(String[] args) {

try {

JFrame frame = new JFrame();

frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

BufferedImage image = ImageIO.read(new URL("http://www.sabre23t.com/images/KL-R-3km-2-67-27jun05.gif"));

XMarkLabel label = new XMarkLabel(image);

frame.add(label);

frame.pack();

frame.setVisible(true);

label.setXMarkLocation(new Point(100, 100));

} catch (Exception e) {e.printStackTrace();}

}

private static class XMarkLabel extends JLabel {

private Point xMarkLocation = new Point();

public XMarkLabel(BufferedImage image) {

super(new ImageIcon(image));

}

public void setXMarkLocation(Point p) {

xMarkLocation.setLocation(p);

repaint();

}

protected void paintComponent(Graphics g) {

super.paintComponent(g);

g = g.create();

g.setColor(Color.BLUE);

g.drawString("X", xMarkLocation.x, xMarkLocation.y);

g.dispose();

}

}

}

Rodney_McKaya at 2007-7-11 15:34:42 > top of Java-index,Security,Cryptography...
# 4
thats great, I'll try it out now, thanks Rodney
gerarddoetsa at 2007-7-11 15:34:42 > top of Java-index,Security,Cryptography...
# 5

> Do you know how to get your GPS data into your java

> app? This is what I'd be most concerned about to

> start with.

Yes I got that working

public static void main(String[]args){

try{

GPSDataProcessor gpsdataprocessor = new GPSNmeaDataProcessor();

Hashtable environment=new Hashtable();

environment.put(GPSSerialDevice.PORT_NAME_KEY,"COM1");

environment.put(GPSSerialDevice.PORT_SPEED_KEY,new Integer(4800));

GPSDevice gpsdevice = new GPSSerialDevice();

gpsdevice.init(environment);

gpsdataprocessor.setGPSDevice(gpsdevice);

System.out.println ("gpsdataprocessor.open()");

gpsdataprocessor.open();

PropertyChangeListener listener = new PropertyChangeListener (){

public void propertyChange (PropertyChangeEvent event ) {

Object value = event.getNewValue ( ) ;

String name = event.getPropertyName ( ) ;

if (name.equals (GPSDataProcessor.LOCATION) ) {

GPSPosition gpspos = (GPSPosition)value;

System.out.println ("De new location is "+ gpspos.getLatitude() +" | " + gpspos.getLongitude() ) ;

}

}

};

gpsdataprocessor.addGPSDataChangeListener(GPSDataProcessor.LOCATION,listener);

gerarddoetsa at 2007-7-11 15:34:42 > top of Java-index,Security,Cryptography...