您的位置:首页 > 产品设计 > UI/UE

第5周作业-打字成绩判断程序GUI

2014-04-05 22:17 309 查看
偷了点懒,功能没全部实现

import java.applet.Applet;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.*;

public class TouchTypeGUI extends Applet implements ActionListener {

/**
* @param args
*/
//新建各类组件对象
JPanel jp = new JPanel();
JPanel jp1 = new JPanel();
JLabel jl = new JLabel("打字数目");
JTextField tf = new JTextField(8);
JLabel jl1 = new JLabel("打字成绩");
JTextField tf1 = new JTextField(8);
JButton jb = new JButton("确定");
JButton jb1 = new JButton("清除");

public void init() {
//初始化组件并添加监听器
add(jp);
add(jp1);
jp.add(jl);
jp.add(tf);
jp.add(jl1);
jp.add(tf1);
jp1.add(jb);
jp1.add(jb1);
tf.addActionListener(this);
jb.addActionListener(this);
jb1.addActionListener(this);
setSize(350, 200);
setVisible(true);

}

// String st = str.toString();
//

public void actionPerformed(ActionEvent e) {
// TODO Auto-generated method stub
String st = tf.getText();//获取文本框的输入信息
Integer in = new Integer(st);

if (e.getSource() == jb1) {//清除文本框的显示信息
tf.setText(null);
tf1.setText(null);
}

//对控件的响应
if (e.getSource() == jb && in <= 15) { // && in < 15

tf1.setText("不及格!!!");

} else if (e.getSource() == jb && 15 < in && in <= 30) {
tf1.setText("合格!!!");

} else if (e.getSource() == jb && in > 30) {
tf1.setText("优秀!!!");
}

}

}





内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: