java代码选址坐标(java怎样获取鼠标在屏幕的坐标)

本文目录
- java怎样获取鼠标在屏幕的坐标
- Java中如何给JButton/JLabel定位置【高分悬赏】
- 求用ECLIPSE java编一个鼠标获取坐标代码!
- Java中 如何使用java.awt.Graphics 来确定图形坐标 譬如:直线,三角系,椭圆,圆,矩形之类的图像,要怎
- 如何用java把数据用坐标实时显示出来代码越全越好
- java.让用户输入x坐标,和y坐标当用户输入完x坐标(比如200),敲enter,
- 求大神Java坐标编程
- java窗体坐标获取
- 求高手 怎么用JAVA语言写 随机取N点坐标 筛选出距离小于500米的
- java程序的坐标怎么写
java怎样获取鼠标在屏幕的坐标
代码如下:
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 {
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);
}
}
Java中如何给JButton/JLabel定位置【高分悬赏】
setLocation
public void setLocation(int x,
int y)将组件移到新位置。通过此组件父级坐标空间中的 x 和 y 参数来指定新位置的左上角。
参数掘搜:
x - 父级坐标空间中新位置左上角的 x 坐标
y - 父级坐标空间中新位置左上角的 y 坐标
setLayout会覆逗散陆盖setLocation行为,
setLocation()不能保证跨平台的界面一致性
setLocation 的X,Y坐标不是画面上的,
下边是山顷给你改的代码.用setBounds来设置坐标及大小.
-------------------------------------------------------------
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
public class GUI {
private static JFrame frame = new JFrame("GUI test");
private static JPanel panel = new JPanel();
private static JLabel label = new JLabel("GUI label test");
private static JButton button = new JButton("Button1");;
public static void main(String args) {
frame.setLayout(null);
panel.setLayout(null);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setSize(800, 768);
panel.add(button);
// button.setLocation(100, 100);
button.setBounds(100, 100, 160, 24);
panel.add(label);
// label.setLocation(50, 50);
panel.setBounds(0, 0, 700, 700);
frame.add(panel);
frame.setVisible(true);
}
}
求用ECLIPSE java编一个鼠标获取坐标代码!
package com.wz.test1;
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
public class Painter extends JFrame {
private int pointCount = 0;
// array of 1000 java.awt.Point references
private Point points;
// set up GUI and register mouse event handler
public Painter()
{
super( "A simple paint program" );
// create a label and place it in SOUTH of BorderLayout
getContentPane().add( new JLabel( "Drag the mouse to draw" ),
BorderLayout.SOUTH );
addMouseMotionListener(
new MouseMotionAdapter() { // anonymous inner class
// store drag coordinates and repaint
public void mouseDragged( MouseEvent event )
{
if ( pointCount 《 points.length ) {
points = event.getPoint();
++pointCount;
repaint();
}
}
} // end anonymous inner class
); // end call to addMouseMotionListener
setSize( 300, 150 );
setVisible( true );
} // end Painter constructor
// draw oval in a 4-by-4 bounding box at specified location on window
public void paint( Graphics g )
{
super.paint( g ); // clears drawing area
for ( int i = 0; i 《 points.length && points != null; i++ )
g.fillOval( points.y, 4, 4 );
}
public static void main( String args )
{
Painter application = new Painter();
application.setDefaultCloseOperation( JFrame.EXIT_ON_CLOSE );
}
} // end class Painter
Java中 如何使用java.awt.Graphics 来确定图形坐标 譬如:直线,三角系,椭圆,圆,矩形之类的图像,要怎
一般而言,程序语言里面的2d图形都是用矩形框起来的,用矩形作为他的边界。比如直线它的区域就是以这条直线为对角线的矩形;圆区域就是以这个圆为内切圆的矩形区域。
所以通过他们的矩形区域来获得他们的区域。
java.awt.Graphics中有getClipBounds() 的函数,返回类型是 Rectang类型,它标明改图形的矩形区域。
你要获得直线两点的坐标的话,就是区域矩形的对角两点。要获得圆心的话,就是区域矩形的中心(这时候矩形是正方形了)。其他大抵如此。。。
如何用java把数据用坐标实时显示出来代码越全越好
Java输出到屏幕最简单的方法是 Println (...);
坐标一般是你自己写的变量 int x ;int y;
所以你只要写
Println ("x="+x+", y="+y);即可输出
另外也可以用Label类、JLable类的实例来显示到窗口的标签里
Label xy = new Lable();
xy.lable = "x="+x+", y="+y;
Jlabel用法同Lable一样,只是他们继承的类不同而已
java.让用户输入x坐标,和y坐标当用户输入完x坐标(比如200),敲enter,
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JTextField;
import javax.swing.SwingConstants;
public class SetLocationFrame extends JFrame{
private JTextField t1,t2;
JLabel l;
int x,y;
public static void main(Stringargs){
new SetLocationFrame();
}
public SetLocationFrame(){
super("Where should I be?");
this.setLayout(null);
this.setDefaultCloseOperation(3);
init();
this.setVisible(true);
}
private void init() {
setBounds(100, 100, 300, 200);
x = this.getLocation().x;
y = this.getLocation().y;
JLabel lblNewLabel = new JLabel("Enter new X here");
lblNewLabel.setBounds(44, 10, 136, 20);
add(lblNewLabel);
JLabel lblEnterNewY = new JLabel("Enter new Y here");
lblEnterNewY.setBounds(44, 40, 136, 20);
add(lblEnterNewY);
t1 = new JTextField(x+"");
t1.setBounds(190, 10, 66, 21);
add(t1);
t1.setColumns(10);
t1.addActionListener(new ActionListener(){
@Override
public void actionPerformed(ActionEvent e) {
x = Integer.parseInt(t1.getText());
l.setText("x is "+ x +" and y is "+y);
t2.requestFocus();
}
});
t2 = new JTextField(y+"");
t2.setColumns(10);
t2.setBounds(190, 40, 66, 21);
add(t2);
t2.addActionListener(new ActionListener(){
@Override
public void actionPerformed(ActionEvent e) {
y = Integer.parseInt(t2.getText());
l.setText("x is "+ x +" and y is "+y);
}
});
JButton b = new JButton("Move The Window");
b.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
setLocation(x,y);
System.out.println(x +":" + y);
}
});
b.setBounds(54, 70, 197, 37);
add(b);
JLabel lblComponentOfCurrent = new JLabel("Component of Current Location:");
lblComponentOfCurrent.setBounds(44, 114, 197, 20);
add(lblComponentOfCurrent);
l = new JLabel("x is "+ x +" and y is "+y);
l.setHorizontalAlignment(SwingConstants.CENTER);
l.setBounds(64, 144, 156, 20);
add(l);
}
}
求大神Java坐标编程
public class Point {
private int x,y,z;
public int getX() {
return x;
}
public void setX(int x) {
this.x = x;
}
public int getY() {
return y;
}
public void setY(int y) {
this.y = y;
}
public int getZ() {
return z;
}
public void setZ(int z) {
this.z = z;
}
public double distance(Point orig){
int dx=this.x-orig.getX();
int dy=this.y-orig.getY();
int dz=this.z-orig.getZ();
return Math.sqrt(dx*dx+dy*dy+dz*dz);
}
}
java窗体坐标获取
给你一个简单的例子吧,自己刚写的,看看是不是你想要的毕培吧。
import java.awt.event.*;
import java.awt.*;
import javax.swing.JFrame;
public class GetSize_Test extends JFrame implements ActionListener{
static GetSize_Test frame = null;
/**
* @param args
*/
public GetSize_Test(){
addWindowListener(new WindowDestroyer());
this.getContentPane();
setTitle("Welcome!");
setBounds(300,200,400,300);
setVisible(true);
}
private void getFrameSize(){
Rectangle test = frame.getBounds();
System.out.println("窗体的坐标:("+test.x+","+test.y+")");
System.out.println("窗念燃体的大小(高,宽):手高唯("+test.height+","+test.width+")");
}
public class WindowDestroyer extends WindowAdapter {
public void windowClosing(WindowEvent e) {
System.exit(0);
}
}
public void actionPerformed(ActionEvent e) {}
public static void main(String args) {
frame = new GetSize_Test();
frame.getFrameSize();
}
}
既然获取了A的坐标那么直接B.setBounds(test.x,test.x,int i,int j);就行了啊。
求高手 怎么用JAVA语言写 随机取N点坐标 筛选出距离小于500米的
//初始化路径,都为最大值。
intpath;
for(inti=1;i《n+1;i++){
for(intj=1;j《n+1;j++)
path=500;
}
//这里需要输入path的具体内容,如果有重复数据漏差的话,需要更新路径为最小值。
intminLen;
//visit初始为0,防止回溯
intvisit;
//初始化1到其返空皮他点的距离。
for(inti=1;i《n+1;i++){
minLen;
}
voidDijkstra(){
minLen=0;
visit=1;
intminj=1;
for(inti=1;i《n+1;i++){
intmin=Integer.MAX_VALUE;
for(intj=1;j《n+1;j++){
if(visit《min){
min=minLen;
minj=j;
}
}
visit=1;
for(intj=1;j《n+1;j++){
if(visit!=
Integer.MAX_VALUE&&亏仔minLen)){
minLen;
}
}
}
}
java程序的坐标怎么写
Point getLocation()
获得组件的位置,形式是指定组件左上角的一个点。
其返回值是一个Point对象,包含着X坐标和Y坐标
接下来可以使用Point的成员
double getX() 以双精度型返回点的 X 坐标。
double getY() 以双精度型返回点的 Y 坐标。
例如:有组件JButton:btnTest
Point p = btnTest.getLocation();
double x = p.getX();
double y = p.getY();
这样可以得到按钮的x坐标和y坐标

更多文章:
export用法搭配(export后用介词in还是from)
2026年2月27日 23:30
i wrote python(python零基础自学的基本知识)
2025年10月1日 20:00
java框架实现日志管理的原理步骤(java中如何使用log4j将记录的操作日志信息)
2025年9月7日 10:15
int是什么意思啊音响上(汽车CD机上的英文字母各是什么意思)
2026年9月13日 08:45
completed是什么意思中文(level completed什么意思)
2026年1月3日 20:15
python读取文件相对路径(python中的绝对路径和相对路径均如何理解呢)
2025年10月1日 15:45
郑州cms建站系统(国内的JAVA版CMS系统哪些比较给力)
2025年9月10日 06:45
正则表达式过滤1234(如何用正则表达式过滤除数字以外的其他字符)
2026年2月16日 12:30
用python画简单的花(pythoncircle函数画花瓣怎么计算角度)
2026年9月25日 13:15
phpstorm如何配置服务器(phpstorm 怎么设置http代理服务器)
2026年1月27日 20:00
sql ser数据库安装路径(我的SQL server 2000安装在c盘下,那么以后保存的数据库都是默认存在c盘下了,)
2025年11月2日 04:45








![grep使用正则表达式(正则表达式:grep “^[[:space :]]*$” 表示什么)](/static/images/nopic/30.jpg)



