需要帮助添加图片而不是文字。我现在有一点问题了。谢谢
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);
}
}