windowtextarea.java

来自「这是哲学家问题算法」· Java 代码 · 共 52 行

JAVA
52
字号
 import java.awt.*;
 import java.awt.event.*;
 import java.util.*;
 class WindowTextArea extends Frame implements TextListener ,ActionListener
 {
 	TextArea text1,text2;
 	Button buttonSort;
 	WindowTextArea()
 	{
 		setLayout(new FlowLayout());
 		text1=new TextArea(6,15);
 		text2=new TextArea(6,15);
 		buttonSort=new Button("排序");
 		add(text1);
 		add(text2);
 		add(buttonSort);
 		text2.setEditable(false);
 		text1.addTextListener(this);
 		buttonSort.addActionListener(this);
 		setBounds(100,100,350,160);
 		setVisible(true);
 		validate();
 	}
 	public void textValueChanged(TextEvent e)
 	{
 		String s=text1.getText();
 		String t[]=s.split(",");
 		text2.setText(null);
 		for(int i=0;i<t.length;i++)
 		{
 			text2.append(t[i]+"\n");
 		}
 	}
 	public void actionPerformed(ActionEvent e)
 	{
 		String s=text2.getText();
 		String t[]=s.split(",");
 		text2.setText(null);
 		Arrays.sort(t);
 		for(int i=0;i<t.length;i++)
 		{
 			text2.append(t[i]+"\n");
 		}
 	}
 }
 class Main
 {
 	public static void main(String args[])
 	{
 		WindowTextArea win=new WindowTextArea();
 	}
 }

⌨️ 快捷键说明

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