当前位置: 技术问答>java相关
又一个小问题,初学者!
来源: 互联网 发布时间:2015-10-16
本文导语: import java.awt.*; import java.awt.event.*; public class ListExample extends Frame implements ItemListener{ Panel p; List theList; TextField tf; ListExample(String s){ super(s); } public static void main(String args[]){ ListExample le = new ListExample...
import java.awt.*;
import java.awt.event.*;
public class ListExample extends Frame implements ItemListener{
Panel p;
List theList;
TextField tf;
ListExample(String s){
super(s);
}
public static void main(String args[]){
ListExample le = new ListExample("List Example");
le.init();
}
public void init(){
theList = new List(5,false);
theList.addItem("Monday");
theList.addItem("Tuesday");
theList.addItem("Wednesday");
theList.addItem("Thurday");
theList.addItem("Friday");
theList.addItem("Saturday");
theList.addItem("Sunday");
p = new Panel();
p.add(theList);
add(p,"Center");
tf = new TextField();
add(tf,"South");
setSize(300,300);
setVisible(true);
}
public void itemStateChanged(ItemEvent e){
tf.setText(theList.getSelectedItem());
}
}
构造函数里的super是怎么一回事啊,能不能给我说说super的用法?
import java.awt.event.*;
public class ListExample extends Frame implements ItemListener{
Panel p;
List theList;
TextField tf;
ListExample(String s){
super(s);
}
public static void main(String args[]){
ListExample le = new ListExample("List Example");
le.init();
}
public void init(){
theList = new List(5,false);
theList.addItem("Monday");
theList.addItem("Tuesday");
theList.addItem("Wednesday");
theList.addItem("Thurday");
theList.addItem("Friday");
theList.addItem("Saturday");
theList.addItem("Sunday");
p = new Panel();
p.add(theList);
add(p,"Center");
tf = new TextField();
add(tf,"South");
setSize(300,300);
setVisible(true);
}
public void itemStateChanged(ItemEvent e){
tf.setText(theList.getSelectedItem());
}
}
构造函数里的super是怎么一回事啊,能不能给我说说super的用法?
|
super指的是父类,意思是调用父类的构造函数
|
就是说他调用了父类的构造方法