?? ch9_28.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 + -