java - 将Java中的放大工具限制在应用程序窗口中
问题描述
我们正在尝试修改现有的 Java 程序以适合视障人士,我们正在进行的更改之一是放大功能。
我们有用于放大鼠标下方图像的代码,但它会影响整个屏幕,我们希望将其限制为将运行它的 Java 程序。例如,用户单击辅助功能菜单,然后放大,鼠标下方但仅在应用程序窗口中的所有内容都被放大,而不是整个屏幕上的所有内容。
import java.awt.event.*;
import javax.swing.*;
import java.awt.*;
class magnify extends JFrame {
// object
static magnify m;
// image
Image i;
// default constrcutor
magnify()
{
// create a frame
super("magnify");
// set size of frame
setSize(200, 220);
show();
// function to magnify the image
work();
}
// main function
public static void main(String args[])
{
// object of class
m = new magnify();
}
public void work()
{
try {
// create a robot
Robot r = new Robot();
// while the frame is visible
while (isVisible()) {
// get the position of mouse
Point p = MouseInfo.getPointerInfo().getLocation();
// create a screen capture around the mouse pointer
i = r.createScreenCapture(new Rectangle((int)p.getX() - 30,
(int)p.getY() - 30, 150, 150));
// repaint the conatiner
repaint();
}
// exit the program
System.exit(0);
}
catch (Exception e) {
System.err.println(e.getMessage());
}
}
// paint function
public void paint(Graphics g)
{
// draw the image
g.drawImage(i, 0, 0, 300, 300, this);
}
}
这是我们目前在另一篇在线帖子中使用的代码。应用程序窗口可以调整大小以适应屏幕,就像原生应用程序一样。
谢谢你的帮助!
解决方案
推荐阅读
- rxjs - 从可观察对象中检索间隔值
- geoserver - 寻找 WMS-in-WMS 功能 - 根据规模调用其他 WMS 的 WMS
- c# - c# interop excel:将一维数组写入excel范围
- cordova - 对于混合应用程序中的增强现实平面检测,我有哪些选择?
- google-workspace - GSuite 移动设备 API 未返回管理员中可见的所有设备
- pandas - 如何根据数据框单元格中的外观制作新单元格
- android - 当我替换片段时,滚动不会到顶部
- swiftui - 在 SwiftUI 中切换导航栏上的按钮并更改外观
- string - (str1[i] || str2[i]) 这是什么意思,谁能解释一下
- firebase - 使用 Cloud Firestore 的 firebase 规则