📄 frame1.java
字号:
package choicetest;
import java.awt.*;
import javax.swing.*;
import java.awt.event.ItemEvent;
import java.awt.event.ItemListener;
import com.borland.jbcl.layout.OverlayLayout2;
public class Frame1
extends JFrame {
JPanel contentPane;
FlowLayout flowLayout1 = new FlowLayout();
Label label1 = new Label();
Choice choice1 = new Choice();
Label label2 = new Label();
OverlayLayout2 overlayLayout21 = new OverlayLayout2();
public Frame1() {
try {
setDefaultCloseOperation(EXIT_ON_CLOSE);
jbInit();
}
catch (Exception exception) {
exception.printStackTrace();
}
}
/**
* Component initialization.
*
* @throws java.lang.Exception
*/
private void jbInit() throws Exception {
contentPane = (JPanel) getContentPane();
contentPane.setLayout(flowLayout1);
setSize(new Dimension(200, 70));
setTitle("选择性别");
label1.setText("性别:");
label2.setText("您的性别是:男");
choice1.addItemListener(new Frame1_choice1_itemAdapter(this));
contentPane.add(label1);
contentPane.add(choice1);
contentPane.add(label2);
choice1.add("男"); //或: choice1.addItem("男");
choice1.add("女"); //或: choice1.addItem("女");
}
public void choice1_itemStateChanged(ItemEvent e) {
label2.setText("您的性别是:"+choice1.getSelectedItem());
// label2.setText("共有"+choice1.getItemCount()+"项");
}
}
class Frame1_choice1_itemAdapter
implements ItemListener {
private Frame1 adaptee;
Frame1_choice1_itemAdapter(Frame1 adaptee) {
this.adaptee = adaptee;
}
public void itemStateChanged(ItemEvent e) {
adaptee.choice1_itemStateChanged(e);
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -