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

📄 10+

📁 本压缩文档为《Java大学实用教程》(7-121-00959-5 电子工业出版社 2005.3) 的电子教案。
💻
字号:
import javax.swing.*;
import java.awt.event.*;
import java.awt.*;
import java.util.regex.*;
import javax.swing.event.*;
class EditWindow extends JFrame implements DocumentListener 
{  
    JTextArea text1,text2;
    JTextField modelText;
    Pattern  p;                              //模式对象。
    Matcher  m;                             //匹配对象。
    EditWindow(String s) 
    {  
      super(s);        
      setSize(260,270);
      setLocation(120,120);
      setVisible(true);
      setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);               
      text1=new JTextArea();
      text2=new JTextArea();
      text1.setLineWrap(true);
      text1.setWrapStyleWord(true);
      text2.setLineWrap(true);
      text2.setWrapStyleWord(true);
      modelText=new JTextField("[0123456789]+");
      Container con=getContentPane();
      JPanel panel=new JPanel();
      panel.setLayout(new GridLayout(1,2));
      panel.add(new JScrollPane(text1));
      panel.add(new JScrollPane(text2));
      panel.validate();
      con.add(panel,BorderLayout.CENTER);
      con.add(modelText,BorderLayout.SOUTH);
      con.validate();
      validate();
      (text1.getDocument()).addDocumentListener(this);//向文档注册监视器。
    } 
    public void changedUpdate(DocumentEvent e)    //接口方法。 
    {
         text2.setText(null);
         String s=text1.getText();
         p=Pattern.compile(modelText.getText());  //初试化模式对象。
         m=p.matcher(s);                       
         while(m.find())
         {
           text2.append(m.group()+",");
         } 
    } 
    public void removeUpdate(DocumentEvent e)//接口方法。
    {
       changedUpdate(e);
    }
    public void insertUpdate(DocumentEvent e)//接口方法。
    {    
       changedUpdate(e);
    }

}
public class Example
{  
    public static void main(String args[])
    { 
      EditWindow win=new EditWindow("窗口");
    }
}

⌨️ 快捷键说明

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