...班级及学号,要求 名字设置为24号黑体,班级以及学号设置为16号加粗...

发布网友 发布时间: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


声明:本网页内容为用户发布,旨在传播知识,不代表本网认同其观点,若有侵权等问题请及时与本网联系,我们将在第一时间删除处理。
E-MAIL:11247931@qq.com