将不同的图片添加到不同的帧

时间:2016-09-30 16:17:45

标签: java jframe jlabel

需要帮助添加图片而不是文字。我现在有一点问题了。谢谢

import javax.swing.*;
public class LabelFrame extends JFrame {
private String text;
private JLabel label;
private int alignment;
public LabelFrame(String text, int alignment) {
super(text);
label = new JLabel(text, alignment);
getContentPane().add(label);
setDefaultCloseOperation(javax.swing.JFrame.EXIT_ON_CLOSE);
}

public static void main(String[] args) {
    LabelFrame f1 = new LabelFrame("Left", JLabel.LEFT);
// setLocation(x,y) is the set location of the frame, the upper left 
// corner will be at (x,y)
f1.setLocation(100,100);
f1.setSize(100,100);
f1.setVisible(true);
LabelFrame f2 = new LabelFrame("Center", JLabel.CENTER);
f2.setLocation(200,100);
f2.setSize(100,100);
f2.setVisible(true);
LabelFrame f3 = new LabelFrame("Right", JLabel.RIGHT);
f3.setLocation(300,100);
f3.setSize(100,100);
f3.setVisible(true);
}
}

0 个答案:

没有答案