import java.awt.*;
import javax.swing.*;public class JLabelDemo extends JFrame{
public JLabelDemo() {
super("LabelDemo");
Container container = getContentPane();
container.setLayout(new FlowLayout());
JLabel label1 =new JLabel("This is a Label with only text");
container.add(label1);
Icon icon =new ImageIcon("Sunset.jpg");
JLabel label2 = new JLabel(icon);
container.add(label2);
setSize(500,500);
setVisible(true);
}
/**
* @param args
*/
public static void main(String[] args) {
// TODO 自動生成されたメソッド・スタブ
JLabelDemo ld= new JLabelDemo();
ld.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
}}
我加载了一个ICON,Sunset.jpg应该存放在什么路径才能正确显示,谢谢各位了
import javax.swing.*;public class JLabelDemo extends JFrame{
public JLabelDemo() {
super("LabelDemo");
Container container = getContentPane();
container.setLayout(new FlowLayout());
JLabel label1 =new JLabel("This is a Label with only text");
container.add(label1);
Icon icon =new ImageIcon("Sunset.jpg");
JLabel label2 = new JLabel(icon);
container.add(label2);
setSize(500,500);
setVisible(true);
}
/**
* @param args
*/
public static void main(String[] args) {
// TODO 自動生成されたメソッド・スタブ
JLabelDemo ld= new JLabelDemo();
ld.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
}}
我加载了一个ICON,Sunset.jpg应该存放在什么路径才能正确显示,谢谢各位了
当前目录