Biblioteca Java - Blame information for rev 3
Subversion Repositories:
Rev | Author | Line No. | Line |
---|---|---|---|
3 | mihai | 1 | /* |
2 | * Browser.java | ||
3 | */ | ||
4 | package lab.scd.net.browser; | ||
5 | |||
6 | /** | ||
7 | * Class created by @author Mihai HULEA at Feb 25, 2005. | ||
8 | * | ||
9 | * This class is part of the laborator2_net project. | ||
10 | * | ||
11 | */ | ||
12 | import javax.swing.*; | ||
13 | import java.awt.*; | ||
14 | import javax.swing.event.*; | ||
15 | import javax.swing.text.*; | ||
16 | import java.net.*; | ||
17 | import java.io.*; | ||
18 | import java.awt.event.*; | ||
19 | |||
20 | |||
21 | class Browser extends JPanel { | ||
22 | Browser() { | ||
23 | setLayout (new BorderLayout (5, 5)); | ||
24 | final JEditorPane jt = new JEditorPane(); | ||
25 | final JTextField input = | ||
26 | new JTextField("http://127.0.0.1:8080"); | ||
27 | // read-only | ||
28 | jt.setEditable(false); | ||
29 | |||
30 | // follow links | ||
31 | |||
32 | jt.addHyperlinkListener(new HyperlinkListener () { | ||
33 | public void hyperlinkUpdate( | ||
34 | final HyperlinkEvent e) { | ||
35 | if (e.getEventType() == | ||
36 | HyperlinkEvent.EventType.ACTIVATED) { | ||
37 | SwingUtilities.invokeLater(new Runnable() { | ||
38 | public void run() { | ||
39 | // Save original | ||
40 | Document doc = jt.getDocument(); | ||
41 | try { | ||
42 | URL url = e.getURL(); | ||
43 | jt.setPage(url); | ||
44 | input.setText (url.toString()); | ||
45 | } catch (IOException io) { | ||
46 | JOptionPane.showMessageDialog ( | ||
47 | Browser.this, "Can't follow link", | ||
48 | "Invalid Input", | ||
49 | JOptionPane.ERROR_MESSAGE); | ||
50 | jt.setDocument (doc); | ||
51 | } | ||
52 | } | ||
53 | }); | ||
54 | } | ||
55 | } | ||
56 | }); | ||
57 | |||
58 | JScrollPane pane = new JScrollPane(); | ||
59 | pane.setBorder ( | ||
60 | BorderFactory.createLoweredBevelBorder()); | ||
61 | pane.getViewport().add(jt); | ||
62 | add(pane, BorderLayout.CENTER); | ||
63 | |||
64 | input.addActionListener (new ActionListener() { | ||
65 | public void actionPerformed (ActionEvent e) { | ||
66 | try { | ||
67 | jt.setPage (input.getText()); | ||
68 | } catch (IOException ex) { | ||
69 | JOptionPane.showMessageDialog ( | ||
70 | Browser.this, "Invalid URL", | ||
71 | "Invalid Input", | ||
72 | JOptionPane.ERROR_MESSAGE); | ||
73 | } | ||
74 | } | ||
75 | }); | ||
76 | add (input, BorderLayout.SOUTH); | ||
77 | } | ||
78 | } | ||
79 | |||
80 | |||
81 | |||
82 |