/* 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 java.awt.* ; 

3. import java.awt.event.*; 

4. import java.applet.AppletContext

5. import java.net.*; 

6.  

7. public class ShowHTML 

8.     extends JApplet 

9.     implements ActionListener 

10.

11.   AppletContext brow ; 

12.  

13.   JButton btn ; 

14.   JTextField tf; 

15.   JLabel lbl; 

16.   public void actionPerformed( ActionEvent ev ) 

17.   { 

18.     lbl.setText( ""); 

19.     try

20.       String tx = tf.getText(); 

21.  

22.       URL htmdoc = new URL ( tx ) ; 

23.       brow.showDocument ( htmdoc , "fraym" ) ; 

24. //      brow.showDocument ( htmdoc , "_self" ) ; 

25.     } 

26.     catch ( MalformedURLException er ) 

27.       {  lbl.setText ( "Incorrect ...." ) ; } 

28.     catch ( Exception er ) 

29.       {   lbl.setText ( "Error : " + er ) ; } 

30.   } 

31.   public void init() 

32.   { 

33.     brow = getAppletContext() ; 

34.  

35.     Container cp = getContentPane() ; 

36.     cp.setBackground( Color.pink ) ; 

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

38.     cp.add ( btn ) ; 

39.     cp.add ( tf ) ; 

40.     cp.add ( lbl ) ; 

41.     btn.addActionListener( this ) ; 

42.     tf.addActionListener( this ) ; 

43.   } 

44.   public ShowHTML() 

45.   { 

46.     tf = new JTextField

47.       "http://science.nasa.gov/Realtime/jtrack/spacecraft.html" ) ; 

48.  

49.     btn = new JButton ( "Click me, please" ) ; 

50.     lbl = new JLabel ("================================"); 

51.   } 

52.