import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
public class ghj extends JFrame{
public ghj(){
JFrame frame=new JFrame("my frame");
Container contentPane=frame.getContentPane();
contentPane.setLayout(new FlowLayout());
ImageIcon icon=createImageIcon("1.gif","ll");
JLabel label=new JLabel("fd",icon,JLabel.CENTER);
JButton button=new JButton("button",buttonicon);
contentPane.add(label,FlowLayout.CENTER);
frame.setSize(100,100);
frame.pack();
frame.setVisible(true);
}
protected static ImageIcon createImageIcon(String path,String description)
{
java.net.URL imgurl=ghj.class,getResource(path);//出问题了,是jfc swing上的例子,请教
if(imgurl!=null)
{return new ImageIcon(imgurl,description);}
else
{
System.err.println("dfdf"+path);
return null;
}
}
public static void main(String[] args){
javax.swing.SwingUtilities.invokeLater(new Runnable(){
public void run()
{new ghj();}
});
}
}
import java.awt.event.*;
import javax.swing.*;
public class ghj extends JFrame{
public ghj(){
JFrame frame=new JFrame("my frame");
Container contentPane=frame.getContentPane();
contentPane.setLayout(new FlowLayout());
ImageIcon icon=createImageIcon("1.gif","ll");
JLabel label=new JLabel("fd",icon,JLabel.CENTER);
JButton button=new JButton("button",buttonicon);
contentPane.add(label,FlowLayout.CENTER);
frame.setSize(100,100);
frame.pack();
frame.setVisible(true);
}
protected static ImageIcon createImageIcon(String path,String description)
{
java.net.URL imgurl=ghj.class,getResource(path);//出问题了,是jfc swing上的例子,请教
if(imgurl!=null)
{return new ImageIcon(imgurl,description);}
else
{
System.err.println("dfdf"+path);
return null;
}
}
public static void main(String[] args){
javax.swing.SwingUtilities.invokeLater(new Runnable(){
public void run()
{new ghj();}
});
}
}
--------------------Configuration: pk - JDK version 1.4 <Default> - <Default>--------------------
d:\Program Files\Xinox Software\JCreatorV3\MyProjects\pk\ghj.java:22: ';' expected
java.net.URL imgurl=ghj.class,getResource(path);
^
d:\Program Files\Xinox Software\JCreatorV3\MyProjects\pk\ghj.java:22: incompatible types
found : java.lang.Class
required: java.net.URL
java.net.URL imgurl=ghj.class,getResource(path);
^
2 errorsProcess completed.
另外 buttonicon 这个变量也没有定义
改为:
java.net.URL imgurl=ghj.class.getResource(path);