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

📄 usetextarea1.java

📁 Java语言
💻 JAVA
字号:
import java.awt.*;
import java.awt.event.*;
public class UseTextArea1{
   public static void main(String args[]){
	MyFrame f=new MyFrame();
	f.setSize(300,200);
	f.setBackground(Color.lightGray);
	f.setLayout(new FlowLayout());
	f.show();
   }
}
class MyFrame extends Frame implements ActionListener{
	TextArea ta1;	TextField tf1;
	Button btn1,btn2,btn3;
	public MyFrame(){
	   super("my frame");
	   ta1=new TextArea(4,30);
	   tf1=new TextField(30);
	   btn1=new Button("添加文本");
	   btn2=new Button("插入文本");
	   btn3=new Button("替换选中文本");
	   btn1.addActionListener(this);
	   btn3.addActionListener(this);
	   btn2.addActionListener(this);
	   System.out.println(this.toString());	
	   setLayout(new FlowLayout());
	   add(ta1); add(tf1); add(btn1); add(btn2); add(btn3); 
	   this.addWindowListener(new WindowAdapter(){
              public void windowClosing(WindowEvent e){
			dispose();
			System.exit(0);
	      }});
	}
   public void actionPerformed(ActionEvent e){
      if(e.getSource()==btn1){
	ta1.append(tf1.getText());
	tf1.setText("");
      }
     if(e.getSource()==btn2){
	ta1.insert(tf1.getText(),ta1.getCaretPosition());
	tf1.setText("");
      }
     if(e.getSource()==btn3){
        int k0=ta1.getSelectionStart();
        int k1=ta1.getSelectionEnd();
	ta1.replaceRange(tf1.getText(),k0,k1);
      }      
   }
}

⌨️ 快捷键说明

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