/* Copyright (c) SEMM NL All rights reserved.
Author : Paul Hamaker. Part of JavaLessons.com
This code is for educational purposes only. Use at own risk.*/

1. import javax.swing.*; 

2. import javax.swing.event.*; 

3. import java.awt.*; 

4. import java.awt.event.*; 

5. import java.net.*; 

6.  

7. public class SwEdit 

8.     extends JApplet 

9.     implements  HyperlinkListener 

10.

11.   JEditorPane edp ; 

12.   JScrollPane sp ; 

13.  

14.   public void init() 

15.   { 

16.     try

17.     url = new URL ( getCodeBase(), "test.html" ); 

18.  

19.     edp = new JEditorPane(); 

20.     edp.setPage (url); 

21.     edp.setEditable (false); 

22.     edp.addHyperlinkListener (this); 

23.  

24.     lbl.setText ( url.toString() ) ; 

25.  

26.     sp = new JScrollPane( edp ) ; 

27.     } 

28.     catch (Exception exc) { 

29.        System.err.println(""+ exc ); 

30.     } 

31.     cp = getContentPane() ; 

32.     cp.setLayout ( new FlowLayout()  ); 

33.     sp.setPreferredSize ( new Dimension(400,400) ) ; 

34.     cp.add ( sp ) ; 

35.     lbl.setBackground ( Color.green ) ; 

36.     lbl.setOpaque ( true ) ; 

37.     cp.add ( lbl ) ; 

38.     cp.setBackground( Color.yellow ); 

39.   } 

40.  

41.   public void 

42.   hyperlinkUpdate ( HyperlinkEvent ev ) 

43.   { 

44.     try

45.     if ( ev.getEventType( ) 

46.       == HyperlinkEvent.EventType.ACTIVATED

47.     { 

48.       edp.setPage ( ev.getURL()  ); 

49.  

50.       lbl.setText ( ev.getURL() +"" ) ; 

51.       } 

52.     } 

53.     catch ( Exception ex ) 

54.     { System.out.println(ex); } 

55.   } 

56.  

57.   JLabel lbl = new JLabel ( "===nothing yet===" ) ; 

58.   Container cp ; 

59.   URL url ; 

60.

61. ====  test.html  ========================= 

62. <HTML

63. <TITLE

64. This edition 

65. </TITLE

66. <BODY

67.  

68. <center> 

69. Another <a href="test2.html">HTML file's hyperlink</a> . 

70. </center> 

71.  

72. <h1>JEditorPane</h1

73.  

74. <h2>In this edition ...</h2

75.  

76. <h3>A <i>JEditorPane</i>, showing HTML .</h3> 

77.  

78. <HR width="100%"

79.  

80. <TABLE border="20"

81.  

82. <tr> 

83. <th>First</th> 

84. <td>Moolah</td> 

85. </tr> 

86.  

87. <tr> 

88. <th>Second</th> 

89. <td>Troolah</td> 

90. </tr> 

91.  

92. </table

93.  

94. <br

95.  

96. <UL

97. <li>Ha 

98. <li>my good friend 

99. <li>who are you ? 

100. <li>today 

101. </ul

102.  

103. <br

104.  <hr width=100%> 

105.  

106. <center> 

107.  

108. <address> 

109. Copyright © 2000 System Exclusive & Multi Midi (NL) All rights 

110. reserved</address></center> 

111.  

112. </BODY

113.  

114. </HTML

115.