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();}
});
}
}
解决方案 »
- 用java往word插入图片
- 在JPANEL上动态的改变背景,并且能有PPT一样的特效
- 可不可以在一个JFrame中显示两个窗口
- 如何读出TXT文件中某一到题目出来 帮我看下代码哪里出错帮忙修改下
- public的类就可以自动继承一个文件夹下其他的类吗?
- 关于jbuilder8.0的问题,高分求救?
- 各位老大,JB7中,DataSet类型在哪个包中啊?我引用了半天总说不认识的类!
- Oracle排序分页的SQL语句问题
- 请教有关Tomcat的问题
- 请各位高手帮助,在下有礼了 我自已写了一类似于画图板的工具,可以选择颜色,线条的宽度,可是我上面画的时侯没有问题,可是一改变IE的大小,或者有一个新的窗口覆盖在这个应用上面,在关闭覆盖的窗口,我所画的图形都不见了,请各个高手帮忙,谢谢!
- 我用JAR生成了一个jar文件,但是运行起来就出错误,为什么呀???
- 请大家释疑
--------------------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);