Advertisement
sav_smolensk

Untitled

Jan 20th, 2019
85
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 2.24 KB | None | 0 0
  1. package ep;
  2.  
  3. import javax.imageio.ImageIO;
  4. import javax.swing.*;
  5. import java.awt.*;
  6. import java.io.IOException;
  7.  
  8. public class Panel extends JComponent {
  9.  
  10.     private static String path;
  11.     private static Panel object;
  12.     private static int slide = 0;
  13.  
  14.     private Panel(String path) {
  15.  
  16.         super();
  17.         setPath(path);
  18.         setLayout(null);
  19.  
  20.     }
  21.  
  22.     public static Panel getPanel(String path) {
  23.  
  24.         if(object == null) object = new Panel(path);
  25.         return object;
  26.  
  27.     }
  28.  
  29.     public void setNavigationButtons() {
  30.  
  31.         Button prevButton = new Button("Пред. Слайд", 5, 630, Listener.PREV_SLIDE);
  32.         prevButton.setPreferredSize(new Dimension(200, 100));
  33.         prevButton.setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR));
  34.         prevButton.addMouseListener(Listener.getListener());
  35.  
  36.         Button nextButton = new Button("След. Слайд", 715, 630, Listener.NEXT_SLIDE);
  37.         nextButton.setPreferredSize(new Dimension(200, 100));
  38.         nextButton.setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR));
  39.         nextButton.addMouseListener(Listener.getListener());
  40.  
  41.         add(prevButton);
  42.         add(nextButton);
  43.         repaint();
  44.  
  45.     }
  46.  
  47.     public void paintComponent(Graphics g){
  48.  
  49.         super.paintComponent(g);
  50.         Graphics2D g2 = (Graphics2D) g;
  51.         Image im = null;
  52.         Image imScaled = im;
  53.         try {
  54. //            System.out.println(path);
  55.             im = ImageIO.read(getClass().getResource(path));
  56.         } catch (IOException e) {
  57.             System.out.println(e);
  58.         }
  59.         try {
  60.             imScaled = im.getScaledInstance(900,600, Image.SCALE_SMOOTH);
  61.         }
  62.         catch(Exception ex) {
  63.             System.out.println(ex);
  64.         }
  65.         g2.drawImage(imScaled, 10, 10, null);
  66.     }
  67.  
  68.     public void setPath(String path) {
  69.  
  70.         this.path = path;
  71.         repaint();
  72.  
  73.     }
  74.  
  75.     public String getPath() {
  76.         return path;
  77.     }
  78.  
  79.     public int getSlide() {
  80.         return slide;
  81.     }
  82.  
  83.     public void slideIncrement() {
  84.         slide++;
  85.     }
  86.  
  87.     public void slideDecrement() {
  88.         slide--;
  89.     }
  90.  
  91.     public void setSlide(int slide) {
  92.         this.slide = slide;
  93.     }
  94.  
  95. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement