importjava.awt.*;importjavax.swing.*;//为什么不能导入图像publicclassLabelDemo{publicstaticvoidmain(String[]args){ImageIconicon=newImageIcon("080221025482169.gif");JFramef...
import java.awt.*;
import javax.swing.*;
//为什么不能导入图像
public class LabelDemo
{
public static void main (String [] args)
{
ImageIcon icon=new ImageIcon ("080221025482169.gif");
JFrame frame=new JFrame ("LabelDemo");
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
JLabel label1,label2,label3;
label1=new JLabel ("left",icon,SwingConstants.CENTER);
label2=new JLabel ("right",icon,SwingConstants.CENTER);
label2.setHorizontalTextPosition(SwingConstants.LEFT);
label2.setVerticalTextPosition(SwingConstants.BOTTOM);
label3=new JLabel ("above",icon,SwingConstants.CENTER);
label3.setHorizontalTextPosition(SwingConstants.CENTER);
label3.setVerticalTextPosition(SwingConstants.BOTTOM);
JPanel panel=new JPanel();
panel.setBackground(Color.cyan);
panel.setPreferredSize(new Dimension(200,250));
panel.add(label1);
panel.add(label2);
panel.add(label3);
frame.getContentPane().add(panel);
frame.pack();
frame.setVisible(true);
}
}
展开