下拉框
package lesson9;
import javax. swing. * ;
import java. awt. * ;
public class TestComboboxDemo01 extends JFrame {
public TestComboboxDemo01 ( ) {
Container container = this . getContentPane ( ) ;
JComboBox status = new JComboBox ( ) ;
status. addItem ( null) ;
status. addItem ( "正在上映" ) ;
status. addItem ( "已下架" ) ;
status. addItem ( "即将上映" ) ;
container. add ( status) ;
this . setVisible ( true ) ;
this . setSize ( 500 , 300 ) ;
this . setDefaultCloseOperation ( WindowConstants. EXIT_ON_CLOSE) ;
}
public static void main ( String[ ] args) {
new TestComboboxDemo01 ( ) ;
}
}
列表框
package lesson9;
import javax. swing. * ;
import java. awt. * ;
public class TestComboboxDemo02 extends JFrame {
public TestComboboxDemo02 ( ) {
Container container = this. getContentPane ( ) ;
String[ ] contents = { "1" , "2" , "3" } ;
JList jList = new JList ( contents) ;
container. add ( jList) ;
this. setVisible ( true) ;
this. setSize ( 500 , 300 ) ;
this. setDefaultCloseOperation ( WindowConstants. EXIT_ON_CLOSE) ;
}
public static void main ( String[ ] args) {
new TestComboboxDemo02 ( ) ;
}
}