JPanel多个背景图显示

来源:百度知道 编辑:UC知道 时间:2024/06/25 10:15:55
程序如下,为一个万年历的一个文件,通过JLABLE能添加一个背景图,但我想通过改变月份来改变背景图,(通过在下拉列表中的事件中,我image改了显示的图,但jlabel没有反应)实现不了,请高手指教啊。
public class MainFrame extends JFrame {

JPanel panel = new JPanel(new BorderLayout());
JPanel panel1 = new JPanel();
JPanel panel2 = new JPanel(new GridLayout(7, 7));
JPanel panel3 = new JPanel();
JLabel[] label = new JLabel[49];
JLabel y_label = new JLabel("年份");
JLabel m_label = new JLabel("月份");
JComboBox com1 = new JComboBox();
JComboBox com2 = new JComboBox();
ImageIcon image;
JLabel lab;
int re_year, re_month;
int x_size, y_size;
String year_num;
Integer month[] = new Integer[12];
Calendar now = Calendar.getInstance(); // 实例化Calendar
public SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy年MM月dd日");

MainFrame() {

super("万年历");
setSize(300, 350);
x_size = (int) (Toolkit.getDefaultToolkit

public class LabelTest {

public static void main(String[] args) {
JFrame frame = new JFrame();
final Color[] colors = new Color[]{Color.RED, Color.GREEN};
JComboBox comboBox = new javax.swing.JComboBox();
final JLabel label = new JLabel(" ");
comboBox.setModel(new javax.swing.DefaultComboBoxModel(new String[]{"2009.01.01", "2009.01.02"}));
frame.getContentPane().add(comboBox, BorderLayout.NORTH);
frame.getContentPane().add(label, BorderLayout.CENTER);
frame.setDefaultCloseOperation(3);
comboBox.addItemListener(new ItemListener() {

public void itemStateChanged(ItemEvent e) {
label.setIcon(createIcon(colors[(int) (Math.random() * 2)]));
}
});
frame.setVisible(true);
}

static Icon createIcon(Color color) {