package org.example;
/**
* @author Administrator
* @version 1.0
* @description:
* @date 2024/3/12 12:47
*/
// MainFrame.java
import java.awt.*;
import java.awt.event.KeyEvent;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;
import javax.swing.*;
import com.sun.jna.platform.win32.Advapi32Util;
import com.sun.jna.platform.win32.WinError;
import com.sun.jna.platform.win32.WinReg;
import org.cef.CefApp;
import org.cef.CefClient;
import org.cef.browser.CefBrowser;
import org.cef.browser.CefMessageRouter;
import org.cef.browser.CefRendering;
import com.jetbrains.cef.JCefAppConfig;
public class MainFrame extends JFrame {
private static final long serialVersionUID = 2541887783679247552L;
private static volatile MainFrame instance;
//private String url = "http://192.168.87.74/";
private String url = System.getProperty("user.dir") + "/dist/index.html";
private CefApp app = null;
private CefClient client = null;
//private CefBrowser browser = null;
public static CefBrowser browser = null;
public MainFrame() {
var args = JCefAppConfig.getInstance().getAppArgs();
String[] args1 = new String[]{
"--disable-web-security"//关闭同源策略,允许跨域
, "--disable-site-isolation-trials" //关闭站点隔离策略,允许跨域
};
var settings = JCefAppConfig.getInstance().getCefSettings();
settings.cache_path = System.getProperty("user.dir") + "/context";
// 获取CefApp实例
CefApp.startup(args1);
app = CefApp.getInstance(args1, settings);
// 创建客户端实例
client = app.createClient();
// 创建浏览器实例
// 在线资源
//browser = client.createBrowser("https://www.baidu.com", CefRendering.DEFAULT, true);
// 本地资源
browser = client.createBrowser(url, CefRendering.DEFAULT, true);
this.getContentPane().setLayout(new BorderLayout(0, 0));
this.getContentPane().add(browser.getUIComponent(), BorderLayout.CENTER);
this.setTitle("测试-jcef");
this.setSize(new Dimension(1280, 720));
this.setMinimumSize(new Dimension(1150, 650));
this.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
this.setLocation((Toolkit.getDefaultToolkit().getScreenSize().width - this.getWidth()) / 2,
(Toolkit.getDefaultToolkit().getScreenSize().height - this.getHeight()) / 2);
this.setVisible(true);
this.setResizable(true);
this.addWindowListener(new WindowAdapter() {
@Override
public void windowClosing(WindowEvent e) {
app.dispose();
System.exit(0);
}
});
CefMessageRouter.CefMessageRouterConfig cmrc = new CefMessageRouter.CefMessageRouterConfig("java", "javaCancel");
//创建查询路由
CefMessageRouter cmr = CefMessageRouter.create(cmrc);
cmr.addHandler(new JCEFMessageRouterHandler(), true);
client.addMessageRouter(cmr);
client.addRequestHandler(new MyRequestHandler());
client.addKeyboardHandler(new KeyboardHandler(this));
}
public static MainFrame getIstance() throws AWTException {
if (instance == null) {
synchronized (MainFrame.class) {
if (instance == null) {
instance = new MainFrame();
String strUrl = System.getProperty("user.dir") + "\\dist\\logo.png";
// 创建系统托盘图标
SystemTray systemTray = SystemTray.getSystemTray();
//URL iconUrl = new URL(strUrl);
//Image icon = Toolkit.getDefaultToolkit().getImage(strUrl);
//Image icon = Toolkit.getDefaultToolkit().createImage(strUrl);
ImageIcon imageIcon = new ImageIcon(strUrl);
Image icon = imageIcon.getImage();
PopupMenu popupMenu = new PopupMenu();
TrayIcon trayIcon = new TrayIcon(icon, "Swing App", popupMenu);
trayIcon.setImageAutoSize(true);
systemTray.add(trayIcon);
Font font = new Font("宋体", Font.BOLD, 12);
MenuItem menuItemRestore = new MenuItem("显示窗口", new MenuShortcut(KeyEvent.VK_M));//显示窗口 Restore
menuItemRestore.setFont(font);
MenuItem menuItemAotoStart = new MenuItem("开机自动启动");
MenuItem menuItemExit = new MenuItem("Exit");//退出
//显示窗口
menuItemRestore.addActionListener(e -> {
instance.setVisible(true);//显示窗口
instance.setExtendedState(JFrame.NORMAL);//恢复正常状态
});
//开机自动启动
menuItemAotoStart.addActionListener(e -> {
try {
/*需要以管理员身份运行*/
// SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Run
/*String keyPath = "SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Run";
String keyValue = Advapi32Util.registryGetStringValue(WinReg.HKEY_LOCAL_MACHINE, keyPath, "Sysdiag");
String exePath = "D:\\Program Files\\TszSoftWares\\TSZNewXTClientForRevitSAAS\\DLL\\TSZ.XTRevitClient.exe";
Advapi32Util.registrySetStringValue(WinReg.HKEY_LOCAL_MACHINE, keyPath, "tstcApp", exePath);*/
String regKey = "HKEY_LOCAL_MACHINE\\SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Run";
String myApp = "myApp";
String exeInstallPath = "X:\\XXX\\XX.exe";
Runtime.getRuntime().exec("reg add " + regKey + " /v " + myApp + " /t reg_sz /d " + exeInstallPath);
} catch (Exception ex) {
System.out.println("Exception is: " + ex);
}
});
//退出
menuItemExit.addActionListener(e -> {
systemTray.remove(trayIcon);
System.exit(0);
});
popupMenu.add(menuItemRestore);
popupMenu.add(menuItemAotoStart);
popupMenu.add(menuItemExit);
//添加监听事件最小化到托盘
instance.addWindowListener(new WindowAdapter() {
@Override
public void windowIconified(WindowEvent e) {
instance.setVisible(false);//隐藏窗口
}
});
}
}
}
return instance;
}
}
没有合适的资源?快使用搜索试试~ 我知道了~
资源推荐
资源详情
资源评论
收起资源包目录
java jcef Java Chromium嵌入式框架, 基于Chromium的 cef框架 (258个子文件)
013511716daac8bc_0 208B
0817bb028c77d672_0 191B
0b32e80e544ecca3_0 218B
0d50b38401292cf4_0 210B
0d8b5770104f9023_0 206B
0d93df14770d1c46_0 228B
0e1a4f95436f4e58_0 235B
1103577e988f30b1_0 205B
16d9cc297119daa1_0 195B
19e719a7e0ff2961_0 201B
1b29fb66eba5ebf9_0 190B
1b646b808f3d1196_0 217B
259457cb8dcf49fb_0 222B
2703519ee7d0c55c_0 224B
28704e97bd88b7de_0 216B
294add3f3964ed6a_0 280B
2a35bca822f8182b_0 204B
378c675d3206b3e0_0 281B
3a88be0890ecbb4a_0 207B
3b12ad884f64978a_0 195B
3da69dd84fde093f_0 199B
3f254a8aee2c6dec_0 218B
3f60e5a9d04abd54_0 213B
3ffb9c4b03dcd86d_0 228B
47033ecfe56a3ba8_0 197B
473daa2149099b03_0 242B
4beb04079e2f1529_0 237B
4d30b47a560832be_0 219B
4df555ca8bc666c5_0 220B
50c2056624b890b0_0 225B
515c41df626f9767_0 219B
52369da398fe53b3_0 228B
550f9bc635b5184d_0 198B
560959b9136bca2d_0 212B
5729788416976915_0 201B
59ea6d8cc3165ae9_0 220B
5a7c6be27fbeeaa4_0 209B
5ff7e62b66423469_0 195B
60995d11d668e53d_0 197B
60b49b74e06d260d_0 29KB
60e42eb57419c98c_0 213B
63c84ae6f6b6ee0c_0 213B
64bd563fbc60973f_0 208B
66c94f3004b850fe_0 200B
6b39fc731bb3d9d8_0 218B
6da13987389b8e95_0 167B
6db03a22681fcf61_0 226B
6e4c1d74604db202_0 221B
7003aa715cc8d8a6_0 202B
70fb3f11f7e4fb52_0 232B
720268bc3797dddf_0 232B
7244fdf0b7bee852_0 234B
72ad44040ec75b12_0 213B
76e8398d2bba4483_0 237B
775a009cc6b70c53_0 244B
77b940429917ab6f_0 198B
781391b13681e883_0 195B
786202ad0d1e3314_0 234B
79002624c3b5c8f9_0 253B
7e5d4a2f5d2f4706_0 227B
81a39831e1a4fdf3_0 188B
828ec1b611a0b204_0 232B
8451190c5f88c9c7_0 190B
86798ed83f1b9625_0 195B
887db53558e11d7e_0 218B
8ad295c4e9f91d7b_0 218B
8f41ccb3ab517271_0 205B
8fb78ab71d43c3f9_0 200B
8fe6e35f682d1502_0 212B
95a6908a7cab3016_0 226B
9a1b0a38ce552e8a_0 191B
9a6a84d696d92b8e_0 198B
9e77b67a0c1e19e2_0 199B
9f0cfdc937785568_0 220B
a3f625116a0d7258_0 217B
a42af9f43d9affc0_0 193B
a8af058f712219ae_0 209B
aac366ef9ee95980_0 226B
ac1f5c806885ffaa_0 208B
acaef701c2ae483c_0 197B
b16fe1a9297883f9_0 241B
b17dc16496acb7ea_0 201B
b1b272a6b7195d10_0 189B
b34c11003e82c951_0 203B
b54cf5c15c534b15_0 233B
b9e42d5c439e98ad_0 1KB
c22b59db32c7c244_0 221B
c2d8471c19e57fa4_0 223B
c9a1fbb3633aee0a_0 205B
cf5e1fce34e19853_0 213B
MainFrame.class 8KB
MyRequestHandler.class 3KB
JCEFMessageRouterHandler.class 2KB
UDPServer.class 2KB
DevToolsDialog.class 2KB
Main.class 2KB
KeyboardHandler.class 2KB
RegexEx.class 901B
DevToolsDialog$1.class 811B
MainFrame$1.class 789B
共 258 条
- 1
- 2
- 3
资源评论
qq_35137757
- 粉丝: 3
- 资源: 17
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
最新资源
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功