📄 text.java
字号:
import javax.swing.*;
import java.applet.Applet;
import java.awt.*;
import java.lang.*;
import java.awt.event.*;
public class text extends Applet implements ActionListener{
TextField text1;Button but1;Label lab1;Label lab2;
double num=100+(200-100)*Math.random() ;
int intnum=0;
int temp=0;
public void init(){
setLayout(new FlowLayout());
text1=new TextField(20);
but1=new Button("猜");
lab1=new Label("请你输入100——200之间的数值!",Label.LEFT);
lab2=new Label(" ",Label.CENTER);
add(lab1);
add(text1);
add(but1);
add(lab2);
text1.addActionListener(this);
but1.addActionListener(this);
this.setSize(350,150);
}
public void actionPerformed(ActionEvent e) {
intnum=(int)num;
if(e.getSource()==but1){
temp=Integer.parseInt( text1.getText());
if(temp>100&&temp<200){
if(temp>intnum){
lab2.setText("大了");
}
else if(temp<intnum){
lab2.setText("小了");
}
else
lab2.setText("您答对啦!答案就是"+intnum);
}
else
lab2.setText("超出数据范围");
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -