📄 xianshi.java
字号:
/*2.编写一程序,使之具有如下功能:选中左边的列表中某项时,
*会自动添加到右边的列表中;当按Close按钮时,则结束程序的运行。
*提示:使用列表的remove()方法移除选中的项。*/
import java.awt.*;
import java.awt.event.*;
import java.util.*;
class xianshi extends Frame implements TextListener,ActionListener
{
TextArea text1,text2;
Button buttonClear;
xianshi()
{
Frame frm=new Frame();
frm.setLayout(new FlowLayout());
frm.setSize(300,300);
text1=new TextArea(6,15);
text2=new TextArea(6,15);
buttonClear=new Button("close");
frm.add(text1);
frm.add(text2);
frm.add(buttonClear);
text2.setEditable(false);
text1.addTextListener(this);
buttonClear.addActionListener(this);
frm.setBounds(200,200,400,200);
frm.setVisible(true);
validate();
}
public void textValueChanged(TextEvent e)
{
String s=text1.getText();
StringTokenizer fenxi=new StringTokenizer(s,",'\n'");
int n=fenxi.countTokens();
String a[]=new String[n];
for(int i=0;i<=n-1;i++)
{
String temp=fenxi.nextToken();
a[i]=temp;
}
Arrays.sort(a);
text2.setText(null);
for(int i=0;i<n;i++)
{
text2.append(a[i]+"\n");
}
}
public void actionPerformed(ActionEvent e)
{
text1.setText(null);
System.exit(0);
}
public static void main(String args[])
{
xianshi win=new xianshi();
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -