关闭

JTextAreaDemo.java

136人阅读 评论(0) 收藏 举报
分类:

这里写图片描述

package com.learn.JFrame;

import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.Container;
import java.awt.Font;
import java.awt.GridLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;

import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
import javax.swing.JTextArea;  

//实现接口ActionListener  
public class JTextAreaDemo implements ActionListener {  

    JFrame jf;  
    JPanel jpanel;  
    JButton jb1, jb2, jb3;  
    JTextArea jta = null;  
    JScrollPane jscrollPane;  

    public JTextAreaDemo() {  

        jf = new JFrame("proteena_LJK");  
        Container contentPane = jf.getContentPane();  
        contentPane.setLayout(new BorderLayout());  

        jta = new JTextArea(10, 15);  
        jta.setTabSize(4);  
        jta.setFont(new Font("微软雅黑", Font.BOLD, 16));  
        jta.setLineWrap(true);// 激活自动换行功能  
        jta.setWrapStyleWord(true);// 激活断行不断字功能  
        jta.setBackground(Color.pink);  

        jscrollPane = new JScrollPane(jta);  
        jpanel = new JPanel();  
        jpanel.setLayout(new GridLayout(1, 3));  

        jb1 = new JButton("Copy");  
        jb1.addActionListener(this);  
        jb2 = new JButton("Paste");  
        jb2.addActionListener(this);  
        jb3 = new JButton("Cut");  
        jb3.addActionListener(this);  

        jpanel.add(jb1);  
        jpanel.add(jb2);  
        jpanel.add(jb3);  

        contentPane.add(jscrollPane, BorderLayout.CENTER);  
        contentPane.add(jpanel, BorderLayout.SOUTH);  

        jf.setSize(400, 300);  
        jf.setLocation(400, 200);  
        jf.setVisible(true);  

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

    // 覆盖接口ActionListener的方法actionPerformed  
    public void actionPerformed(ActionEvent e) {  
        if (e.getSource() == jb1) {  
            jta.copy();  
        } else if (e.getSource() == jb2) {  
            jta.paste();  
        } else if (e.getSource() == jb3) {  
            jta.cut();  
        }  
    }  

    public static void main(String[] args) {  
        new JTextAreaDemo();  
    }  
}  
0
0

查看评论
* 以上用户言论只代表其个人观点,不代表CSDN网站的观点或立场
    个人资料
    • 访问:5404次
    • 积分:176
    • 等级:
    • 排名:千里之外
    • 原创:10篇
    • 转载:10篇
    • 译文:0篇
    • 评论:1条
    文章分类