求把每一句都写上注解、越详细越好、谢谢啦~
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import java.lang.*;
public class Test51{
Frame f;
TextArea center;
Label la1,la2,la3;
Panel east,south,north;
Button b1,b2,b3,b4;
Choice l1;
TextField t1;
public static void main(String[] args){
Test51 mb = new Test51();
mb.go();
}
private void go(){
f = new Frame("留言版程序");
f.addWindowListener(new WindowAdapter(){
public void windowClosing(WindowEvent evt){
f.setVisible(false);
System.exit(0);
}
});
f.setBounds(0,0,600,400);
f.setLayout(new BorderLayout());
f.setResizable(false);
north = new Panel();
south = new Panel();
east = new Panel();
center = new TextArea("留言内容:");
center.setEditable(false);
b1 = new Button("清屏");
b2 = new Button("至顶");
b3 = new Button("至尾");
la1 = new Label("留言版");
la2 = new Label("你");
la3 = new Label(" 地说:");
t1 = new TextField(20);
b4 = new Button("提交");
l1 =new Choice();
l1.add("微笑 ");
l1.add("生气 ");
l1.add("伤心 ");
f.add(BorderLayout.NORTH,north);
f.add(BorderLayout.SOUTH,south);
f.add(BorderLayout.EAST,east);
f.add(BorderLayout.CENTER,center);
north.add(BorderLayout.CENTER,la1);
south.add(la2);
south.add(l1);
south.add(la3);
south.add(t1);
south.add(b4);
east.setLayout(new GridLayout(9,0,1,10));
east.add(b1);
east.add(b2);
east.add(b3);
f.setVisible(true);
b4.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent e){
String text1,text2;
text1 = l1.getSelectedItem();
text2 = t1.getText();
t1.setText(null);
if(t1.getText() != ""){
center.append("\n");
center.append(text1);
center.append(text2);
}
}
});
b1.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent e){
center.setText("留言内容:");
}
});
b2.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent e){
center.requestFocusInWindow();
center.setCaretPosition(8);
}
});
b3.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent e){
center.requestFocusInWindow();
center.setCaretPosition(center.getText().length());
}
});
}
}
嗯、没学会、额…应该说没听吧、嘿嘿…