首页上一页 1 下一页尾页 3 条记录 1/1页
关于一个无参的构造函数
发表在JavaWeb图书答疑
2009-08-06
是否精华
是
否
版块置顶:
是
否
package swing;
import java.awt.*;
import java.awt.event.*;
import java.lang.*;
import javax.swing.*;
public class JComboBoxModelTest extends JFrame{
JComboBox jc=new JComboBox(new MyComboBox());
JLabel jl=new JLabel("请选择证件");
public JComboBoxModelTest(){
setTitle("在窗体中设置下拉菜单");
setSize(200,150);
setVisible(true);
setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE);
Container container=getContentPane();
container.setLayout(new FlowLayout());
container.add(jl);
container.add(jc);
}
public static void main(String[] args) {
// TODO Auto-generated method stub
new JComboBoxModelTest();
}
}
class MyComboBox extends AbstractListModel implements ComboBoxModel{
String selecteditem=null;
String[] test={"军人证","身份证","学生证","工作证"};
public Object getElementAt(int index){
return test[index];
}
public int getSize(){
return test.length;
}
public void setSelectedItem(Object item){
selecteditem=(String)item;
}
public Object getSelectedItem(){
return selecteditem;
}
}
第8行那个JComboBox jc=new JComboBox(new MyComboBox());里的new MyComboBox()是怎么调用的
在在那个MyComboBox类里里并没有定义无参的构造函数MyComboBox(),调用new MyComboBox()时,会调用MyComboBox类里的成员方法吗,/*MyComboBox类里的getElementAt(int index),getSize()是AbstractListModel
的方法,public void setSelectedItem(Object item),public Object getSelectedItem()是接ComboBoxModel
的方法*/
import java.awt.*;
import java.awt.event.*;
import java.lang.*;
import javax.swing.*;
public class JComboBoxModelTest extends JFrame{
JComboBox jc=new JComboBox(new MyComboBox());
JLabel jl=new JLabel("请选择证件");
public JComboBoxModelTest(){
setTitle("在窗体中设置下拉菜单");
setSize(200,150);
setVisible(true);
setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE);
Container container=getContentPane();
container.setLayout(new FlowLayout());
container.add(jl);
container.add(jc);
}
public static void main(String[] args) {
// TODO Auto-generated method stub
new JComboBoxModelTest();
}
}
class MyComboBox extends AbstractListModel implements ComboBoxModel{
String selecteditem=null;
String[] test={"军人证","身份证","学生证","工作证"};
public Object getElementAt(int index){
return test[index];
}
public int getSize(){
return test.length;
}
public void setSelectedItem(Object item){
selecteditem=(String)item;
}
public Object getSelectedItem(){
return selecteditem;
}
}
第8行那个JComboBox jc=new JComboBox(new MyComboBox());里的new MyComboBox()是怎么调用的
在在那个MyComboBox类里里并没有定义无参的构造函数MyComboBox(),调用new MyComboBox()时,会调用MyComboBox类里的成员方法吗,/*MyComboBox类里的getElementAt(int index),getSize()是AbstractListModel
的方法,public void setSelectedItem(Object item),public Object getSelectedItem()是接ComboBoxModel
的方法*/