import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
public class SwingImage extends JFrame
implements ActionListener
{
JButton b;
JLabel lbl;
public SwingImage()
{
super("Displaying Image in Swing");
b = new JButton("Display");
lbl=new JLabel(new ImageIcon("fish.jpg")) ;
setLayout(new FlowLayout());
b.addActionListener(this);
add(b);
add(lbl,BorderLayout.CENTER);
addWindowListener(new WindowAdapter() {
public void windowClosing(WindowEvent e) {
System.exit(0);
}
});
lbl.setVisible(false);
setSize(300,300);
setVisible(true);
}
public void actionPerformed(ActionEvent e)
{
if (e.getActionCommand().equals("Display"))
{
lbl.setVisible(true);
b.setText("Hide");
} else
{
b.setText("Display");
lbl.setVisible(false);
}
}
public static void main(String[] args) {
SwingImage si = new SwingImage();
}
}
0 comments:
Post a Comment