import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import javax.swing.event.*;
import java.io.*;
//Write By Fubin My MSN:yonghe169@163.com
public class MagnifierWindow extends JFrame{
private Container container = getContentPane();
private JPopupMenu popupMenu = new JPopupMenu();
private JMenuItem menuRefresh = new JMenuItem("Refresh");
private JMenuItem menuHide = new JMenuItem("Hide");
private JMenu menuSize = new JMenu("Size");
private JMenuItem menu100Pixels = new JMenuItem("100 Pixels");
private JMenuItem menu200Pixels = new JMenuItem("200 Pixels");
private JMenu menuHelp = new JMenu("Help");
private JMenuItem menuHow = new JMenuItem("How to use");
private JMenuItem menuSite = new JMenuItem("Visit web site");
private JMenuItem menuAbout = new JMenuItem("About");
private JMenuItem menuExit = new JMenuItem("Exit");
private TimeUpdate timeUpdate = new TimeUpdate();
private int timeUpdateDelay = 10;
private int onScreenMoveDidectionUp = 1;
private int onScreenMoveDidectionDown = -1;
private int onScreenMoveDidectionX = onScreenMoveDidectionUp;
private int onScreenMoveDidectionY = onScreenMoveDidectionUp;
private int setCoordinateX;
private int setCoordinateY;
private int absoluteCoordinateX;
private int absoluteCoordinateY;
private int relativeCoordinateXWhenMousePressed;
private int relativeCoordinateYWhenMousePressed;
private boolean mousePressedNow;
private boolean magnifierStopped;
private ConfigData configData = new ConfigData();
private int screenWidth = Toolkit.getDefaultToolkit().getScreenSize().width;
private int screenHeight = Toolkit.getDefaultToolkit().getScreenSize().height;
private int magnifierSize = 100;
private MagnifierPanel magnifierPanel = new MagnifierPanel(magnifierSize);
private Image magnifierIcon;
private int updateScreenDelay = 500;
public MagnifierWindow(String windowTitle){
super(windowTitle);
magnifierIcon = new ImageIcon(MagnifierIcon.magnifierIcon).getImage();
setIconImage(magnifierIcon);
setUndecorated(true);
container.add(magnifierPanel);
addMouseListener(new MouseFunctions());
addMouseMotionListener(new MouseMotionFunctions());
timeUpdate.start();
menuRefresh.addActionListener(
new ActionListener(){
public void actionPerformed(ActionEvent e){
updateScreen();
}
}
);
menuHide.addActionListener(
new ActionListener(){
public void actionPerformed(ActionEvent e){
setState(JFrame.ICONIFIED);
}
}
);
menu100Pixels.addActionListener(
new ActionListener(){
public void actionPerformed(ActionEvent e){
magnifierSize = 100;
updateSize(magnifierSize);
}
}
);
menu200Pixels.addActionListener(
new ActionListener(){
public void actionPerformed(ActionEvent e){
magnifierSize = 200;
updateSize(magnifierSize);
}
}
);
menuHow.addActionListener(
new ActionListener(){
public void actionPerformed(ActionEvent e){
JOptionPane jOptionPane = new JOptionPane();
JTextArea jTextArea = new JTextArea();
jTextArea.setText("1.Single click on left mouse button stops magnifier movement.\n" +
"2.Double click on left mouse button starts magnifier movement.\n" +
"3.Single click on right mouse button stops magnifier movement and shows menu.\n" +
"4.Move magnifier by click on left mouse button on it and drag to desired place.\n" +
"5.Refresh option in the menu is needed to update last screen status.\n" +
"6.Hide option in the menu is needed to minimize magnifier");
jOptionPane.showMessageDialog(null,
jTextArea,
"How to use magnifier",
JOptionPane.INFORMATION_MESSAGE);
}
}
);
menuSite.addActionListener(
new ActionListener(){
public void actionPerformed(ActionEvent e){
JOptionPane jOptionPane = new JOptionPane();
JTextField jTextField = new JTextField();
jTextField.setText("http://softcollection.sytes.net/javaprog");
jOptionPane.showMessageDialog(null,
jTextField,
"Please visit web site!",
JOptionPane.INFORMATION_MESSAGE);
}
}
);
menuAbout.addActionListener(
new ActionListener(){
public void actionPerformed(ActionEvent e){
JOptionPane.showMessageDialog(null,"Magnifier v1.14","About",JOptionPane.INFORMATION_MESSAGE);
}
}
);
menuExit.addActionListener(
new ActionListener(){
public void actionPerformed(ActionEvent e){
System.exit(0);
}
}
);
popupMenu.add(menuRefresh);
popupMenu.add(menuHide);
popupMenu.add(menuSize);
menuSize.add(menu100Pixels);
menuSize.add(menu200Pixels);
popupMenu.add(menuHelp);
menuHelp.add(menuHow);
menuHelp.add(menuSite);
menuHelp.add(menuAbout);
popupMenu.add(menuExit);
updateSize(magnifierSize);
openFile();
show();
}
public void updateSize(int magnifierSize){
magnifierPanel.setMagnifierSize(magnifierSize);
setSize(magnifierSize,magnifierSize);
validate();
}
public void updateScreen(){
hide();
try{Thread.sleep(updateScreenDelay);} catch(InterruptedException e){}
magnifierPanel.getScreen();
show();
}
private class TimeUpdate extends Thread{
public void run(){
while(true){
if (magnifierStopped == false){
setCoordinateX += onScreenMoveDidectionX;
setCoordinateY += onScreenMoveDidectionY;
if (setCoordinateX < 0) onScreenMoveDidectionX = onScreenMoveDidectionUp;
if (setCoordinateY < 0) onScreenMoveDidectionY = onScreenMoveDidectionUp;
if (setCoordinateX > (screenWidth-magnifierSize)) onScreenMoveDidectionX = onScreenMoveDidectionDown;
if (setCoordinateY > (screenHeight-magnifierSize)) onScreenMoveDidectionY = onScreenMoveDidectionDown;
magnifierPanel.setMagnifierLocation(setCoordinateX,setCoordinateY);
setLocation(setCoordinateX,setCoordinateY);
}
try{Thread.sleep(timeUpdateDelay);} catch(InterruptedException e){}
}
}
}
private class MouseFunctions extends MouseAdapter{
public void mousePressed(MouseEvent e){
if (e.getClickCount()==1){
mousePressedNow = true;
relativeCoordinateXWhenMousePressed=e.getX();
relativeCoordinateYWhenMousePressed=e.getY();
magnifierStopped = true;
}
if (e.getButton()==MouseEvent.BUTTON1&&e.getClickCount()==2){
magnifierStopped = false;
}
}
public void mouseReleased(MouseEvent e){
mousePressedNow = false;
saveFile();
if (e.isPopupTrigger()){
popupMenu.show(e.getComponent(),e.getX(),e.getY());
}
}
}
private class MouseMotionFunctions extends MouseMotionAdapter{
public void mouseDragged(MouseEvent e){
if (mousePressedNow == true){
absoluteCoordinateX = MagnifierWindow.this.getLocationOnScreen().x + e.getX();
absoluteCoordinateY = MagnifierWindow.this.getLocationOnScreen().y + e.getY();
setCoordinateX = absoluteCoordinateX-relativeCoordinateXWhenMousePressed;
setCoordinateY = absoluteCoordinateY-relativeCoordinateYWhenMousePressed;
magnifierPanel.setMagnifierLocation(setCoordinateX,setCoordinateY);
setLocation(setCoordinateX,setCoordinateY);
}
}
}
public void saveFile(){
ObjectOutputStrea
没有合适的资源?快使用搜索试试~ 我知道了~
基于Java的实例源码-实现的放大镜效果附有源文件.zip
共23个文件
class:16个
java:4个
project:1个
5星 · 超过95%的资源 1 下载量 77 浏览量
2023-07-08
11:36:43
上传
评论 1
收藏 21KB ZIP 举报
温馨提示
基于Java的实例源码-实现的放大镜效果附有源文件.zip
资源推荐
资源详情
资源评论
收起资源包目录
基于Java的实例源码-实现的放大镜效果附有源文件.zip (23个子文件)
codefans.net
Magnifier
MagnifierPanel.java 3KB
MagnifierWindow.java 9KB
MagnifierWindow$8.class 647B
MagnifierWindow$2.class 654B
.classpath 226B
MagnifierPanel.class 3KB
MagnifierIcon.class 812B
MagnifierWindow$1.class 650B
MagnifierWindow$5.class 1KB
MagnifierWindow$TimeUpdate.class 1KB
Magnifier.cfg 113B
ConfigData.class 386B
Magnifier.java 253B
MagnifierWindow$7.class 760B
MagnifierWindow$MouseMotionFunctions.class 1KB
MagnifierIcon.java 432B
MagnifierWindow$3.class 766B
MagnifierWindow$4.class 767B
Magnifier.class 489B
Magnifier
.project 385B
MagnifierWindow$6.class 1KB
MagnifierWindow$MouseFunctions.class 1KB
MagnifierWindow.class 8KB
共 23 条
- 1
资源评论
- 易小侠2023-07-18很不错的资源,给我很大帮助 #完美解决问题 #运行顺畅 #内容详尽 #全网独家 #注释完整
毕业课程设计
- 粉丝: 2246
- 资源: 1634
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
最新资源
- 基于python的高性能爬虫程序,使用了多线程+缓存+xpath实现的,这里以彼-岸图库为例,实现,仅用于学习交流
- 中分辨率成像光谱仪(MODIS)烧毁面积产品信息MODIS-C6-BA-User-Guide-1.2.pdf
- Screenshot_20240427_172613_com.huawei.browser.jpg
- 关于学习Python的相关资源网站链接及相关介绍.docx
- (HAL库)基于STM32F103C8T6的温控PID系统[Dht11、ESP8266、无线透传、L298N……]
- VoLTE高丢包优化指导书.xlsx
- Rust资源文件.zip
- 前后端分离实践:使用 React 和 Express 搭建完整登录注册流程
- gradle-publish-to-MavenLocal.zip
- 10份网络优化创新案例.zip
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功