一、下拉框
package GUI;
import java.awt.*;
import java.awt.event.*;
import java.net.URL;
import javax.swing.*;
public class TestDemo extends JFrame {
public TestDemo(){
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, 500);
this.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
}
public static void main(String[] args) {
new TestDemo();
}
}
二、列表框
package GUI;
import java.awt.*;
import java.awt.event.*;
import java.net.URL;
import java.util.Vector;
import javax.swing.*;
public class TestDemo extends JFrame {
public TestDemo(){
Container container = this.getContentPane();
Vector contents = new Vector();
contents.add("zhangsan");
contents.add("zhangsan1");
contents.add("zhangsan2");
JList jList = new JList(contents);
container.add(jList);
this.setVisible(true);
this.setBounds(100, 100, 500, 500);
this.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
}
public static void main(String[] args) {
new TestDemo();
}
}
三、文本框
package GUI;
import java.awt.*;
import java.awt.event.*;
import java.net.URL;
import java.util.Vector;
import javax.swing.*;
public class TestDemo extends JFrame {
public TestDemo(){
Container container = this.getContentPane();
JTextField textField = new JTextField("hello");
JTextField textField2 = new JTextField("world",20);
container.add(textField2,BorderLayout.NORTH);
container.add(textField,BorderLayout.SOUTH);
this.setVisible(true);
this.setBounds(100, 100, 500, 500);
this.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
}
public static void main(String[] args) {
new TestDemo();
}
}
四、密码框
package GUI;
import java.awt.*;
import java.awt.event.*;
import java.net.URL;
import java.util.Vector;
import javax.swing.*;
public class TestDemo extends JFrame {
public TestDemo(){
Container container = this.getContentPane();
JPasswordField passwordField = new JPasswordField();
passwordField.setEchoChar('*');
container.add(passwordField);
this.setVisible(true);
this.setBounds(100, 100, 500, 500);
this.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
}
public static void main(String[] args) {
new TestDemo();
}
}