想要MyEclipse中的swing中实现下拉框和文本框实现,对下拉框创建MouseEvent、ItemEvent、ActionEvent
private void xingbieMouseClicked(java.awt.event.MouseEvent evt) {
// TODO add your handling code here:
setSelectedItem(evt, this.xingbie1);
}
private void xingbieItemStateChanged(java.awt.event.ItemEvent evt) {
// TODO add your handling code here:
setSelectedItem(evt, this.xingbie1);
}
private void setsex1(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
setSelectedItem(evt, this.xingbie1);
}
public static void setSelectedItem(AWTEvent e, JTextField ipTextField) {
JComboBox target = (JComboBox) e.getSource();
String selectedPort = (String) target.getSelectedItem();
ipTextField.setText(selectedPort);
}
更多文章请关注以下公众号