62,623
社区成员
发帖
与我相关
我的任务
分享
package main;
import java.awt.Dimension;
import javax.swing.DefaultComboBoxModel;
import javax.swing.JComboBox;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.WindowConstants;
public class Demo extends JFrame {
public Demo() {
super("图片显示");
ImagePanel p = new ImagePanel();
this.getContentPane().add(p);
this.setSize(new Dimension(500,500));
this.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
this.setVisible(true);
}
class ImagePanel extends JPanel {
public ImagePanel() {
super();
initComponent();
}
private void initComponent() {
this.setLayout(null);
this.setPreferredSize(new Dimension(400, 500));
// ****************************************************************
JComboBox comBox4 = new JComboBox();
Object[] items4 = new Object[] {
new javax.swing.ImageIcon("images/01.jpg"),
new javax.swing.ImageIcon("images/02.jpg"),
new javax.swing.ImageIcon("images/03.jpg"),
new javax.swing.ImageIcon("images/04.jpg"),
new javax.swing.ImageIcon("images/05.jpg"),
new javax.swing.ImageIcon("images/06.jpg"),
new javax.swing.ImageIcon("images/07.jpg"),
new javax.swing.ImageIcon("images/08.jpg"),
new javax.swing.ImageIcon("images/09.jpg"),
new javax.swing.ImageIcon("images/10.jpg"),
new javax.swing.ImageIcon("images/11.jpg") };
DefaultComboBoxModel comBoxModel4 = new DefaultComboBoxModel(items4);
comBox4.setModel(comBoxModel4);
JLabel label4 = new JLabel("选择图片");
label4.setBounds(20, 170, 100, 30);
comBox4.setBounds(130, 170, 150, 100);
this.add(label4);
this.add(comBox4);
}
}
public static void main(String args[]) {
Demo d = new Demo();
}
}