简体   繁体   English

在桌面应用程序中加载网页

[英]Loading web pages in Desktop application

As i am good in HTML and CSS, I want to make desktop application and mobile apps on one platform so that it will load an HTML page at runtime. 因为我精通HTML和CSS,所以我想在一个平台上制作桌面应用程序和移动应用程序,以便在运行时加载HTML页面。 My second purpose of doing that is, because if i update the webpage, the desktop application automatically gets updated. 我这样做的第二个目的是因为如果我更新网页,则桌面应用程序会自动更新。

I will prefer java because it can be used across multiple platform. 我更喜欢java,因为它可以跨多个平台使用。 I wants to render the page as Google Chrome renders it. 我想以Google Chrome呈现的方式呈现页面。

I want to make all types of application as a desktop application 我想将所有类型的应用程序都作为桌面应用程序

  • Windows 视窗
  • Mac 苹果电脑

I also wants to make all kinds of mobile application 我也想做各种移动应用

  • Android Android的
  • BlackBerry OS 黑莓操作系统
  • iOS 的iOS
  • Symbian OS Symbian作业系统
  • Java Mobile Application Java移动应用程序

Any platform welcome. 任何平台的欢迎。

Thanks in advance. 提前致谢。

Java has classes that can render basic html. Java具有可以呈现基本html的类。

If you want something better you have to use a web browser. 如果您想要更好的东西,则必须使用网络浏览器。 I would probably go with QtJambi and Webkit. 我可能会选择QtJambi和Webkit。

I think you can use a JEditorPane to view a web page. 我认为您可以使用JEditorPane来查看网页。

try this: 尝试这个:

import javax.swing.text.*;
import javax.swing.*;
import java.io.*;
import java.awt.*;

public class OReillyHomePage {

  public static void main(String[] args) {

     JEditorPane jep = new JEditorPane();
     jep.setEditable(false);   

     try {
       jep.setPage("http://www.oreilly.com");
     }
     catch (IOException e) {
       jep.setContentType("text/html");
       jep.setText("<html>Could not load http://www.oreilly.com </html>");
     } 

     JScrollPane scrollPane = new JScrollPane(jep);     
     JFrame f = new JFrame("O'Reilly & Associates");
     // Next line requires Java 1.3
     f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
     f.getContentPane().add(scrollPane);
     f.setSize(512, 342);
     f.show();

  }

}

reference: Using a JEdtiroPane to dispaly a web page 参考: 使用JEdtiroPane分发网页

You didn't mention what ui toolkit you were going to use. 您没有提到要使用什么ui工具包。 The default would be to Swing and if you want to go that route then I would recommend DJ Native Swing . 默认设置为Swing,如果您要走那条路线,那么我建议DJ Native Swing It gives you a true native browser that can be embedded into your application. 它为您提供了可以嵌入到您的应用程序中的真正的本机浏览器。

Another choice is to use SWT which has a browser component build right into the toolkit. 另一种选择是使用SWT,它在工具包中内置了浏览器组件。 Take a look at the Javadoc or this simple tutorial . 看一下Javadoc或这个简单的教程

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM