package practice;import java.awt.Button;
import java.awt.Color;
import java.awt.FlowLayout;
import java.awt.Frame;
import java.awt.TextField;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;
import java.util.*;
public class SortingExample implements ActionListener{
Frame f;
TextField tf1;
Button b1,b2,b3,b4;
public void display() {
f=new Frame("Calculation");
f.setSize(260,150);
f.setLocation(320,240);
//f.setBounds(320, 240, 260, 150);可以代替上面两句
f.setBackground(Color.LIGHT_GRAY);
f.setLayout(new FlowLayout(FlowLayout.LEFT));
tf1=new TextField(30);
tf1.setEditable(false);
f.add(tf1);
b1=new Button("1");
b2=new Button("2");
b3=new Button("+");
b4=new Button("C");
f.add(b1);
f.add(b2);
f.add(b3);
f.add(b4);
b1.addActionListener(this);//this指的是?为什么既不是f又不是SortingExample类的对象?
b2.addActionListener(this);
b3.addActionListener(this);
b4.addActionListener(this);
f.addWindowListener(new WindowAdapter(){
public void windowClosing(WindowEvent e)
{
System.exit(0);
}
});
f.setVisible(true);
}
public void actionPerformed(ActionEvent e) {
if(e.getSource()==b4) 
tf1.setText(" ");
else
tf1.setText(tf1.getText()+e.getActionCommand());
}
public static void main(String[] args) throws java.io.FileNotFoundException{

(new SortingExample()).display();
}}

解决方案 »

  1.   

    this指的是?
    当前类的对象
      

  2.   

    b1.addActionListener(this);//this指的是?为什么既不是f又不是SortingExample类的对象?
    这个this是一个实现了 ActionListener的对象   实际就是SortingExample 
      

  3.   

    对于2楼的回答:SortingExample只是一个类而不是对象啊
      

  4.   

    this就是SortingExample类的对象,this代表当前类的对象,在你的例子中当前类就是SortingExample。加上下面的一句试试!看打印的结果就知道是不是了!
    System.out.println(this instanceof SortingExample);