1
나는 인터넷 검색을 수행했으며, 모든 메소드는 HTML에서 클릭 가능한 링크를 달성하는 방법에 대해서는 설명하지 않았습니다 (적어도 이해할만큼 충분하지는 않음). 조금 더 정교하게 기꺼이하려는 사람?JEditorPane에서 클릭 가능한 HTML 링크를 표시합니다.
내 코드 : 사전에
import javax.imageio.ImageIO;
import javax.swing.*;
import java.io.*;
import java.awt.*;
import java.awt.event.*;
import java.net.*;
public class WebBrowser extends JFrame {
public JPanel
address_panel, window_panel;
public JLabel
address_label;
public JTextField
address_tf;
public JEditorPane
window_pane;
public JScrollPane
window_scroll;
public JButton
address_b;
private Go go = new Go();
public WebBrowser() throws IOException {
try {
UIManager.setLookAndFeel("com.sun.java.swing.plaf.nimbus.NimbusLookAndFeel");
} catch (ClassNotFoundException e1) {
e1.printStackTrace();
} catch (InstantiationException e1) {
e1.printStackTrace();
} catch (IllegalAccessException e1) {
e1.printStackTrace();
} catch (UnsupportedLookAndFeelException e1) {
e1.printStackTrace();
}
Image image = null;
try {
image = ImageIO.read(new File("images/icon.gif"));
} catch (IOException e) {
e.printStackTrace();
}
address_label = new JLabel(" address: ", SwingConstants.CENTER);
address_tf = new JTextField("");
address_tf.addActionListener(go);
address_b = new JButton("Go");
address_b.addActionListener(go);
window_pane = new JEditorPane("http://(server):(port)/");
window_pane.setContentType("text/html");
window_pane.setEditable(false);
address_panel = new JPanel(new BorderLayout());
window_panel = new JPanel(new BorderLayout());
address_panel.add(address_label, BorderLayout.WEST);
address_panel.add(address_tf, BorderLayout.CENTER);
address_panel.add(address_b, BorderLayout.EAST);
window_scroll = new JScrollPane(window_pane);
window_panel.add(window_scroll);
Container pane = getContentPane();
pane.setLayout(new BorderLayout());
pane.add(address_panel, BorderLayout.NORTH);
pane.add(window_panel, BorderLayout.CENTER);
setIconImage(image);
setTitle("web browser");
setSize(800,600);
setVisible(true);
setDefaultCloseOperation(EXIT_ON_CLOSE);
}
public class Go implements ActionListener{
public void actionPerformed(ActionEvent ae){
try {
window_pane.setPage("http://(server):(port)/"+address_tf.getText());
} catch (MalformedURLException e) {
window_pane.setText("MalformedURLException: " + e);
} catch (IOException e) {
window_pane.setText("IOException: " + e);
}
}
}
}
덕분에 당신은 HyperlinkListener
하지 ActionListener
추가 할 필요가
AIRIS
질문 : 내가 뭘 잘못하고 있는지, 내가 정확히 무엇을하고 있는지 알 수있다. http://pastie.org/5499277 – Airis
나는 그것을 고맙게 생각했다. – Airis