⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 editordemo.java

📁 java 完全探索的随书源码
💻 JAVA
字号:
// EditorDemo.java

import javax.swing.*;
import javax.swing.event.*;

import java.awt.*;
import java.awt.event.*;

import java.net.*;

class EditorDemo extends JFrame
                 implements ActionListener, HyperlinkListener
{
   JEditorPane view;
   JTextField commandLine;

   EditorDemo (String title)
   {
      super (title);

      addWindowListener (new WindowAdapter ()
                         {
                             public void windowClosing (WindowEvent e)
                             {
                                System.exit (0);
                             }
                         });

      commandLine = new JTextField ();
      commandLine.addActionListener (this);
      getContentPane ().add (commandLine, BorderLayout.NORTH);

      view = new JEditorPane ();
      view.setEditable (false);
      view.setPreferredSize (new Dimension (400, 400));
      view.addHyperlinkListener (this);

      getContentPane ().add (view, BorderLayout.CENTER);

      pack ();
      setVisible (true);
   }

   public void actionPerformed (ActionEvent e)
   {
      try
      {
         URL url = new URL (e.getActionCommand ());
         view.setPage (url);
         commandLine.setText (url.toExternalForm ());
      }
      catch (MalformedURLException e2)
      {
         System.out.println ("Bad URL: " + e.getActionCommand ());
      }
      catch (java.io.IOException e2) {}
   }

   public void hyperlinkUpdate (HyperlinkEvent e)
   {
      try
      {
         view.setPage (e.getURL ());
         commandLine.setText (e.getURL ().toExternalForm ());
      }
      catch (java.io.IOException e2) {}
   }

   public static void main (String [] args)
   {
      new EditorDemo ("Editor Demo");
   }
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -