Russian version
English version
| | | | SILICON TAIGA | ISDEF | CD | | | | | | | |
 
 
 
IT-
 
 
 
RSS-

Java-

Java-, Java-, - , -. , , . , .

-, HTML- , "" . , , Java Map, . , , . , HTML- , Java . "" "" .

, - . , Map.dat , "" . : . , :

# Global map picture
V0.jpg

# Map area definition
202 214 55 55 V1.jpg
202 159 55 55 V2.jpg
257 159 55 55 V3.jpg
257 214 55 55 V4.jpg
92 214 55 55 V7.jpg
147 214 55 55 V8.jpg
147 159 55 55 V9.jpg
92 159 55 55 V10.jpg

1. Map.dat

"#" .

Java-. Map.java. :

import java.applet.*;

public class Map extends Applet
{
/**
* Initialization.
*/
public void init()
{
//
//
}
}

2. Map.java

( 2) : . . getData() Map.dat. ( ) InputStream StreamTokenizer java.io. StreamTokenizer , InputStream (). Map.dat : . , nextToken() . , : StreamTokenizer.TT_EOF, StreamTokenizer.TT_NUMBER, StreamTokenizer.TT_WORD. , "#", commentChar().

:

/**
* Read the data file Map.dat.
*/
protected void getData()
{
InputStream is=null;
int i=0;
int ix=0;
int x=0,y=0,w=0,h=0;

try
{
try
{
is = new URL(getCodeBase(),
"Map.dat").openStream();
StreamTokenizer st =
new StreamTokenizer(is);

st.eolIsSignificant(false);
st.commentChar('#');

while (st.ttype !=
StreamTokenizer.TT_EOF)
{
st.nextToken();

if (st.ttype==st.TT_NUMBER)
{
int n = (int) st.nval;
switch (i)
{
case 0:
x = n;
break;
case 1:
y = n;
break;
case 2:
w = n;
break;
case 3:
h = n;
break;
}
i++;
if (i==4)
{
lPoint[ix] = new Point(x,y);
rPoint[ix] = new Point(w,h);
i=0;
}
//continue;
}

if(st.ttype==st.TT_WORD)
{
mapFile[ix]=st.sval;
ix++;
}
} /* while */
}
catch (MalformedURLException e) {}
}
catch (IOException e) {}
count=ix;
}

3. getData()

, lPoint rPoint. Point , . Point, awt, , X,Y. mapFile - .

getMap(). pic, . repaint();

/**
* Get file of map picture from URL.
*/
private void getMap(String pic)
{
map = getImage(getCodeBase(), pic);
repaint();
}

/**
* Update applet.
**/
public void update(Graphics g)
{
paint(g);
}

public void paint(Graphics g)
{
g.drawImage(map,0,0,this);
g.setColor(Color.black);
g.drawRect(0,0,size().width-1,
size().height-1);
if (!isZoom & curId!=0)
{
g.setColor(Color.red);
g.drawRect(lPoint[curId].x,
lPoint[curId].y,
rPoint[curId].x,
rPoint[curId].y);
}
}

4. getMap(), update() paint()

isZoom, true, , .. . / . , , , (, ), "" . , .

public boolean mouseUp(Event evt, int x, int y)
{
if (isZoom)
{
isZoom=false;
getMap(mapFile[0]);
}
else
{
if (curId == 0)
{
showStatus("This area have not zoom.");
}
else
{
isZoom=true;
getMap(mapFile[curId]);
}
}
return true;
}

public boolean mouseMove(Event evt, int x, int y)
{
int i;
i = getIndex(x,y);

if (!isZoom)
{
if (curId != i)
{
if (curId != 0)
repaint(lPoint[curId].x,
lPoint[curId].y,rPoint[curId].x+1,
rPoint[curId].y+1);
if (i != 0)
showArea(i);
curId = i;
}
}
return true;
}

/**
* Show area under mouse pointer.
**/
private void showArea(int i)
{
Graphics g = null;
g = this.getGraphics();
g.setColor(Color.red);
g.drawRect(lPoint[i].x,
lPoint[i].y,
rPoint[i].x,
rPoint[i].y);
}

/**
* Get index of map image.
**/
private int getIndex(int x, int y)
{
for (int i=1; i=lPoint[i].x
& x<=(lPoint[i].x+rPoint[i].x)
& y>=lPoint[i].y
& y<=(lPoint[i].y+rPoint[i].y))
return i;
return 0;
}

5.

, - , .

/**
* Show message in status line.
**/
private void zoomStatus()
{
String msg;
if (isZoom)
msg="Click for unzoom";
else
msg="Click for zoom";
showStatus(msg);
}

5. zoomStatus()

, , , , :

import java.awt.*;
import java.awt.image.*;
import java.applet.*;
import java.net.*;
import java.io.*;

public class Map extends Applet
{

int max=100;

Image map;
int count;

Point lPoint[];
Point rPoint[];

String mapFile[]=new String[max];

int curId;
boolean isZoom;

/**
* Initialization.
*/
public void init()
{
lPoint = new Point[max];
rPoint = new Point[max];

getData();
getMap(mapFile[0]);
}

6.

Map.class HTML-. :


, , HTML-


     
 
 
  : 04.05.2006  

| | | | SILICON TAIGA | ISDEF | CD | | | | | | | |

: Silicon Taiga    
Rambler's Top100 Rambler's Top100