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

📄 textareaclone.java

📁 Java课堂练习
💻 JAVA
字号:
/**
 * @(#)TextAreaClone.java
 *
 *
 * @author 
 * @version 1.00 2007/11/17
 */
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import java.io.*;

class Win extends JFrame implements ActionListener {
 JTextArea  text=null;
 JButton button;
 Win() {
  setLayout(new FlowLayout());
  text=new JTextArea(6,10);
  button=new JButton("文本区克隆");
  button.addActionListener(this);
  add(new JScrollPane(text));
  add(button);
  
  setVisible(true);
  setSize(500,300);
  validate();
  setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);  
 }
 Object  getClone(Object a) {
  Object object=null;
  try {
   FileOutputStream  outOne=new FileOutputStream("4.txt");
   ObjectOutputStream  outTwo=new ObjectOutputStream(outOne);
   outTwo.writeObject(a);
   FileInputStream inOne=new FileInputStream("4.txt");
   ObjectInputStream  inTwo=new ObjectInputStream(inOne);
   object=inTwo.readObject();   
  }
  catch (Exception e) {
   System.out.println(e);
  }
  return object;
 }
 public void actionPerformed(ActionEvent e) {
  JTextArea  textClone=(JTextArea) (getClone(text));
  textClone.setBackground(Color.pink);
  add(new JScrollPane(textClone));
  validate();
 }
}
public class TextAreaClone {
        
    /**
     * Creates a new instance of <code>TextAreaClone</code>.
     */
    public TextAreaClone() {
    }
    
    /**
     * @param args the command line arguments
     */
    public static void main(String[] args) {
        // TODO code application logic here
        new Win();
    }
}

⌨️ 快捷键说明

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