我也才学GUI没多久,帮你写了个简单的,不过不知道用什么组件查看图片,暂时用的JLabel。图片放在package下image文件中(image与src文件夹同一级位置)。程序如下:(我用eclipse写的,有用的话一定给分啊,熬夜写的。。)import java.awt.FlowLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.ImageIcon;
import javax.swing.JButton;
import javax.swing.JDialog;
import javax.swing.JFrame;
import javax.swing.JLabel;public class Test extends JFrame implements ActionListener{ JButton button;
public Test(){
setLayout(new FlowLayout());
button=new JButton("打开惊喜吧~~");
button.addActionListener(this);
add(button);
setTitle("surprise");
setVisible(true);
setBounds(150,100,200,100);
setDefaultCloseOperation(EXIT_ON_CLOSE);
}
public class  apple extends JDialog{
JLabel label;
public apple(){
setVisible(true);
setBounds(200,100,150,150);
label=new JLabel();
add(label);
label.setIcon(new ImageIcon("image\\apple.PNG"));
label.setDisabledIcon(new ImageIcon("image\\apple.PNG"));
}
}
@Override
public void actionPerformed(ActionEvent e) {
// TODO Auto-generated method stub
new apple();
}
}第二个类:
public class aaaa { public static void main(String[] args){
new Test();
}}