untitled1.java~86~

来自「java 猜大小 图形界面 简单的java程序 适合初学java GUI着」· JAVA~86~ 代码 · 共 68 行

JAVA~86~
68
字号
package untitled1;
//import java.applet.Applet;
import java.awt.*;
import java.awt.event.*;
import java.util.*;

public class Untitled1  implements ActionListener {
    Frame f = new Frame("text");
    Label lb = new Label("");
    Label la = new Label("");
    Button b1 = new Button("小");
    Button b2 = new Button("大");
    Panel pan = new Panel();
    public Untitled1() {

        b1.addActionListener(this);
        b2.addActionListener(this);

        b1.setSize(80, 20);
        b2.setSize(80, 20);

        pan.setSize(100, 100);

        pan.setLayout(new GridLayout(2,2));

        pan.add(b2);  pan.add(b1);
        pan.add(lb);
        f.add(pan,BorderLayout.CENTER);
        f.add(la,BorderLayout.SOUTH);
        f.setSize(300, 200);
        f.setVisible(true);
    }

    public void actionPerformed(ActionEvent e) {
        Random x = new Random();
        int y = x.nextInt(10);

        String s = e.getActionCommand();
        if (s == "小") {
            lb.setText(Integer.toString(y));
            if (y <= 4)

                  la.setText("恭喜,您猜对了!");
              else
                  la.setText("对不起,您猜错了!");



        }
        if (s == "大") {lb.setText(Integer.toString(y));
            if (y >= 5)


                la.setText("恭喜,您猜对了!");
            else
            la.setText("对不起,您猜错了!");

        }


    }

    public static void main(String args[]) {
        Untitled1 pp = new Untitled1();

    }
}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?