📄 untitled1.java~85~
字号:
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();
// Monitor bh = new Monitor();
//Monitor bh2 = new Monitor();
public Untitled1() {
b1.addActionListener(this);
b2.addActionListener(this);
//lb.setEditable(false);
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("CENTER",lb);
f.add(pan,BorderLayout.CENTER);
f.add(la,BorderLayout.SOUTH);
f.setSize(300, 200);
f.setVisible(true);
}
public void actionPerformed(ActionEvent e) {
//String s=new String("");
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();
}
}
/*public class Untitled1
{
public static void main(String args[]) {
Untitled2 pp = new Untitled2();
}
}
class Monitor extends Applet implements ActionListener {
public void actionPerformed(ActionEvent e) {
//String s=new String("");
Random x=new Random();
int y=x.nextInt(10);
String s=e.getActionCommand();
if(s=="小")
{
if(y<=4)
{
System.out.print(y);
lb.setText(Integer.toString(y));
}
}
if(s=="大")
{
if(y>=5)
{
//((TextField) e.getSource()).setText(Integer.toString(y));
}
}
}
}
*/
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -