java多选_java中怎么编写多项选择题代码展开全部
import java.awt.Checkbox;
import java.awt.CheckboxGroup;
import java.awt.Choice;
import java.awt.FlowLayout;
import java.awt.Label;
import java.awt.TextField;
import java.awt.event.ItemEvent;
import java.awt.event.ItemListener;
import javax.swing.JFrame;
public class Choose extends JFrame implements ItemListener {
/
**
*
*/
private static final long serialVersionUID = 1L;
Label l1, l2;
TextField t1, t2;
CheckboxGroup checkboxGroup = new CheckboxGroup();
Checkbox checkbox1 = new Checkbox("QQ", checkboxGroup, false);
Checkbox checkbox2 = new Checkbox("MSN", checkboxGroup, false);
Checkbox checkbox3 = new Checkbox("ICQ", checkboxGroup, false);
Choice c;
public Choose() {
super("简单⼩程62616964757a686964616fe78988e69d8331333337386631序");
this.setLayout(new FlowLayout());
l1 = new Label("选择你常⽤的软件:");
java怎么编写l2 = new Label("选择你喜欢的⽔果:");
checkbox1.addItemListener(this);
checkbox2.addItemListener(this);
checkbox3.addItemListener(this);
t1 = new TextField(20);
t2 = new TextField(20);
c = new Choice();
c.addItemListener(this);
c.add("苹果");
c.add("橘⼦");
c.add("⾹蕉");
c.add("梨⼦");
this.add(l1);
this.add(checkbox1);
this.add(checkbox2);
this.add(checkbox3);
this.add(t1);
this.add(l2);
this.add(c);
this.add(t2);
this.setSize(450, 200);
this.setVisible(true);
}
public static void main(String[] args) {
new Choose();
}
public void itemStateChanged(ItemEvent e) {
if (e.getSource() == checkbox1) {
t1.setText("你常⽤的软件是:" + Label());
}
if (e.getSource() == checkbox2) {
t1.setText("你常⽤的软件是:" + Label());
}
if (e.getSource() == checkbox3) {
t1.setText("你常⽤的软件是:" + Label());
}
t2.setText("你喜欢的⽔果是:" + c.getSelectedItem());// 得到选中的下拉列表值}
}
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系QQ:729038198,我们将在24小时内删除。
发表评论