English 中文(简体)
根植于JFrame的浏览器中的 Apple果
原标题:Applet embedded in browser embedded in JFrame

I m new to java. 我想把一个浏览器放在一个联合阵线。 我使用JEditorPane显示超文本,但该页面仍然正确显示。 这页显示,但事情已经消失。 我最大的关切是,网页上的 Java光器没有在我的习惯浏览器上显示。 我可能不正确使用JEditorPane。 我的守则是:

import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import java.net.*;
import java.io.*;

public class Frame1 extends JFrame implements ActionListener
{
    private JEditorPane editorPane;    
    private JTextField addressField;
    private JButton goButton;
    private JLabel label;

    public Frame1() {        
        super("Frame1");
        try {
            UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
        } catch(Exception e) {
            System.out.println("Unablet to set look and feel.");
        }

        setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        label = new JLabel("Enter URL. Must include http://");

        // setup editor pane
        editorPane = new JEditorPane();
        editorPane.setEditable(false);
        URL url = null;
        try {
            url = new URL("http://www.cut-the-knot.org/SimpleGames/FrogsAndToads2d.shtml");
        } catch (MalformedURLException e) {

        }

        if (url != null) {
            try {
                editorPane.setPage(url);
            } catch (IOException e) {
                label.setText("Attempted to read a bad URL: " + url);
            }
        } else {
            label.setText("String specifies an unknown protocol.");
        }

        // put editor pane in a scroll pane
        JScrollPane editorScrollPane = new JScrollPane(editorPane);
        editorScrollPane.setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_ALWAYS);
        editorScrollPane.setPreferredSize(new Dimension(250, 145));
        editorScrollPane.setMinimumSize(new Dimension(10, 10));

        // setup everything in southPanel.
        // southPanel > addressBar + label> addressField + goButton
        addressField = new JTextField(30);
        goButton = new JButton("Go");    
        goButton.addActionListener(this);
        JPanel addressBar = new JPanel();           
        JPanel southPanel = new JPanel(new GridLayout(2, 1));
        addressBar.add(addressField);
        addressBar.add(goButton);
        southPanel.add(addressBar);
        southPanel.add(label);

        // add everything to JFrame
        setLayout(new BorderLayout());        
        add(southPanel, BorderLayout.SOUTH);
        add(editorScrollPane, BorderLayout.CENTER);

        setSize(500, 500);
        setVisible(true);
    }

    public void actionPerformed(ActionEvent e) {
        if (e.getSource() == goButton) {
            URL url = null;
            try {
                url = new URL(addressField.getText());
            } catch (MalformedURLException murle) {

            }
            if (url != null) {
                try {
                    editorPane.setPage(url);
                } catch (IOException ioe) {
                    label.setText("Attempted to read a bad URL: " + url);
                }
            } else {
                label.setText("String specifies an unknown protocol.");
            }
        }
    }

    public static void main(String[] args) {
        new Frame1();
    }
}
问题回答

您应考虑wing木embedded带。 例如:

  1. lobo java browser
  2. DJ Project Native Swing
  3. you could also condsider SWT Browser

这些都是自由的开放源 j。

希望这一帮助。





相关问题
Spring Properties File

Hi have this j2ee web application developed using spring framework. I have a problem with rendering mnessages in nihongo characters from the properties file. I tried converting the file to ascii using ...

Logging a global ID in multiple components

I have a system which contains multiple applications connected together using JMS and Spring Integration. Messages get sent along a chain of applications. [App A] -> [App B] -> [App C] We set a ...

Java Library Size

If I m given two Java Libraries in Jar format, 1 having no bells and whistles, and the other having lots of them that will mostly go unused.... my question is: How will the larger, mostly unused ...

How to get the Array Class for a given Class in Java?

I have a Class variable that holds a certain type and I need to get a variable that holds the corresponding array class. The best I could come up with is this: Class arrayOfFooClass = java.lang....

SQLite , Derby vs file system

I m working on a Java desktop application that reads and writes from/to different files. I think a better solution would be to replace the file system by a SQLite database. How hard is it to migrate ...

热门标签