mycount.java
来自「是一个综合开发程序,可以做为系统研究人员的参考」· Java 代码 · 共 51 行
JAVA
51 行
import java.awt.*;
import java.awt.event.*;
public class mycount {//extends Frame implements ActionListener
static Frame frm =new Frame("this is my first count");
static TextField text1 =new TextField();
static TextField text2 =new TextField();
static TextField text3 =new TextField();
static Button but1 =new Button("计算");
static Button but2 =new Button("清空");
static Button but3=new Button("退出");
public static void main(String[] args){
frm.setLayout(null);
frm.setLocation(300,150);
Label lab1 =new Label("第一个数 :");
Label lab2 =new Label("第二个数 :");
Label lab3 =new Label("两数和为:");
frm.setSize(250,200);
lab1.setBounds(30,30,60,30);
lab2.setBounds(30,70,60,30);
lab3.setBounds(30,110,60,30);
text1.setBounds(100,30,80,20);
text2.setBounds(100,70,80,20);
text3.setBounds(100,110,80,20);
but1.setBounds(30,140,40,20);
but2.setBounds(90,140,40,20);
but3.setBounds(150,140,40,20);
frm.add(lab1);
frm.add(lab2);
frm.add(lab3);
frm.add(text1);
frm.add(text2);
frm.add(text3);
frm.add(but1);
frm.add(but2);
frm.add(but3);
but1.addActionListener(new acti());
but2.addActionListener(new acti());
but3.addActionListener(new acti());
frm.show();
}
static class acti implements ActionListener{
public void actionPerformed(ActionEvent e){//actionPerformed 的P要大写
Button but=(Button) e.getSource();
if (but == but1){
String a,b;
int x,y, c;
a= text1.getText();
b= text2.getText();
x =Integer.parseInt(a);//将String转换成整数
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?