JAVA - How To Create A Slideshow In Java
__________________________________________________________________________
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:
Download Projects Source Code
netbeans could not find out "SetImageSize(6);" in the database so project does not run
RépondreSupprimeri'm not using database in this project
Supprimerdoes it require any jar files
RépondreSupprimernope
Supprimerits not displaying images for mee using same code
RépondreSupprimerIt only displays the first image but won't run through the other images
RépondreSupprimerthe diagram are available for this code...both class and block
RépondreSupprimer"super("Java SlideShow");"
RépondreSupprimerhas 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
Ce commentaire a été supprimé par l'auteur.
RépondreSupprimerNice from Renita Lobo
RépondreSupprimerNice
RépondreSupprimerGood
RépondreSupprimer