📄 mapperclientapplet.java
字号:
}
}
/*//////////////////////////////////////////////////////////////////////////////////////////////////
连接servelet得到初始url
///////////////////////////////////////////////////////////////////////////////////////////////////*/
void initMap()
{
try
{
String url = m_servletName + "?init=true&m_Width=" + MapPicWidth+"&m_Height=" + MapPicHeigth;
mapServer = new URL(url);
//System.out.println(url);
URLConnection s = mapServer.openConnection();
in = new BufferedReader(new InputStreamReader(s.getInputStream()));
String inputLine=in.readLine();
if (inputLine != null)
{
m_sessionURL=inputLine;
//System.out.println("Received: "+inputLine);
}
//in.close();
}
catch (Exception e)
{
e.printStackTrace();
}
}
/*//////////////////////////////////////////////////////////////////////////////////////////////////
建立地图画布
///////////////////////////////////////////////////////////////////////////////////////////////////*/
class MCanvas extends Canvas//Panel
{
Image m_bufferedImage=null;
void setImage(Image i)
{
m_bufferedImage = i;
}
public void paint(Graphics g)
{
if (m_bufferedImage != null && g != null)
{
g.drawImage(m_bufferedImage, 0, 0, this);
}
}
public boolean imageUpdate(Image img, int infoflag, int x, int y,
int width, int height)
{
boolean result = true;
if ((infoflag & (ERROR | ABORT)) != 0)
{
result = false;
}
else
{
if ((infoflag & ALLBITS) != 0)
{
result = false;
}
repaint();
}
return result;
}
public void update(Graphics g)
{
paint(g);
}
/////////////////////////////////////////////////////////////////////////////
Point startPoint = new Point(0,0);
Point lastEndPoint = new Point(0,0);
Point thisEndPoint = new Point(0,0);
Point finalEndPoint = new Point(0,0);
public String drawStyle = "rect";
boolean figureState = false;
boolean firstDraw = true;
public MCanvas(){
addMouseListener(new MouseAdapter(){
public void mousePressed(MouseEvent e){
Graphics g = getGraphics();
g.setXORMode(getBackground());
drawFigure(g,startPoint,finalEndPoint);
// drawFigure(g,startPoint,finalEndPoint);
// drawFigure(g,startPoint,finalEndPoint);
// drawFigure(g,startPoint,thisEndPoint);
// drawFigure(g,startPoint,thisEndPoint);
startPoint.x = lastEndPoint.x = thisEndPoint.x = e.getPoint().x;
startPoint.y = lastEndPoint.y = thisEndPoint.y = e.getPoint().y;
setCursor(Cursor.getPredefinedCursor(Cursor.CROSSHAIR_CURSOR));
figureState = true;
}
public void mouseReleased(MouseEvent e){
finalEndPoint.x = e.getPoint().x;
finalEndPoint.y = e.getPoint().y;
setCursor(Cursor.getPredefinedCursor(Cursor.DEFAULT_CURSOR));
Graphics g = getGraphics();
//g.setColor(Color.white);
g.setXORMode(getBackground());
if(firstDraw)
drawFigure(g,startPoint,finalEndPoint);
figureState = false;
firstDraw = true;
drawFigure(g,startPoint,thisEndPoint);
drawFigure(g,startPoint,thisEndPoint);
g.dispose();
}
});
addMouseMotionListener(new MouseMotionAdapter(){
public void mouseDragged(MouseEvent e){
Graphics g = getGraphics();
// g.setColor(Color.black);
g.setXORMode(getBackground());
if(figureState){
lastEndPoint.x = thisEndPoint.x;
lastEndPoint.y = thisEndPoint.y;
thisEndPoint.x = e.getPoint().x;
thisEndPoint.y = e.getPoint().y;
}
if(firstDraw){
drawFigure(g,startPoint,thisEndPoint);
firstDraw = false;
}else {
drawFigure(g,startPoint,lastEndPoint);
drawFigure(g,startPoint,thisEndPoint);
}
g.dispose();
}
});
///////////////////////////////////////////////////////////////////
addMouseListener(new MouseAdapter()
{
int PointCount=0;
public void mouseClicked(MouseEvent e)
{
//System.out.println(m_tool);
if (m_tool == RULER_TOOL)
{
xOra = e.getX();
yOra = e.getY();
if (xTemp == 0 && yTemp == 0) {
xTemp = xOra;
yTemp = yOra;
}
PointCount++;
Graphics g = getGraphics();
g.setColor(Color.red);
g.drawLine(xTemp, yTemp, xOra, yOra);
//blndraw = true;
xTemp = xOra;
yTemp = yOra;
//repaint();
if (e.getClickCount() == 2){
lCarStatus.setText("");
xTemp = 0;
yTemp = 0;
m_tool=PAN_TOOL;
dDistance=0;
double x=116.368855;
double y=39.179225;
try
{
String url = m_sessionURL;
// url += "?ptx=" + new Integer(x);
//url += "&pty=" + new Integer(y);
url += "?ptx=" + x;
url += "?pty=" + y;
url += "&tool=" + m_tool;
mapServer = new URL(url);
//System.out.println(url);
URLConnection s = mapServer.openConnection();
adjustMap(url);
//in = new BufferedReader(new InputStreamReader(s.getInputStream()));
//String inputLine=in.readLine();
//if (inputLine != null)
//{
// m_sessionURL=inputLine;
// System.out.println("Received: "+inputLine);
//}
//in.close();
}
catch (Exception ee)
{
ee.printStackTrace();
}
//g.dispose();
}
}
}
});
}
public void setDrawStyle(String style){
drawStyle = style;
}
public void drawFigure(Graphics g,Point start,Point end){
if(drawStyle == "line"){
g.drawLine(start.x,start.y,end.x,end.y);
}else if(drawStyle == "rect"){
int x = start.x ,y = start.y;
if(end.x < start.x) x = end.x;
if(end.y < start.y) y = end.y;
g.drawRect(x,y,Math.abs(end.x - start.x),Math.abs(end.y - start.y));
}else if(drawStyle == "oval"){
int x = start.x ,y = start.y;
if(end.x < start.x) x = end.x;
if(end.y < start.y) y = end.y;
g.drawOval(x,y,Math.abs(end.x-start.x),Math.abs(end.y - start.y));
}
}
}
//end of MCanvas
//Component initialization
private void jbInit() throws Exception {
//////////////////////////////////////////////////////////
//得到公司名称
//// companyName = this.getParameter("companyName");
// companyid=this.getParameter("G_ID");
companyid="300";
System.out.println("the value of G_ID in applet: "+companyid);
// Ismanager=Integer.parseInt(this.getParameter("ismanager"));
//companyName="现代";
// Ismanager=1;
// System.out.println("the value of Ismanager in applet: "+Ismanager);
// user_cardid=this.getParameter("cardid");
// user_cardid="11000001";
System.out.println("the value of user_cardid in applet: "+user_cardid);
// this.setLayout(null);
this.setLayout(new BorderLayout());
this.add(m_map,BorderLayout.CENTER);
JPanel jp = new JPanel();
jp.setLayout(new BorderLayout());
lCarStatus.setBackground(Color.white);
lCarStatus.setForeground(Color.blue);
jp.add(lCarStatus);
lCarStatus.setPreferredSize(new Dimension(0,20));
// lCarStatus.setBounds(0,MapPicHeigth-100,MapPicWidth,20);
initTable();
jp.add(this.jScrollPaneRight,BorderLayout.SOUTH);
jScrollPaneRight.setPreferredSize(new Dimension(0,80));
jp.setPreferredSize(new Dimension(0,100));
this.add(jp,BorderLayout.SOUTH);
//jTable.setRowHeaderVisible(true) ;
////////////////////////////////////////////////////////////
//得到车辆信息
////////////////////////////////////////////////////////////
m_tool=INITCAR_TOOL;
String url =m_sessionURL + "?tool=" + m_tool;
//System.out.println("this is dapeng's"+url);
GetCarInfo(url);
m_tool=NO_TOOL;
////////////////////////////////////////////////////////////
//得到车辆信息 end
////////////////////////////////////////////////////////////
// jTable.updateUI();
// jScrollPaneRight = new JScrollPane(jTable);
jp.updateUI();
//////////////////////////////////////////////////////////
}
private void initTable() {
jScrollPaneRight.setHorizontalScrollBarPolicy(JScrollPane.HORIZONTAL_SCROLLBAR_AS_NEEDED);
jScrollPaneRight.setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_ALWAYS);
jScrollPaneRight.setViewportBorder(BorderFactory.createLineBorder(Color.black));
// this.add(lCarStatus,null);
// this.add(m_map, null);
jTable.setBounds(0,MapPicHeigth-80,MapPicWidth,80);
// this.add(jScrollPaneRight, null);
//this.add(label1, null);
jTable.setBorder(BorderFactory.createLoweredBevelBorder());
jTable.setCellSelectionEnabled(true);
//jTable.setEditable(false);
jTable.setEnabled(true);
jTable.setCellSelectionEnabled(false);
//jdbTable.setTableHeader(null);
//this.setBackground(Color.magenta);
//this.add(jdbTable, null);
jScrollPaneRight.setBounds(new Rectangle(0, 336, 622, 80));
jScrollPaneRight.getViewport().add(jTable, null);
//jdbTable.setBounds(0, 8, 100,140);
// String row[]=new String[11];
// jTable.setDataSet(null);
// tableModel.addColumn("车辆ID");
tableModel.addColumn("车主姓名");
tableModel.addColumn("车辆牌照");//车辆牌照颜色 纬度 纬度
tableModel.addColumn("SIM卡号");
tableModel.addColumn("车辆类型");
tableModel.addColumn("颜色");
tableModel.addColumn("类型");
tableModel.addColumn("纬度");
tableModel.addColumn("经度");
// tableModel.addColumn("定位状态");
// tableModel.addColumn("GPS型号");
// tableModel.addColumn("类型");
// tableModel.addColumn("登记日期");
tableModel.addColumn("速度");
tableModel.addColumn("定位时间");
//tableModel.addColumn("公司");
//tableModel.addColumn(companyName);
jTable.setAutoResizeMode(JTable.AUTO_RESIZE_ALL_COLUMNS );
jTable.setRowSelectionAllowed(true);
jTable.setModel(tableModel);
}
//Start the applet
public void start() {
}
//Stop the applet
public void stop() {
}
//Destroy the applet
public void destroy() {
}
//Get Applet information
public String getAppletInfo() {
return "Applet Information";
}
//Get parameter info
public String[][] getParameterInfo() {
return null;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -