choiceoptionexample.java
来自「samplecode 111 for J2SE project」· Java 代码 · 共 54 行
JAVA
54 行
package soe;import java.awt.Choice;import java.awt.FlowLayout;import java.awt.Frame;import java.awt.Label;import java.awt.List;import java.awt.event.WindowAdapter;import java.awt.event.WindowEvent;public class ChoiceOptionExample { /** * @param args */ public static void main(String[] args) { Frame frame=new Frame("Choice"); Label label=new Label("What is your Choice:"); Choice choice=new Choice(); frame.add(label); frame.add(choice); choice.add("ROSE"); choice.add("JASMIN"); choice.add("RHODODENDRONS"); List lst=new List(4,true); lst.add("Java Programming"); lst.add("Network Security"); lst.add("Database Design"); lst.add("Advanced Java"); frame.add(lst); int a=choice.getSelectedIndex(); System.out.println("Selected index :" + a); int a1=choice.getItemCount(); System.out.println("Number of Items :" + a1); // String a2=choice.getSelectedItem(); System.out.println("Selected Item :"+choice.getSelectedItem() ); frame.setLayout(new FlowLayout()); frame.setSize(250,150); frame.setVisible(true); frame.addWindowListener(new WindowAdapter(){ public void windowClosing(WindowEvent e){ System.exit(0);} }); } }
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?