home *** CD-ROM | disk | FTP | other *** search
/ Online Praxis 1998 March / Image.iso / CD-ROM / HOMEPAGE / JAVA / ICE40.EXE / examples / DocView.java < prev    next >
Encoding:
Java Source  |  1998-03-02  |  3.8 KB  |  120 lines

  1. import java.awt.*;
  2. import java.awt.event.*;
  3. import java.io.StringReader;
  4.  
  5. import ice.htmlbrowser.*;
  6.  
  7. public class DocView extends Frame
  8.     implements WindowListener, ActionListener {
  9.  
  10.         protected Document doc = null;
  11.         protected TextArea ta = null;
  12.         protected TextField db = null;
  13.         protected Button btnUpdate = null;
  14.         
  15.     public static void main(String[] args) {
  16.         new DocView();
  17.     }
  18.  
  19.         public DocView() 
  20.         {
  21.                 super("HTML Document Test");
  22.  
  23.                 setSize( 650, 500 );
  24.                 setBackground( new Color( 192, 192, 192 ) );
  25.                 setResizable( true );
  26.  
  27.                 addWindowListener( this );
  28.                 
  29.                 makeGUI();
  30.                 this.show();
  31.         }
  32.  
  33.  
  34.  
  35.         public void actionPerformed(ActionEvent event) {
  36.                 String command = event.getActionCommand();
  37.                 if(command.equals("Update")) btClicked();
  38.         }
  39.         
  40.         private void btClicked() {
  41.         doc.htmlClear();
  42.  
  43.         try {
  44.             doc.setDocumentBaseString(db.getText());
  45.         }
  46.         catch (java.net.MalformedURLException m) {
  47.             String msg ="<b>Bad URL for document base "+db.getText()+"</b><br>";
  48.             doc.htmlAppend(msg);
  49.             doc.htmlWait(false);
  50.         }
  51.  
  52.         doc.htmlAppend(ta.getText());
  53.         doc.htmlWait(false);
  54.         }
  55.  
  56.     Panel containerPanel = new Panel();
  57.  
  58.         private void makeGUI()
  59.         {
  60.                 containerPanel.setLayout( null );
  61.  
  62.                 doc = new Document();
  63.                 
  64.                 doc.setBounds( new Rectangle( new Dimension( 431, 195 ) ) ); 
  65.                 doc.setLocation( 77, 10 );
  66.                 containerPanel.add( doc );
  67.                 doc.setBackground( new Color( 192, 192, 192 ) );
  68.                 doc.setForeground( new Color( 0, 0, 0 ) );
  69.                 doc.setEnabled( true );
  70.                 doc.setVisible( true );
  71.  
  72.                 ta = new TextArea( "", 0, 20 );
  73.                 ta.setBounds( new Rectangle( new Dimension( 431, 195 ) ) ); 
  74.                 ta.setLocation( 77, 225 );
  75.                 containerPanel.add( ta );
  76.                 ta.setBackground( new Color( 192, 192, 192 ) );
  77.                 ta.setForeground( new Color( 0, 0, 0 ) );
  78.                 ta.setEnabled( true );
  79.                 ta.setVisible( true );
  80.  
  81.         Label dbl = new Label("Document base:");
  82.                 dbl.setBounds( new Rectangle( new Dimension( 150, 15 ) ) ); 
  83.                 dbl.setLocation( 77, 435 );
  84.                 containerPanel.add( dbl );
  85.                 dbl.setVisible( true );
  86.  
  87.         db = new TextField("http://",140);
  88.                 db.setBounds( new Rectangle( new Dimension( 281, 30 ) ) ); 
  89.                 db.setLocation( 77+150, 430 );
  90.                 containerPanel.add( db );
  91.  
  92.                 db.setBackground( new Color( 192, 192, 192 ) );
  93.                 db.setForeground( new Color( 0, 0, 0 ) );
  94.                 db.setEnabled( true );
  95.                 db.setVisible( true );
  96.  
  97.  
  98.                 btnUpdate = new Button( "Update" );
  99.                 btnUpdate.setBounds( new Rectangle( new Dimension( 106, 23 ) ) ); 
  100.                 btnUpdate.setLocation( 532, 397 );
  101.                 containerPanel.add( btnUpdate );
  102.                 btnUpdate.setBackground( new Color( 192, 192, 192 ) );
  103.                 btnUpdate.setForeground( new Color( 0, 0, 0 ) );
  104.                 btnUpdate.setEnabled( true );
  105.                 btnUpdate.setVisible( true );
  106.                 btnUpdate.addActionListener(this);
  107.                 add( containerPanel );
  108.         }
  109.  
  110.         public void windowClosing( WindowEvent event ) { dispose(); }
  111.         public void windowOpened( WindowEvent event ) {}
  112.         public void windowIconified( WindowEvent event ) {}
  113.         public void windowDeiconified( WindowEvent event ) {}
  114.         public void windowClosed( WindowEvent event ) { System.exit(0);}
  115.         public void windowActivated( WindowEvent event ) {}
  116.         public void windowDeactivated( WindowEvent event ) {}
  117. }
  118.  
  119.  
  120.