发布网友 发布时间:2024-10-24 16:31
共2个回答
热心网友 时间:2024-11-01 23:40
import java.applet.Applet;
import java.awt.*;
import java.awt.event.*;
public class Student extends Applet implements TextListener
{
String stname = "";
String msg = "";
String classno = "";
int stno = 0;
TextField inputname,inputclassno,inputstno;
public void init()
{
inputname = new TextField(10);
inputclassno = new TextField(24);
inputstno = new TextField(24);
inputname.addTextListener(this);
inputclassno.addTextListener(this);
inputstno.addTextListener(this);
add(inputname);
add(inputclassno);
add(inputstno);
}
public void paint(Graphics g)
{
g.setFont(new Font("TimesRoman",Font.BOLD,24));
g.drawString(stname, 20, 150);
g.setFont(new Font("TimesRoman",(Font.ITALIC)|(Font.BOLD),16));
g.drawString(classno,20,180);
g.drawString(msg,20,200);
}
@Override
public void textValueChanged(TextEvent e) {
stname = inputname.getText();
classno = inputclassno.getText();
try{
this.setstno(inputstno.getText());
msg = " "+stno;
}catch(NumberFormatException ee){
msg = "请输入正确的学号";
}
repaint();
}
void setstno(String i)
{
stno = Integer.parseInt(inputstno.getText());
}
int getstno(){
return stno;
}
}
热心网友 时间:2024-11-01 23:32