JAVA - How To Create A Slideshow In Java Swing Using NetBeans

JAVA - How To Create A Slideshow In Java

__________________________________________________________________________

In this java Tutorial we will see How To Make Slide Show In Java Swing Using NetBeans .



Project Source Code:

package JavaDB_001;
import java.awt.Color;
import java.awt.Image;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.*;


public class Project extends JFrame{
    JLabel pic;
    Timer tm;
    int x = 0;
    //Images Path In Array
    String[] list = {
                      "C:/Users/samsng/Desktop/jv1.png",//0
                      "C:/Users/samsng/Desktop/jv2.jpg",//1
                      "C:/Users/samsng/Desktop/jv3.jpg",//2
                      "C:/Users/samsng/Desktop/jv4.jpg",//3
                      "C:/Users/samsng/Desktop/jv5.png",//4
                      "C:/Users/samsng/Desktop/jv6.jpg",//5
                      "C:/Users/samsng/Desktop/jv7.jpg"//6
                    };
    
    public Project(){
        super("Java SlideShow");
        pic = new JLabel();
        pic.setBounds(40, 30, 700, 300);

        //Call The Function SetImageSize
        SetImageSize(6);
               //set a timer
        tm = new Timer(500,new ActionListener() {

            @Override
            public void actionPerformed(ActionEvent e) {
                SetImageSize(x);
                x += 1;
                if(x >= list.length )
                    x = 0; 
            }
        });
        add(pic);
        tm.start();
        setLayout(null);
        setSize(800, 400);
        getContentPane().setBackground(Color.decode("#bdb67b"));
        setLocationRelativeTo(null);
        setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        setVisible(true);
    }
    //create a function to resize the image 
    public void SetImageSize(int i){
        ImageIcon icon = new ImageIcon(list[i]);
        Image img = icon.getImage();
        Image newImg = img.getScaledInstance(pic.getWidth(), pic.getHeight(), Image.SCALE_SMOOTH);
        ImageIcon newImc = new ImageIcon(newImg);
        pic.setIcon(newImc);
    }

public static void main(String[] args){ 
      
    new Project();
}
}




////////////OUTPUT:




Share this

Related Posts

Previous
Next Post »

12 comments

comments
2 décembre 2015 à 01:29 delete

netbeans could not find out "SetImageSize(6);" in the database so project does not run

Reply
avatar
2 décembre 2015 à 02:34 delete

i'm not using database in this project

Reply
avatar
23 janvier 2017 à 04:37 delete

does it require any jar files

Reply
avatar
23 janvier 2017 à 08:28 delete

its not displaying images for mee using same code

Reply
avatar
4 mars 2017 à 08:01 delete

It only displays the first image but won't run through the other images

Reply
avatar
15 décembre 2017 à 08:55 delete

the diagram are available for this code...both class and block

Reply
avatar
22 janvier 2018 à 09:28 delete

"super("Java SlideShow");"
has error.

error message:
constructor Object in class Object cannot be applied to given types
required: no arguments
found: string
reason: actual and formal arguments lists differ in length

Please help

Reply
avatar
15 novembre 2018 à 20:43 delete Ce commentaire a été supprimé par l'auteur.
avatar