用java怎么获得一张图片上的一个文字的坐标点 求高手解答

用java怎么获得一张图片上的一个文字的坐标点 求高手解答,第1张

//提示坐标依次打印在命令符窗口

//提示:坐标依次打印在命令符窗口

//提示:坐标依次打印在命令符窗口

//不就是监听鼠标事件吗?

import javaxswing;

import javaawt;

import javaawtevent;

import javaxswingborderBorder;

/

我想建立个界面,可以加载本机中。

加载后可以通过鼠标点击获得上任意点坐标。

提问者: sunny929929 - 试用期 一级

/

public class MyPicture extends JFrame implements MouseListener{

 private JLabel tipLabel;

 /

 main()

 /

 public static void main(String[] args){

  MyPicture frame = new MyPicture();

   framesetDefaultCloseOperation(JFrameEXIT_ON_CLOSE);

   framesetVisible(true);

    }

/

    constructor

    /

    public MyPicture(){

  setSize(800, 600);//根据要求调整大小

  setLocation(100,100);

  setTitle("获得上任意点坐标");

        setResizable(false);

        Container con=getContentPane();

        ImageIcon bgIcon=new ImageIcon("bgpicjpg");//注意的路径

  ImagePanel backpicPanel=new ImagePanel(bgIcon);

  backpicPaneladdMouseListener(this);

  conadd(backpicPanel,BorderLayoutCENTER);

  tipLabel=new JLabel("--------------------提示:坐标依次打印在屏幕上!--------------------");

  conadd(tipLabel,BorderLayoutSOUTH);

 }

/

 

 /

 public void mousePressed(MouseEvent e){

  int x=egetX();

  int y=egetY();

  String message="("+x+","+y+")";

  tipLabelsetText(message);

  Systemoutprintln(message);

 }

 public void mouseReleased(MouseEvent e){

 }

 public void mouseEntered(MouseEvent e){

 }

 public void mouseExited(MouseEvent e){

 }

 public void mouseClicked(MouseEvent e){

 }

}

/

 类ImagePanel,用于添加背景

 /

class ImagePanel extends JPanel{

 private   Image   img;

    public  ImagePanel (ImageIcon   imageIcon){

     img=imageIcongetImage();

    }

    public  void  paintComponent(Graphics   g){

     superpaintComponent(g);

     gdrawImage(img,0,0,this);

    }

}

//你运行一下,看在你的电脑上能不能用。

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

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

import javaawtDimension;

import javaawtMouseInfo;

import javaawtPoint;

import javaawtRobot;

import javaawteventActionEvent;

import javaawteventActionListener;

import javaawteventMouseEvent;

import javaawteventMouseMotionListener;

import javaxswingJButton;

import javaxswingJFrame;

import javaxswingWindowConstants;

public class MouseHelp extends javaxswingJPanel 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();

framegetContentPane()add(new MouseHelp());

framesetDefaultCloseOperation(WindowConstantsDISPOSE_ON_CLOSE);

framepack();

framesetVisible(true);

}

public MouseHelp() {

super();

initGUI();

}

private void initGUI() {

try {

robot=new Robot();

addMouseMotionListener(this);

setPreferredSize(new Dimension(400, 300));

thissetLayout(null);

{

textButton = new JButton();

thisadd(textButton);

textButtonsetText("\u8fd0 \u884c");

textButtonsetBounds(136, 72, 127, 22);

textButtonaddActionListener(new ActionListener(){

public void actionPerformed(ActionEvent e) {

robotmouseMove(30,745);

try {

Threadsleep(1000);

robotmousePress(MouseEventBUTTON1_MASK);

robotmouseRelease(MouseEventBUTTON1_MASK);

Threadsleep(1000);

robotmouseMove(150,481);

robotmousePress(MouseEventBUTTON1_MASK);

robotmouseRelease(MouseEventBUTTON1_MASK);

} catch (InterruptedException e1) {

// TODO Auto-generated catch block

e1printStackTrace();

}

}});

}

} catch (Exception e) {

eprintStackTrace();

}

}

public void mouseDragged(MouseEvent e) {

// TODO Auto-generated method stub

}

public void mouseMoved(MouseEvent e) {

// TODO Auto-generated method stub

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

//Point mousepoint = MouseInfogetPointerInfo()getLocation();

//Systemoutprintln(mousepointx+"\t"+mousepointy);

}

}

以上就是关于用java怎么获得一张图片上的一个文字的坐标点 求高手解答全部的内容,包括:用java怎么获得一张图片上的一个文字的坐标点 求高手解答、java获取鼠标坐标、等相关内容解答,如果想了解更多相关内容,可以关注我们,你们的支持是我们更新的动力!

欢迎分享,转载请注明来源:内存溢出

原文地址:https://54852.com/web/9316526.html

(0)
打赏 微信扫一扫微信扫一扫 支付宝扫一扫支付宝扫一扫
上一篇 2023-04-27
下一篇2023-04-27

发表评论

登录后才能评论

评论列表(0条)

    保存