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

📄 testjtextarea.java

📁 java2 primer plus一书源程序
💻 JAVA
字号:
/* * TestJTextArea.java * * Created on July 30, 2002, 2:36 PM */package ch16;import javax.swing.*;import java.awt.*;import java.awt.event.*;/** * * @author  Stephen Potts * @version */public class TestJTextArea extends JFrame implements ActionListener{    JButton btnExit;    JButton btnAppend;    JButton btnInsert;    JButton btnReplace;    JTextArea taLetter;    JPanel p1;    JScrollPane sp;        /** Creates new TestJTextArea */    public TestJTextArea()    {        btnAppend = new JButton("Append");        btnAppend.addActionListener(this);        btnInsert = new JButton("Insert");        btnInsert.addActionListener(this);        btnReplace = new JButton("Replace");        btnReplace.addActionListener(this);        btnExit = new JButton("Exit");        btnExit.addActionListener(this);        taLetter =        new JTextArea(10,20);        taLetter.setLineWrap(true);        taLetter.setWrapStyleWord(true);        taLetter.append(              "I am writing this letter to inform you that you");        taLetter.append(              " have been drafted into the United States Army.");        taLetter.append(              " You will report to Fort Bragg, North Carolina ");        taLetter.append(              "on July 20, 1966.  You will be assigned to ");        taLetter.append("Vietnam.");                p1 = new JPanel();        p1.add(taLetter);        //create the scroll pane        sp = new JScrollPane(p1);        sp.setHorizontalScrollBarPolicy(                   JScrollPane.HORIZONTAL_SCROLLBAR_ALWAYS);        sp.setVerticalScrollBarPolicy(                   JScrollPane.VERTICAL_SCROLLBAR_ALWAYS);                getContentPane().add(btnAppend);        getContentPane().add(btnInsert);        getContentPane().add(btnReplace);        getContentPane().add(btnExit);        getContentPane().add(sp);                this.getContentPane().setLayout(new FlowLayout());                this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);                setTitle("Using a JTextArea Object");        setBounds( 100, 100, 400, 400);        setVisible(true);    }        public void actionPerformed(ActionEvent ae)    {        if (ae.getActionCommand().equals("Append"))            taLetter.append("\n\nSincerely, \n     The Draft Board");        if (ae.getActionCommand().equals("Insert"))            taLetter.insert("Dear Steve,\n     ", 0);        if (ae.getActionCommand().equals("Replace"))            taLetter.replaceRange("Dear Jerry,\n     ", 0, 12);        if (ae.getActionCommand().equals("Exit"))            System.exit(0);    }        public static void main(String[] args)    {        TestJTextArea tjta = new TestJTextArea();    }    }

⌨️ 快捷键说明

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