帮忙看一下我的JAVA程序哪里错了?问题在图片地址附近 15
importjava.awt.*;importjava.net.URL;importjavax.swing.*;publicclassJButtonTestextends...
import java.awt.*;
import java.net.URL;
import javax.swing.*;
public class JButtonTest extends JFrame{
public JButtonTest()
{
URL url=JButtonTest.class.getResource("D:\\我的资料\\截图\\QQ图片20140815122647.jpg");
Icon icon=new ImageIcon(url);
setLayout(new GridLayout(3,2,5,5));
Container c=getContentPane();
for(int i=1;i<=5;i++)
{
JButton J=new JButton("button"+i,icon);
c.add(J);
if(i%2==0)
{
J.setEnabled(false);
}
}
JButton jb=new JButton();
jb.setMaximumSize(new Dimension(90,30));
jb.setIcon(icon);
jb.setHideActionText(true);
jb.setToolTipText("picture buttom");
jb.setBorderPainted(false);
c.add(jb);
setTitle("a buttom with pic");
setSize(350,150);
setVisible(true);
setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE);
}
public static void main(String args[]) {
new JButtonTest();
}
} 展开
import java.net.URL;
import javax.swing.*;
public class JButtonTest extends JFrame{
public JButtonTest()
{
URL url=JButtonTest.class.getResource("D:\\我的资料\\截图\\QQ图片20140815122647.jpg");
Icon icon=new ImageIcon(url);
setLayout(new GridLayout(3,2,5,5));
Container c=getContentPane();
for(int i=1;i<=5;i++)
{
JButton J=new JButton("button"+i,icon);
c.add(J);
if(i%2==0)
{
J.setEnabled(false);
}
}
JButton jb=new JButton();
jb.setMaximumSize(new Dimension(90,30));
jb.setIcon(icon);
jb.setHideActionText(true);
jb.setToolTipText("picture buttom");
jb.setBorderPainted(false);
c.add(jb);
setTitle("a buttom with pic");
setSize(350,150);
setVisible(true);
setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE);
}
public static void main(String args[]) {
new JButtonTest();
}
} 展开
2个回答
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询