该程序提供了一个简单便捷的方式,在屏幕上测量距离,包括游戏地图分析在内。它允许用户准确确定屏幕上两点之间的距离,帮助游戏过程中的战略规划、资源管理和决策制定。
特点:
- 简单易用的界面:直观的控制使测量距离变得轻松。
- 精准测量:提供屏幕距离的精确测量。
注意:确保应用程序窗口覆盖屏幕上感兴趣的区域,以进行准确的测量。对于游戏地图,请调整缩放级别或分辨率,以匹配游戏内的设置,从而进行精确测量。
示例用法:
- 在策略游戏中,测量单位或游戏地图上的战略点之间的距离,以规划移动并预测敌人的行动。
- 在角色扮演游戏中,测量位置之间的距离,以估计旅行时间并优化探索路线。
- 在模拟游戏中,测量对象或地标之间的距离,以计算游戏环境内的尺寸和空间关系。
import javax.swing.*;
import java.awt.*;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
public class DistanceCalculator extends JFrame {
private Point point1;
private Point point2;
private Point initialClick;
public DistanceCalculator() {
setTitle("小影测距计算器");
setSize(500, 500);
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
setLocationRelativeTo(null);
setAlwaysOnTop(true); // 设置窗口置顶
// setExtendedState(JFrame.MAXIMIZED_BOTH);
JPanel panel = new JPanel() {
@Override
protected void paintComponent(Graphics g) {
g.setColor(Color.RED);
Font boldLargeFont = new Font("Serif", Font.BOLD, 30);
g.setFont(boldLargeFont);
g.drawString("小影测距辅助器",(getWidth()/2)-120,50 );
Font f2 = new Font("Serif", Font.BOLD, 15);
g.setFont(f2);
super.paintComponent(g);
if (point1 != null) {
g.setColor(Color.RED);
g.fillOval(point1.x - 5, point1.y - 5, 10, 10);
}
if (point2 != null) {
g.setColor(Color.BLUE);
g.fillOval(point2.x - 5, point2.y - 5, 10, 10);
}
if (point1 != null && point2 != null) {
g.setColor(Color.BLACK);
g.drawLine(point1.x, point1.y, point2.x, point2.y);
double distance = point1.distance(point2);
// 100米等于100像素
double mi=100;// 100米
double px = 100;// 像素
double metersForTargetPixels = mi / px;// 计算1px定于多少米
double resultMi = distance * metersForTargetPixels;// 米
g.drawString("距离:" + distance + " 像素;"+resultMi+"米", 10, getHeight() - 10);
}
}
};
panel.setOpaque(false); // Make the panel transparent
setUndecorated(true); // Remove window decorations
setBackground(new Color(100, 100, 100, 100)); // Set the JFrame background color to be transparent
panel.addMouseListener(new MouseAdapter() {
@Override
public void mouseClicked(MouseEvent e) {
if (point1 == null) {
point1 = e.getPoint();
} else if (point2 == null) {
point2 = e.getPoint();
} else {
// Reset points if two points are already recorded
point1 = e.getPoint();
point2 = null;
}
panel.repaint();
}
@Override
public void mousePressed(MouseEvent e) {
initialClick = e.getPoint();
}
});
panel.addMouseMotionListener(new MouseAdapter() {
@Override
public void mouseDragged(MouseEvent e) {
// get location of Window
int thisX = getLocation().x;
int thisY = getLocation().y;
// Determine how much the mouse moved since the initial click
int xMoved = (thisX + e.getX()) - (thisX + initialClick.x);
int yMoved = (thisY + e.getY()) - (thisY + initialClick.y);
// Move window to this position
int X = thisX + xMoved;
int Y = thisY + yMoved;
setLocation(X, Y);
}
});
add(panel);
setVisible(true);
}
@Override
public void paint(Graphics g) {
super.paint(g);
if (point1 != null && point2 != null) {
g.setColor(Color.BLACK);
g.drawLine(point1.x, point1.y, point2.x, point2.y);
}
}
public static void main(String[] args) {
SwingUtilities.invokeLater(DistanceCalculator::new);
}
}