📄 suiji.java
字号:
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
public class SuiJi extends JFrame{
private int count = (int)(Math.random()*100)+0;
private JLabel Lab;
private JButton btn_ok;
private JTextField text_show,text_tip;
public SuiJi(){
super("随机数");
Lab = new JLabel("输入一个0~100的数:");
btn_ok = new JButton("OK");
text_show = new JTextField();
text_tip = new JTextField();
this.setSize(300,100);
this.setResizable(false);
this.setLocation(300,240);
this.add(Lab,"North");
this.add(text_tip,"South");
this.add(text_show,"Center");
this.add(btn_ok,"East");
this.setVisible(true);
btn_ok.addActionListener(new TFlistener());
this.addWindowListener(new WindowAdapter(){
public void windowClosing(WindowEvent e){
System.exit(0);
}
});
}
private class TFlistener implements ActionListener{
public void actionPerformed(ActionEvent e){
int i = Integer.parseInt(text_show.getText());
if(i>count){
text_tip.setText("所输的数较大,请重新输入");
text_show.setText("");
}
else if(i<count){
text_tip.setText("所输的数较小,请重新输入");
text_show.setText("");
}
else{
text_tip.setText("输入正确,数值为:"+text_show.getText());
}
}
}
public static void main(String args[]){
SuiJi suiji = new SuiJi();
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -