Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package ep;
- import javax.imageio.ImageIO;
- import javax.swing.*;
- import java.awt.*;
- import java.io.IOException;
- public class Panel extends JComponent {
- private static String path;
- private static Panel object;
- private static int slide = 0;
- private Panel(String path) {
- super();
- setPath(path);
- setLayout(null);
- }
- public static Panel getPanel(String path) {
- if(object == null) object = new Panel(path);
- return object;
- }
- public void setNavigationButtons() {
- Button prevButton = new Button("Пред. Слайд", 5, 630, Listener.PREV_SLIDE);
- prevButton.setPreferredSize(new Dimension(200, 100));
- prevButton.setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR));
- prevButton.addMouseListener(Listener.getListener());
- Button nextButton = new Button("След. Слайд", 715, 630, Listener.NEXT_SLIDE);
- nextButton.setPreferredSize(new Dimension(200, 100));
- nextButton.setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR));
- nextButton.addMouseListener(Listener.getListener());
- add(prevButton);
- add(nextButton);
- repaint();
- }
- public void paintComponent(Graphics g){
- super.paintComponent(g);
- Graphics2D g2 = (Graphics2D) g;
- Image im = null;
- Image imScaled = im;
- try {
- // System.out.println(path);
- im = ImageIO.read(getClass().getResource(path));
- } catch (IOException e) {
- System.out.println(e);
- }
- try {
- imScaled = im.getScaledInstance(900,600, Image.SCALE_SMOOTH);
- }
- catch(Exception ex) {
- System.out.println(ex);
- }
- g2.drawImage(imScaled, 10, 10, null);
- }
- public void setPath(String path) {
- this.path = path;
- repaint();
- }
- public String getPath() {
- return path;
- }
- public int getSlide() {
- return slide;
- }
- public void slideIncrement() {
- slide++;
- }
- public void slideDecrement() {
- slide--;
- }
- public void setSlide(int slide) {
- this.slide = slide;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement