开源 企业版 高校版 私有云 模力方舟 AI 队友
代码拉取完成,页面将自动刷新
捐赠
捐赠前请先登录
扫描微信二维码支付
取消
支付完成
支付提示
将跳转至支付宝完成支付
确定
取消
1 Star 0 Fork 0

DXFB/java-cef

加入 Gitee
与超过 1400万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
已有帐号? 立即登录
文件
master
分支 (1)
master
master
分支 (1)
master
克隆/下载
克隆/下载
提示
下载代码请复制以下命令到终端执行
为确保你提交的代码身份被 Gitee 正确识别,请执行以下命令完成配置
初次使用 SSH 协议进行代码克隆、推送等操作时,需按下述提示完成 SSH 配置
1 生成 RSA 密钥
2 获取 RSA 公钥内容,并配置到 SSH公钥
在 Gitee 上使用 SVN,请访问 使用指南
使用 HTTPS 协议时,命令行会出现如下账号密码验证步骤。基于安全考虑,Gitee 建议 配置并使用私人令牌 替代登录密码进行克隆、推送等操作
Username for 'https://gitee.com': userName
Password for 'https://userName@gitee.com': # 私人令牌
master
分支 (1)
master
java-cef
/
java
/
tests
/
simple
/
MainFrame.java
java-cef
/
java
/
tests
/
simple
/
MainFrame.java
MainFrame.java 10.08 KB
一键复制 编辑 原始数据 按行查看 历史
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229
// Copyright (c) 2014 The Chromium Embedded Framework Authors. All rights
// reserved. Use of this source code is governed by a BSD-style license that
// can be found in the LICENSE file.
package tests.simple;
import org.cef.CefApp;
import org.cef.CefApp.CefAppState;
import org.cef.CefClient;
import org.cef.CefSettings;
import org.cef.OS;
import org.cef.browser.CefBrowser;
import org.cef.browser.CefFrame;
import org.cef.handler.CefAppHandlerAdapter;
import org.cef.handler.CefDisplayHandlerAdapter;
import org.cef.handler.CefFocusHandlerAdapter;
import java.awt.BorderLayout;
import java.awt.Component;
import java.awt.GraphicsConfiguration;
import java.awt.KeyboardFocusManager;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.FocusAdapter;
import java.awt.event.FocusEvent;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;
import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.JTextField;
import javax.swing.SwingUtilities;
/**
* This is a simple example application using JCEF.
* It displays a JFrame with a JTextField at its top and a CefBrowser in its
* center. The JTextField is used to enter and assign an URL to the browser UI.
* No additional handlers or callbacks are used in this example.
*
* The number of used JCEF classes is reduced (nearly) to its minimum and should
* assist you to get familiar with JCEF.
*
* For a more feature complete example have also a look onto the example code
* within the package "tests.detailed".
*/
public class MainFrame extends JFrame {
private static final long serialVersionUID = -5570653778104813836L;
private final JTextField address_;
private final CefApp cefApp_;
private final CefClient client_;
private final CefBrowser browser_;
private final Component browserUI_;
private boolean browserFocus_ = true;
private JFrame fullscreenFrame_;
/**
* To display a simple browser window, it suffices completely to create an
* instance of the class CefBrowser and to assign its UI component to your
* application (e.g. to your content pane).
* But to be more verbose, this CTOR keeps an instance of each object on the
* way to the browser UI.
*/
private MainFrame(String startURL, boolean useOSR, boolean isTransparent) {
// (1) The entry point to JCEF is always the class CefApp. There is only one
// instance per application and therefore you have to call the method
// "getInstance()" instead of a CTOR.
//
// CefApp is responsible for the global CEF context. It loads all
// required native libraries, initializes CEF accordingly, starts a
// background task to handle CEF's message loop and takes care of
// shutting down CEF after disposing it.
CefApp.addAppHandler(new CefAppHandlerAdapter(null) {
@Override
public void stateHasChanged(org.cef.CefApp.CefAppState state) {
// Shutdown the app if the native CEF part is terminated
if (state == CefAppState.TERMINATED) System.exit(0);
}
});
CefSettings settings = new CefSettings();
settings.windowless_rendering_enabled = useOSR;
cefApp_ = CefApp.getInstance(settings);
// (2) JCEF can handle one to many browser instances simultaneous. These
// browser instances are logically grouped together by an instance of
// the class CefClient. In your application you can create one to many
// instances of CefClient with one to many CefBrowser instances per
// client. To get an instance of CefClient you have to use the method
// "createClient()" of your CefApp instance. Calling an CTOR of
// CefClient is not supported.
//
// CefClient is a connector to all possible events which come from the
// CefBrowser instances. Those events could be simple things like the
// change of the browser title or more complex ones like context menu
// events. By assigning handlers to CefClient you can control the
// behavior of the browser. See tests.detailed.MainFrame for an example
// of how to use these handlers.
client_ = cefApp_.createClient();
// (3) One CefBrowser instance is responsible to control what you'll see on
// the UI component of the instance. It can be displayed off-screen
// rendered or windowed rendered. To get an instance of CefBrowser you
// have to call the method "createBrowser()" of your CefClient
// instances.
//
// CefBrowser has methods like "goBack()", "goForward()", "loadURL()",
// and many more which are used to control the behavior of the displayed
// content. The UI is held within a UI-Compontent which can be accessed
// by calling the method "getUIComponent()" on the instance of CefBrowser.
// The UI component is inherited from a java.awt.Component and therefore
// it can be embedded into any AWT UI.
browser_ = client_.createBrowser(startURL, useOSR, isTransparent);
browserUI_ = browser_.getUIComponent();
// (4) For this minimal browser, we need only a text field to enter an URL
// we want to navigate to and a CefBrowser window to display the content
// of the URL. To respond to the input of the user, we're registering an
// anonymous ActionListener. This listener is performed each time the
// user presses the "ENTER" key within the address field.
// If this happens, the entered value is passed to the CefBrowser
// instance to be loaded as URL.
address_ = new JTextField(startURL, 100);
address_.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
browser_.loadURL(address_.getText());
}
});
// Update the address field when the browser URL changes.
client_.addDisplayHandler(new CefDisplayHandlerAdapter() {
@Override
public void onAddressChange(CefBrowser browser, CefFrame frame, String url) {
address_.setText(url);
}
@Override
public void onFullscreenModeChange(CefBrowser browser, boolean fullscreen) {
setBrowserFullscreen(fullscreen);
}
});
// Clear focus from the browser when the address field gains focus.
address_.addFocusListener(new FocusAdapter() {
@Override
public void focusGained(FocusEvent e) {
if (!browserFocus_) return;
browserFocus_ = false;
KeyboardFocusManager.getCurrentKeyboardFocusManager().clearGlobalFocusOwner();
address_.requestFocus();
}
});
// Clear focus from the address field when the browser gains focus.
client_.addFocusHandler(new CefFocusHandlerAdapter() {
@Override
public void onGotFocus(CefBrowser browser) {
if (browserFocus_) return;
browserFocus_ = true;
KeyboardFocusManager.getCurrentKeyboardFocusManager().clearGlobalFocusOwner();
browser.setFocus(true);
}
@Override
public void onTakeFocus(CefBrowser browser, boolean next) {
browserFocus_ = false;
}
});
// (5) All UI components are assigned to the default content pane of this
// JFrame and afterwards the frame is made visible to the user.
getContentPane().add(address_, BorderLayout.NORTH);
getContentPane().add(browserUI_, BorderLayout.CENTER);
pack();
setSize(800, 600);
setVisible(true);
// (6) To take care of shutting down CEF accordingly, it's important to call
// the method "dispose()" of the CefApp instance if the Java
// application will be closed. Otherwise you'll get asserts from CEF.
addWindowListener(new WindowAdapter() {
@Override
public void windowClosing(WindowEvent e) {
CefApp.getInstance().dispose();
dispose();
}
});
}
public void setBrowserFullscreen(boolean fullscreen) {
SwingUtilities.invokeLater(new Runnable() {
@Override
public void run() {
if (fullscreen) {
if (fullscreenFrame_ == null) {
fullscreenFrame_ = new JFrame();
fullscreenFrame_.setUndecorated(true);
fullscreenFrame_.setResizable(true);
}
GraphicsConfiguration gc = MainFrame.this.getGraphicsConfiguration();
fullscreenFrame_.setBounds(gc.getBounds());
gc.getDevice().setFullScreenWindow(fullscreenFrame_);
getContentPane().remove(browserUI_);
fullscreenFrame_.add(browserUI_);
fullscreenFrame_.setVisible(true);
fullscreenFrame_.validate();
} else {
fullscreenFrame_.remove(browserUI_);
fullscreenFrame_.setVisible(false);
getContentPane().add(browserUI_, BorderLayout.CENTER);
getContentPane().validate();
}
}
});
}
public static void main(String[] args) {
// Perform startup initialization on platforms that require it.
if (!CefApp.startup(args)) {
System.out.println("Startup initialization failed!");
return;
}
// The simple example application is created as anonymous class and points
// to Google as the very first loaded page. Windowed rendering mode is used by
// default. If you want to test OSR mode set |useOsr| to true and recompile.
boolean useOsr = false;
new MainFrame("http://www.google.com", useOsr, false);
}
}
Loading...
举报
举报成功
我们将于2个工作日内通过站内信反馈结果给你!
请认真填写举报原因,尽可能描述详细。
请选择举报类型
取消
发送
误判申诉

此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。

如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。

取消
提交

简介

暂无描述
取消

发行版

暂无发行版

贡献者

全部

近期动态

不能加载更多了
编辑仓库简介
简介内容
主页
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/DXFB/java-cef.git
git@gitee.com:DXFB/java-cef.git
DXFB
java-cef
java-cef
master
点此查找更多帮助

搜索帮助

评论
仓库举报
回到顶部
登录提示
该操作需登录 Gitee 帐号,请先登录后再操作。
立即登录
没有帐号,去注册

AltStyle によって変換されたページ (->オリジナル) /