Simple question here I basically want to display an image within the frame from the click of a button. My problem is getting that image to display. Here is the code Thanks...
Code:
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
public class MyImage extends JFrame
{
private JButton open;
private JPanel mainPanel;
public MyImage()
{
setTitle("Open Image");
setLocationRelativeTo(null);
setDefaultCloseOperation(EXIT_ON_CLOSE);
setVisible(true);
setSize(700,700);
open = new JButton("open");
open.addActionListener(new ActionListener()
{
public void actionPerformed(ActionEvent e)
{
ImageIcon zz = new ImageIcon("barkley.jpg");
//mainPanel.add(zz);
setVisible(true);
pack();
}
});
mainPanel = new JPanel();
getContentPane().add(mainPanel);
mainPanel.setLayout(null);
mainPanel.add(open);
mainPanel.add(zz);
open.setBounds(0,0,100,100);
}
public static void main(String[] args)
{
MyImage mi = new MyImage();
}
}