java图象用户界面笔记

来源:互联网 发布:javascript常用 编辑:程序博客网 时间:2024/06/06 23:55

import java.awt.*;
import java.awt.event.*;
public class Second extends Frame implements TextListener,ActionListener {
 TextField tf1,tf2,tf3;
 public Second()
 {
  tf1=new TextField(10);
  tf2=new TextField(10);
  tf3=new TextField(10);
  tf1.addActionListener(this);
  tf1.addTextListener(this);
  tf2.addTextListener(this);
  Label la1,la2;
  la1=new Label("+");
  la2=new Label("=");
  setLayout(new FlowLayout());
  add(tf1);
  add(la1);
  add(tf2);
  add(la2);
  add(tf3);
  
  
  setVisible(true);
  pack();
 }
 

 public void textValueChanged(TextEvent e) {
  int num=Integer.parseInt(tf1.getText())+Integer.parseInt(tf2.getText());
  tf3.setText(""+num);
  
 }


 public void actionPerformed(ActionEvent e) {
  tf2.requestFocus();
  
 }
 public static void main(String [] args)
 {
  new Second();
 }
 

}
 

原创粉丝点击