Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.awt.event.ActionEvent;
- import java.awt.event.ActionListener;
- import javax.swing.*;
- public class DelayGUI extends JFrame
- {
- private JPanel panel;
- private JLabel lblPic;
- private JButton btnClick;
- private ImageIcon img1, img2;
- public DelayGUI()
- {
- super("Delay Test");
- img1 = new ImageIcon("back.png");
- img2 = new ImageIcon("leia.png");
- panel = new JPanel();
- lblPic = new JLabel(img1);
- btnClick = new JButton(img1);
- //panel.add(lblPic);
- panel.add(btnClick);
- btnClick.addActionListener(new ButtonHandler());
- add(panel);
- }
- private class ButtonHandler implements ActionListener
- {
- @Override
- public void actionPerformed(ActionEvent e)
- {
- //"show" the image
- btnClick.setIcon(img2);
- //delay
- try {
- Thread.sleep(5000);
- } catch (InterruptedException e1) {
- // TODO Auto-generated catch block
- e1.printStackTrace();
- }
- // now change pic back
- //btnClick.setIcon(img1);
- }
- }
- public static void main(String[] args)
- {
- // create object
- DelayGUI frame = new DelayGUI();
- frame.setSize(300, 300);
- frame.setVisible(true);
- frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement