0

こんにちは私は、ユーザーがトップ10のMMOの画像を見ることができるシンプルなJframeをユーザーに提示しようとしています。私はすでに、画像がユーザーを正しいゲームのWebURLに誘導する単純なhtmlファイルを持っています。

    public static void main(String[] args) throws Exception {
    String url = "exmaple web address etc http//..";
    JEditorPane editor = new JEditorPane(url);
    editor.setEditable(false);
    JScrollPane pane = new JScrollPane(editor);
    JFrame frame = new JFrame("Top 10 MMO's");
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    frame.getContentPane().add(pane);
    frame.setSize(400, 300);
    frame.setVisible(true);

    public void HyperLinked(HyperlinkEvent e) throws URISyntaxException {
    if (e.getEventType() == HyperlinkEvent.EventType.ACTIVATED) {
        if (Desktop.isDesktopSupported()) {
            try {
                Desktop.getDesktop().browse(e.getURL().toURI());
            } catch (IOException | URISyntaxException e1) {
            }
        }
    }
}

サンプルのhtmlコードには、それぞれ独自のクリック可能なWebアドレスを持つ画像が含まれています

            </p>
            <p>
                <h4>Dungeons and Dragons</h4>
                <a href="http://www.ddo.com/" target="_blank"><img src="images/ddo.jpg" alt="Dungeons and Dragons Online" width="351" height="144" border="0" /></a>
            </p>
            <p>
                <h4>Lord of the Rings</h4>
                <a href="http://www.lotro.com/en?lang=en_GB&" target="_blank"><img src="images/lotro.jpg" alt="Lord of the Rings" width="351" height="144" border="0" /></a>
            </p>
            <p>
                <h4>Aion</h4>
                <a href="http://www.aionfreetoplay.com/website/" target="_blank"><img src="images/aion.jpg" alt="Aion" width="351" height="144" border="0" /></a>
            </p>
            <p>

以下の画像の例は、新しいユーザールールなどとして投稿できません http://s14.postimage.org/7xt52lbox/mmoset.jpg

画像を表示することができますが、クリック可能であり、JFrameでのみ機能することはわかっていますが、画像をクリックすることはできません。マウスクリックなどを追加する必要があるのでしょうか。

フィードバックや助けをいただければ幸いです。ありがとうございます。

4

1 に答える 1

0

あなたはほとんどそれを手に入れました。

    editor.addHyperlinkListener(new HyperlinkListener() {
        @Override
        public void hyperlinkUpdate(HyperlinkEvent e) {
            if (e.getEventType() == HyperlinkEvent.EventType.ACTIVATED) {
                if (Desktop.isDesktopSupported()) {
                    try {
                        Desktop.getDesktop().browse(e.getURL().toURI());
                    } catch (IOException | URISyntaxException e1) {
                    }
                }
            }
        }
    });
于 2013-01-28T16:05:34.680 に答える