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

📄 ch9_28.java

📁 60多个javaSwing范例
💻 JAVA
字号:
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import javax.swing.undo.*;
import javax.swing.event.*;
public class ch9_28 extends JFrame implements UndoableEditListener,ActionListener
{
     UndoableEdit edit;
     JTextArea jt1=null;
     JTextArea jt2=null;
     
     JButton b1,b2;
    public ch9_28()
    {
        setBounds(20,20,500,300);
        getContentPane().setLayout(null);
        setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);              
    }
    public static void main(String [] args)
    {
        ch9_28 f=new ch9_28();
        f.getContentPane().setLayout(null);
        
        f.jt1=new JTextArea();
        f.jt1.setBounds(20,20,200,80);
        f.jt1.getDocument().addUndoableEditListener(f);
        
        
        f.jt2=new JTextArea();
        f.jt2.setBounds(230,20,200,80);
        f.jt2.setEditable(false);
        
        f.b1=new JButton("undo");
        f.b1.addActionListener(f);
        f.b1.setBounds(20,110,80,30);
        
        f.b2=new JButton("redo");
        f.b2.addActionListener(f);
        f.b2.setBounds(130,110,80,30);
       
        f.getContentPane().add(f.jt1);
        f.getContentPane().add(f.jt2);
        //f.add(new JScrollPane(f.jt1));
        //f.add(new JScrollPane(f.jt2));
        
        
        f.getContentPane().add(f.b1);
        f.getContentPane().add(f.b2);
        

        
      
        f.show();
    }
    public void actionPerformed(ActionEvent e)
    {
        if(e.getSource()==b1)
        {
            edit.undo();
            jt2.append("- undo -\n");
        }
        if(e.getSource()==b2)
        {
            edit.redo();
            jt2.append("- redo -\n");
        }
        

    }
    public void undoableEditHappened(UndoableEditEvent e)
    {
        StringBuffer buf=new StringBuffer(200);
        edit=e.getEdit();
        buf.append("undoableEdit:");
        buf.append(edit.getPresentationName());
        buf.append("\n");
        jt2.append(buf.toString());
    }    
}

⌨️ 快捷键说明

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