java程序设计题,编写一个Application程序的GUI
Java程序:
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
public class Test35 extends JFrame implements ItemListener{
private static final long serialVersionUID = 1L;
JComboBox cmbGender;
JLabel lblMessage;
public 闷埋Test35(){
super("工业09");
String[] arr = new String[]{"男", "女"};
cmbGender = new JComboBox(arr);
lblMessage = new JLabel("请选择你的性别");
this.setLayout(new FlowLayout());
this.add(lblMessage);
this.add(cmbGender);
cmbGender.addItemListener(this);
this.setSize(200, 100);
this.setVisible(true);
this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
}
public static void main(String[] args) {
new Test35();
}
@Override
public void itemStateChanged(ItemEvent e) {
JComboBox cmb = (JComboBox)e.getSource();
if(cmb == cmbGender){
lblMessage.setText(cmb.getSelectedItem().toString());
}
}
}
运行清族测试答罩弊: