请高手帮忙解答一个Java问题
我想知道那个这段复选框程序中,最后那一句return0是什么意思?我好像把它改成别的数字都没有什么影响啊?请高手答疑importjava.awt.Container;im...
我想知道那个这段复选框程序中,最后那一句return 0是什么意思?我好像把它改成别的数字都没有什么影响啊?请高手答疑
import java.awt.Container;
import java.awt.Dimension;
import java.awt.FlowLayout;
import javax.swing.AbstractListModel;
import javax.swing.ComboBoxModel;
import javax.swing.JComboBox;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.WindowConstants;
public class SelectID extends JFrame {
public static void main(String[] args) {
new SelectID();
}
JComboBox x = new JComboBox(new MyComeboBox());
JLabel t = new JLabel("please choice");
public SelectID() {
setTitle("CHOICE");
setSize(new Dimension(300, 280));
setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
setVisible(true);
Container a = getContentPane();
setLayout(new FlowLayout());
a.add(t);
a.add(x);
}
}
class MyComeboBox extends AbstractListModel implements ComboBoxModel {
String aa = null;
String[] liste = { "A", "B", "C", "D" };
public Object getElementAt(int index) {
return liste[index];
}
public int getSize() {
return liste.length;
}
public Object getSelectedItem() {
return aa;
}
@Override
public void setSelectedItem(Object anItem) {
aa = (String) anItem;
}
public int getindex() {
for (int i = 0; i < liste.length; i++) {
if (liste[i].equals(getSelectedItem())) {
return i;
}
break;
}
return 0;
}
} 展开
import java.awt.Container;
import java.awt.Dimension;
import java.awt.FlowLayout;
import javax.swing.AbstractListModel;
import javax.swing.ComboBoxModel;
import javax.swing.JComboBox;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.WindowConstants;
public class SelectID extends JFrame {
public static void main(String[] args) {
new SelectID();
}
JComboBox x = new JComboBox(new MyComeboBox());
JLabel t = new JLabel("please choice");
public SelectID() {
setTitle("CHOICE");
setSize(new Dimension(300, 280));
setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
setVisible(true);
Container a = getContentPane();
setLayout(new FlowLayout());
a.add(t);
a.add(x);
}
}
class MyComeboBox extends AbstractListModel implements ComboBoxModel {
String aa = null;
String[] liste = { "A", "B", "C", "D" };
public Object getElementAt(int index) {
return liste[index];
}
public int getSize() {
return liste.length;
}
public Object getSelectedItem() {
return aa;
}
@Override
public void setSelectedItem(Object anItem) {
aa = (String) anItem;
}
public int getindex() {
for (int i = 0; i < liste.length; i++) {
if (liste[i].equals(getSelectedItem())) {
return i;
}
break;
}
return 0;
}
} 展开
2个回答
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询