📄 xlcd.java
字号:
import java.awt.*;
import java.awt.*;
public class Xlcd extends java.applet.Applet implements
ItemListener,ActionListener
{
Choice choice;
TextField text;
TextArea area;
Button add;
Button del;
public void init()
{ setLayout(new GridLayout(3,1));
choice=new Choice();
text=new TextField(12);
area=new TextArea("S",20,10,TextArea.SCROLLBARS_BOTH);
add=new Button("添加");
del=new Button("删除");
choice.add("音乐天地");
choice.add("清华大学");
choice.add("北京大学");
choice.add("学友之旅");
Panel p1=new Panel();
Panel p2=new Panel();
Panel p3=new Panel();
add(p1,"North");
add(p2,"Center");
add(p3,"South");
p1.add(choice);
p1.add(del);
p2.add(text);
p2.add(add);
p3.add(area);
choice.addItemListener(this);
add.addActionListener(this);
del.addActionListener(this);
}
public void itemStateChanged(ItemEvent e)
{
String name=choice.getSelectedItem();
int index=choice.getSelectedIndex();
area.setText("\n"+index+":"+name+"\n");
}
public void actionPerformed(ActionEvent e)
{
if (e.getSource()==add||e.getSource()==text)
{
String str=text.getText();
if(str.length()>0)
{
choice.add(str);
area.append("\n"+"增加"+str);
choice.select(str);
}
}
if (e.getSource()==del)
{String st=choice.getSelectedItem();
choice.remove(st);
area.append("\n"+"删除"+st);
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -