import java.awt.*; import javax.swing.*; import java.awt.event.*; import javax.swing.event.*; import javax.swing.text.*; import java.net.*; import java.io.*; public class Browser extends JPanel { public Browser() { setLayout (new BorderLayout ()); final JEditorPane jt = new JEditorPane(); final JTextField input = new JTextField("http://www.tpu.ee"); jt.setEditable(false); // reageeri viidetele jt.addHyperlinkListener(new HyperlinkListener () { public void hyperlinkUpdate( final HyperlinkEvent e) { if (e.getEventType() == HyperlinkEvent.EventType.ACTIVATED) { SwingUtilities.invokeLater(new Runnable() { public void run() { Document doc = jt.getDocument(); try { URL url = e.getURL(); jt.setPage(url); input.setText (url.toString()); } catch (IOException io) { //vahetus ebaõnnestus veateade(); jt.setDocument (doc); } } }); } } }); JScrollPane pane = new JScrollPane(); pane.setBorder ( BorderFactory.createLoweredBevelBorder()); pane.getViewport().add(jt); add(pane, BorderLayout.CENTER); input.addActionListener (new ActionListener() { public void actionPerformed (ActionEvent e) { try { jt.setPage (input.getText()); } catch (IOException ex) { veateade(); } } }); add (input, BorderLayout.SOUTH); try{jt.setPage(input.getText());} catch(IOException e){veateade();} } void veateade(){ JOptionPane.showMessageDialog ( Browser.this, "Vigane URL", "Tõenäoliselt vigane URL", JOptionPane.ERROR_MESSAGE); } public static void main(String argumendid[]){ JFrame f=new JFrame("Brauser"); f.getContentPane().add(new Browser()); f.setSize(300, 300); f.setVisible(true); } }