java 建立直角坐标系

Python013

java 建立直角坐标系,第1张

//不能用的话肯定是坐标不对

//把mouseMoved方法里的注释去掉重新获取

import java.awt.Dimension

import java.awt.MouseInfo

import java.awt.Point

import java.awt.Robot

import java.awt.event.ActionEvent

import java.awt.event.ActionListener

import java.awt.event.MouseEvent

import java.awt.event.MouseMotionListener

import javax.swing.JButton

import javax.swing.JFrame

import javax.swing.WindowConstants

public class MouseHelp extends javax.swing.JPanel implements MouseMotionListener {

private JButton textButton

Robot robot

/**

* Auto-generated main method to display this

* JPanel inside a new JFrame.

*/

public static void main(String[] args) {

JFrame frame = new JFrame()

frame.getContentPane().add(new MouseHelp())

frame.setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE)

frame.pack()

frame.setVisible(true)

}

public MouseHelp() {

super()

initGUI()

}

private void initGUI() {

try {

robot=new Robot()

addMouseMotionListener(this)

setPreferredSize(new Dimension(400, 300))

this.setLayout(null)

{

textButton = new JButton()

this.add(textButton)

textButton.setText("\u8fd0 \u884c")

textButton.setBounds(136, 72, 127, 22)

textButton.addActionListener(new ActionListener(){

public void actionPerformed(ActionEvent e) {

robot.mouseMove(30,745)

try {

Thread.sleep(1000)

robot.mousePress(MouseEvent.BUTTON1_MASK)

robot.mouseRelease(MouseEvent.BUTTON1_MASK)

Thread.sleep(1000)

robot.mouseMove(150,481)

robot.mousePress(MouseEvent.BUTTON1_MASK)

robot.mouseRelease(MouseEvent.BUTTON1_MASK)

} catch (InterruptedException e1) {

// TODO Auto-generated catch block

e1.printStackTrace()

}

}})

}

} catch (Exception e) {

e.printStackTrace()

}

}

public void mouseDragged(MouseEvent e) {

// TODO Auto-generated method stub

}

public void mouseMoved(MouseEvent e) {

// TODO Auto-generated method stub

//从这里获取鼠标的全局坐标

//Point mousepoint = MouseInfo.getPointerInfo().getLocation()

//System.out.println(mousepoint.x+"\t"+mousepoint.y)

}

}

若是独立坐标系,无转换参数是无法取得wgs84坐标的。若是wgs84的坐标的空间直角坐标的形式,你可以从网上coord转换,图标是一个小笑脸,坐标转换应当可以搜到。补充:既然是两组10位数字,那肯定就不是经纬度咯,建议你先了解一下坐标系统。我国目前常用的坐标系有北京54坐标系,西安80坐标系以及WGS84。