• 大小: 1KB
    文件类型: .rar
    金币: 1
    下载: 0 次
    发布日期: 2021-05-17
  • 语言: Java
  • 标签: java  swing  

资源简介

直接运行就可以弹出swing页面,然后根据鼠标移动位置在界面显示鼠标坐标位置,亲测有用,欢迎下载

资源截图

代码片段和文件信息

package com.yang.controller;
import java.awt.BorderLayout;
import java.awt.FlowLayout;

import javax.swing.JButton;
import javax.swing.JDialog;
import javax.swing.Jframe;
import javax.swing.JPanel;
import javax.swing.border.EmptyBorder;
import javax.swing.JLabel;
import java.awt.Font;
import java.awt.Point;
import java.util.Timer;
import java.util.TimerTask;
import java.awt.Color;

public class MouseInfo extends Jframe {

    private final JPanel contentPanel = new JPanel();
    JLabel value_x = null;
    JLabel value_y = null;

    /**
     * Launch the application.
     */
    public static void main(String[] args) {
        try {
            final MouseInfo info_frame = new MouseInfo();
            info_frame.setDefaultCloseOperation(Jframe.EXIT_ON_CLOSE);
            info_frame.setVisible(true);
            info_frame.setAlwaysOnTop(true);
            Timer timer = new Timer();
            timer.schedule(new TimerTask() {
                @Override
                public void run() {
                    Point point = java.awt.MouseInfo.getPointerInfo().getLocation();
                    // System.out.println(“Location:x=“ + point.x + “ y=“ +
                    // point.y);
                    info_frame.value_x.setText(““ + point.x);
                    info_frame.value_y.setText(““ + point.y);
                }
            } 100 100);
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    /**
     * Create the dialog.
     */
    public MouseInfo() {
        settitle(“\u9F20\u6807\u5750\u6807\u83B7\u53D6\u5668“);
        setBounds(100 100 217 156);
        getContentPane().setLayout(new BorderLayout());
        contentPanel.setBorder(new EmptyBorder(5 5 5 5));
        getContentPane().add(contentPanel BorderLayout.CENTER);
        contentPanel.setLayout(null);

        JLabel lblx = new JLabel(“\u5750\u6807x:“);
        lblx.setFont(new Font(“宋体“ Font.PLAIN 15));
        lblx.setBounds(22 27 66 31);
        contentPanel.add(lblx);

        JLabel lbly = new JLabel(“\u5750\u6807y:“);
        lbly.setFont(new Font(“宋体“ Font.PLAIN 15));
        lbly.setBounds(22 68 66 31);
        contentPanel.add(lbly);

        value_x = new JLabel(“0“);
        value_x.setForeground(Color.BLUE);
        value_x.setFont(new Font(“宋体“ Font.PLAIN 20));
        value_x.setBounds(82 27 66 31);
        contentPanel.add(value_x);

        value_y = new JLabel(“0“);
        value_y.setForeground(Color.BLUE);
        value_y.setFont(new Font(“宋体“ Font.PLAIN 20));
        value_y.setBounds(82 68 66 31);
        contentPanel.add(value_y);
    }
}

 属性            大小     日期    时间   名称
----------- ---------  ---------- -----  ----

     文件       2726  2018-09-07 11:54  获取鼠标坐标swing\MouseInfo.java

     目录          0  2018-09-07 11:57  获取鼠标坐标swing

----------- ---------  ---------- -----  ----

                 2726                    2


评论

共有 条评论