swing列表、文本框
3.6列表
-
下拉框
package com.zishi.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.setSize(200,400);
this.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
}
public static void main(String[] args) {
new TestComboboxDemo01();
}
}
-
列表框
package com.zishi.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"};
// JList list = new JList(contents);
//生成列表的内容 动态
Vector contents = new Vector();
JList list = new JList(contents);
contents.add("1");
contents.add("2");
contents.add("3");
container.add(list);
this.setVisible(true);
this.setSize(300,400);
this.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
}
public static void main(String[] args) {
new TestComboboxDemo02();
}
}
3.7 文本框
-
文本框
package com.zishi.lesson06;
import javax.swing.*;
import java.awt.*;
public class TestTextDemo01 extends JFrame {
public TestTextDemo01(){
Container container = this.getContentPane();
JTextField textField = new JTextField("textField",20);
JTextField textField02 = new JTextField("textField2",20);
container.add(textField,BorderLayout.NORTH);
container.add(textField02,BorderLayout.SOUTH);
this.setVisible(true);
this.setSize(300,400);
this.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
}
public static void main(String[] args) {
new TestTextDemo01();
}
}
-
文本域
package com.zishi.lesson06;
import javax.swing.*;
import java.awt.*;
public class TestTextDemo03 extends JFrame {
public TestTextDemo03(){
Container container = this.getContentPane();
JTextArea textArea = new JTextArea();
textArea.setText("一起学JAVA" +
"skaljdlajks" +
"ksjmalkdjkla" +
"asdbagskjaghkjd");
//Scroll滚动面板
JScrollPane scrollPane = new JScrollPane(textArea);
container.add(scrollPane);
this.setVisible(true);
this.setSize(300,400);
this.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
}
public static void main(String[] args) {
new TestTextDemo03();
}
}
-
密码框
package com.zishi.lesson06;
import javax.swing.*;
import java.awt.*;
public class TestTextDemo02 extends JFrame {
public TestTextDemo02(){
Container container = this.getContentPane();
JPasswordField passwordField = new JPasswordField(20);//........默认
passwordField.setEchoChar('*');//********
container.add(passwordField);
this.setVisible(true);
this.setSize(300,400);
this.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
}
public static void main(String[] args) {
new TestTextDemo02();
}
}