下来框+列表框-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();
}
}
posted @ 2022-12-12 15:59  Rui2022  阅读(5)  评论(0编辑  收藏  举报