下來框+列表框-2022-12-12
阿新 • • 發佈:2022-12-12
下拉框
package Lesson06;
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.setBounds(100,100,500,350);
this.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
}
public static void main(String[] args) {
new TestComboboxDemo01();
}
}
列表框
package Lesson06;
import javax.swing.*;
import java.awt.*;
import java.util.Vector;
public class TestComboboxDemo02 extends JFrame {
public TestComboboxDemo02(){
Container container = this.getContentPane();
//生成列表的內容,靜態的資料
//String[] contents = {"1","2","3"};
//動態資料
Vector contents = new Vector();
//列表中需要放入內容
JList jList = new JList(contents);
contents.add("zhangsn");
contents.add("lis");
contents.add("wangwu");
container.add(jList);
this.setVisible(true);
this.setBounds(100,100,500,350);
this.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
}
public static void main(String[] args) {
new TestComboboxDemo02();
}
}