想实现窗口中显示图片和文字,但是总是找不到图片,不知道应该怎样写才能找到图片,程序如下
import javax.swing.JFrame;
import javax.swing.JLabel;
public class Myfirstframe extends JFrame
{
public static void main(String [] args)
{
Myfirstframe frame=new Myfirstframe();
frame.setVisible(true);
}
public Myfirstframe()
{
super();
setTitle("setJFrame");
setBounds(100,100,500,375);
getContentPane().setLayout(null);
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
final JLabel label=new JLabel();
label.setBounds(0,0,492,341);
label.setText("welcome to swing");
label.setHorizontalAlignment(JLabel.CENTER);
label.setIcon(new ImageIcon("/img/left.JPG"));
label.setHorizontalTextPosition(JLabel.CENTER);
label.setVerticalTextPosition(JLabel.BOTTOM);
getContentPane().add(label);
}
}
求大神指点
import javax.swing.JFrame;
import javax.swing.JLabel;
public class Myfirstframe extends JFrame
{
public static void main(String [] args)
{
Myfirstframe frame=new Myfirstframe();
frame.setVisible(true);
}
public Myfirstframe()
{
super();
setTitle("setJFrame");
setBounds(100,100,500,375);
getContentPane().setLayout(null);
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
final JLabel label=new JLabel();
label.setBounds(0,0,492,341);
label.setText("welcome to swing");
label.setHorizontalAlignment(JLabel.CENTER);
label.setIcon(new ImageIcon("/img/left.JPG"));
label.setHorizontalTextPosition(JLabel.CENTER);
label.setVerticalTextPosition(JLabel.BOTTOM);
getContentPane().add(label);
}
}
求大神指点