G2A Many GEOs
SHARE
TWEET

oop_lab_7

darkor Apr 6th, 2020 (edited) 190 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. import javax.imageio.ImageIO;
  2. import javax.swing.*;
  3. import java.awt.*;
  4. import java.awt.event.MouseAdapter;
  5. import java.awt.event.MouseEvent;
  6. import java.awt.image.BufferedImage;
  7. import java.io.File;
  8. import java.io.IOException;
  9.  
  10. public class qqq extends JFrame {
  11.     static JFrame jFrame = getFrame();
  12.     static JPanel jPanel = new JPanel();
  13.  
  14.     public static void main(String[] args) throws IOException {
  15.         jFrame.add(jPanel);
  16.         BufferedImage myPicture_1 = ImageIO.read(new File("D:\\new\\1.png"));       // ввести шлях до зображення 1
  17.         BufferedImage myPicture_2 = ImageIO.read(new File("D:\\new\\2.jpg"));       // ввести шлях до зображення 2
  18.         JLabel picLabel = new JLabel(new ImageIcon(myPicture_1));
  19.         final boolean[] counter = {true};
  20.         picLabel.addMouseListener(new MouseAdapter()
  21.         {
  22.             public void mouseClicked(MouseEvent e)
  23.             {
  24.                 if (counter[0]) {
  25.                     picLabel.setIcon(new ImageIcon(myPicture_2));
  26.                     counter[0] = false;
  27.                 }
  28.                 else {
  29.                     picLabel.setIcon(new ImageIcon(myPicture_1));
  30.                     counter[0] = true;
  31.                 }
  32.             }
  33.         });
  34.         jPanel.add(picLabel);
  35.         jPanel.revalidate();
  36.     }
  37.  
  38.     static JFrame getFrame() {
  39.         JFrame jFrame = new JFrame() {};
  40.         jFrame.setVisible(true);
  41.         jFrame.setResizable(false);
  42.         Toolkit toolkit = Toolkit.getDefaultToolkit();
  43.         Dimension dimension = toolkit.getScreenSize();
  44.         jFrame.setBounds(dimension.width/2 - 300, dimension.height/2 - 200, 600, 400);
  45.         jFrame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
  46.         return jFrame;
  47.     }
  48. }
RAW Paste Data
Ledger Nano X - The secure hardware wallet
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
Top