java 程序加注释

来源:百度知道 编辑:UC知道 时间:2024/06/22 08:21:57
import java.awt.*;
import java.awt.event.*;
public class welcomenYou {
public static void main(String args []){
new FrameInOut();
}
}

class FrameInOut extends Frame implements ActionListener {
Label prompt;
TextField input,output;
Button btnn;
FrameInOut(){
prompt=new Label("please input your name");
input=new TextField(10);
output=new TextField(25);
btnn=new Button("class");
setLayout(new FlowLayout());
add(prompt);
add(input);
add(output);
add(btnn);
btnn.addActionListener(this);
setSize(300,200);
show();
}
public void actionPerformed(ActionEvent e) {
if(e.getSource()==btnn)
output.setText(input.getText()+" welcome you!");
else {
dispose();
System.exit(0);
}
}
}
这个程序以已可以运行了,不过没有关闭按钮
加注释,如果加上关闭按钮就更好了
如果注解详细,我绝不惜分!

AWT和小程序,已经落伍了,现在人们都在使用Swing,不过Swing做一般的程序还可以,不过做实用性的就差了,建议你还是去看一些开源的GUI包

给你加了,希望对你的学习有帮助,最好的办法是自己试,一共也没有多少东西,注掉了,然后自己看效果,这样学得能快点,如果你没到一定的程度,看别人写的也没有什么进步

import java.awt.*;
import java.awt.event.*;

public class welcomenYou {

public static void main(String args[]) {
// 运行方法,实例化窗口类
new FrameInOut();
}
}

// 窗口类,引用了侦听器接口,可以写听事件
class FrameInOut extends Frame implements ActionListener {

// 文本标签
Label prompt;
// 文本框
TextField input, output;
// 按钮
Button btnn;

FrameInOut() {
// 实例化标签,上面显示的字是"please input your name"
prompt = new Label("please input your name");
// 实例化文本框
input = new TextField(10);
// 实例化文本框
output = new TextField(25);
// 实例化按钮,上面显示的字是"class"
btnn = new Button("class");
// 设置布局
setLayout(new FlowLayout());
// 添加标签
ad