当前位置: 技术问答>java相关
为什么我的ImageIcon不好使?
来源: 互联网 发布时间:2015-04-06
本文导语: 为什么只看见按钮看不见图片,请各位大虾指点一下。源代码如下: import java.awt.*; import java.awt.event.*; import javax.swing.*; public class ButtonImageTest extends JPanel{ static JFrame myFrame; public ButtonImageTest(){ ...
为什么只看见按钮看不见图片,请各位大虾指点一下。源代码如下:
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
public class ButtonImageTest extends JPanel{
static JFrame myFrame;
public ButtonImageTest(){
JButton b;
Icon icon = new ImageIcon("dell.gif");
b = new JButton("A Java Button!", icon);
add(b);
}
public static void main(String[] args) {
myFrame = new JFrame("ButtonImageTest");
ButtonImageTest jt = new ButtonImageTest();
myFrame.getContentPane().add("Center",jt);
myFrame.setSize(400,250);
myFrame.addWindowListener(new WindowAdapter(){
public void windowClosing(WindowEvent e) {
System.exit(0);
}
});
myFrame.setVisible(true);
}
}
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
public class ButtonImageTest extends JPanel{
static JFrame myFrame;
public ButtonImageTest(){
JButton b;
Icon icon = new ImageIcon("dell.gif");
b = new JButton("A Java Button!", icon);
add(b);
}
public static void main(String[] args) {
myFrame = new JFrame("ButtonImageTest");
ButtonImageTest jt = new ButtonImageTest();
myFrame.getContentPane().add("Center",jt);
myFrame.setSize(400,250);
myFrame.addWindowListener(new WindowAdapter(){
public void windowClosing(WindowEvent e) {
System.exit(0);
}
});
myFrame.setVisible(true);
}
}
|
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
public class ButtonImageTest extends JPanel{
static JFrame myFrame;
public ButtonImageTest(){
JButton b;
Icon icon = new ImageIcon("dell.gif");
b = new JButton("A Java Button!", icon);
add(b);
}
}
//////////另建一个文件
public class B extends Frame{
public b()
{
ButtonImageTest jt = new ButtonImageTest();
add(jt);
setSize(400,250);
addWindowListener(new WindowAdapter(){
public void windowClosing(WindowEvent e) {
System.exit(0);
}
});
setVisible(true);
}
public static void main(String[] args)
{
myFrame = new JFrame();
}
}
import java.awt.event.*;
import javax.swing.*;
public class ButtonImageTest extends JPanel{
static JFrame myFrame;
public ButtonImageTest(){
JButton b;
Icon icon = new ImageIcon("dell.gif");
b = new JButton("A Java Button!", icon);
add(b);
}
}
//////////另建一个文件
public class B extends Frame{
public b()
{
ButtonImageTest jt = new ButtonImageTest();
add(jt);
setSize(400,250);
addWindowListener(new WindowAdapter(){
public void windowClosing(WindowEvent e) {
System.exit(0);
}
});
setVisible(true);
}
public static void main(String[] args)
{
myFrame = new JFrame();
}
}
|
ImageIcon icon = new ImageIcon("dell.gif");
您可能感兴趣的文章:
本站(WWW.)旨在分享和传播互联网科技相关的资讯和技术,将尽最大努力为读者提供更好的信息聚合和浏览方式。
本站(WWW.)站内文章除注明原创外,均为转载、整理或搜集自网络。欢迎任何形式的转载,转载请注明出处。
本站(WWW.)站内文章除注明原创外,均为转载、整理或搜集自网络。欢迎任何形式的转载,转载请注明出处。