Return Styles: Pseud0ch, Terminal, Valhalla, NES, Geocities, Blue Moon.

Pages: 1-

Defining areas for mouselistener in Java?

Name: Anonymous 2007-07-04 10:04 ID:zJcfOP/9

Well, I have to code a risk clone in java (yes, fail) and I need the program to select the province when clicked on - so I need to define these areas some way. My idiot instructor suggested that I add every pixel manually, and I happen to prefer dying over it.

I am sure there is a more intelligent way, but does anyone know?

Name: Anonymous 2007-07-04 10:13 ID:AKSJ0b5D

who cares

Name: Anonymous 2007-07-04 11:07 ID:djQkpocw

use polygons

Name: Anonymous 2007-07-04 11:17 ID:x7VCuLe9

Use a bitmap with region 1 in colour 1, region 2 in colour 2, etc. for lookup. Polygons are fine, too.

Name: Anonymous 2007-07-04 12:07 ID:xtJT+2Ic

you have a bitmap of each region. you know where you place it. To iterate through all the bitmaps and check to see if your click was there is not hard. Fuck you guys are such retards.

Name: Anonymous 2007-07-04 12:34 ID:VpzFcPq6

>>1
Use color keys, i.e. what >>4 said.
Oh, wait. You said Java?

Well then, you want to define a class hierarchy for geometric information, like (all classes):

Geometry (abstract)
    Geometry2D (abstract)
        GeometricShapes (abstract)
            Polygon (holds a list of Axis)
                Triangle (for convenience)
                Square (for convenience)
                RegularPolygon
                    RegularTriangle (for convenience)
        Geometry2DTypes (abstract)
            Point
            Axis (aggregates 2 Point)


Well, this was actually a stub. The final implementation will most surely implement more classes, as well as a few interfaces to describe geometry.

Then you define methods for creating these shapes, associate them to objects describing your provinces (again, under a class hierarchy to model universes, galaxies, solar systems, planets, continents, countries, states, autonomous communities, provinces, counties, towns, neighbourhoods, residential and other types of areas and parcels), and find whether a point you recover from mouse information, casted or recreated as a geometric point and contemplating a certain offset (which you may model as inherited properties in the geometry class hierarchy somehow) will belong to an area.

That would be appropriate for a Java job.

Name: Anonymous 2007-07-04 12:35 ID:Heaven

>>5
shit solution

>>4
good, simple solution

>>3
might work if the area boundraries are simple, but you'd still need to iterate so it's not much better than >>5

Name: Anonymous 2009-03-06 12:15

Geometry YOU BITCH IDIOT.

Name: Anonymous 2010-11-15 2:12

Name: Anonymous 2011-02-04 15:36

Name: Anonymous 2011-02-17 19:47

that's cool and all, but check my doubles over there

Don't change these.
Name: Email:
Entire Thread Thread List