📄 main.java
字号:
/*
* Main.java
*
* Created on 2007年11月24日, 下午1:26
*
* To change this template, choose Tools | Template Manager
* and open the template in the editor.
*/
package exp3;
import java.util.Calendar;
import java.awt.*;
import java.awt.event.*;
/**
*
* @author Administrator
*/
public class Main {
/** Creates a new instance of Main */
public Main() {
}
/**
* @param args the command line arguments
*/
public static void main(String[] args) {
new FrameInOut();
}
}
abstract interface Getage{
public int Age();}
class closewindow extends WindowAdapter{
public void windowClosing(WindowEvent e)
{
Frame frm=(Frame)(e.getSource());
frm.dispose();
System.exit(0);
}
}
class FrameInOut extends Frame implements ActionListener,Getage{
public int Age(){
Calendar ca=Calendar.getInstance();
int year=ca.get(Calendar.YEAR);
String s=input.getText();
int yearborn=Integer.valueOf(s).intValue();
int hisage=year-yearborn;
return hisage;}
Label prompt1,prompt2;
TextField input,output;
Button btn1,btn2;
FrameInOut(){
super("计算年龄");
prompt1=new Label("请输入出生年份:");
prompt2=new Label(" 结果: ");
input=new TextField(10);
output=new TextField(15);
btn1=new Button("确定");
btn2=new Button("关闭");
setLayout(new FlowLayout());
add(prompt1);
add(input);
add(prompt2);
add(output);
add(btn1);
add(btn2);
addWindowListener(new closewindow());
btn1.addActionListener(this);
btn2.addActionListener(this);
setSize(250,150);
show();
}
public void actionPerformed(ActionEvent e){
if(e.getSource()==btn1){
output.setText("此人的年龄为:"+Age());
}
else{
dispose();
System.exit(0);}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -