| | |
java slide show
Thread Solved |
•
•
Join Date: Feb 2009
Posts: 98
Reputation:
Solved Threads: 1
hi ..i found out this code
but the pics are not showing ......how can i change the code to show the pics .....and what is this (File f=new File(file)
how can i use this code in the best way ? and thnx
Java Syntax (Toggle Plain Text)
import java.awt.*; import javax.swing.*; import java.io.*; import javax.swing.border.*; import java.awt.event.*; import java.awt.Rectangle; public class Photoes extends JFrame { static int x=1; JButton bNext = new JButton(); JButton bPrevious = new JButton(); TitledBorder titledBorder1 = new TitledBorder(""); JLabel lblPhoto = new JLabel(); TitledBorder titledBorder2 = new TitledBorder(""); public Photoes() { try { jbInit(); } catch (Exception e) { } } private void jbInit() throws Exception { getContentPane().setLayout(null); this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); this.setResizable(false); this.setTitle("Simple Photo Viewer"); this.setBounds(50,10,810,740); this.setVisible(true); this.addWindowListener(new Photoes_this_windowAdapter(this)); lblPhoto.setFont(new java.awt.Font("Arial", Font.BOLD, 30)); lblPhoto.setHorizontalAlignment(JLabel.CENTER); lblPhoto.setBorder(titledBorder2); lblPhoto.setBounds(new Rectangle(10, 10, 800, 600)); bNext.setBounds(new Rectangle(610, 636, 118, 46)); bNext.setToolTipText("Show next image"); bNext.setText("Next"); bNext.addMouseListener(new Photoes_bNext_mouseAdapter(this)); bNext.addActionListener(new Photoes_bNext_actionAdapter(this)); bNext.setMnemonic('N'); bPrevious.setBounds(new Rectangle(371, 636, 111, 46)); bPrevious.setToolTipText("Show Previous Photo"); bPrevious.setText("Previous"); bPrevious.addActionListener(new Photoes_bPrevious_actionAdapter(this)); bPrevious.setMnemonic('P'); this.getContentPane().add(lblPhoto); this.getContentPane().add(bNext); this.getContentPane().add(bPrevious); this.viewPhotoes(); } public void viewPhotoes(){ String file = Integer.toString(x) + ".jpg"; File f = new File(file); if (!f.exists()) { JOptionPane.showConfirmDialog((Component)null, "Photo " + f.getName() + " not available.Re-viewing files again.", "File not found.", JOptionPane.PLAIN_MESSAGE); x=0; } /*JLabel picturelabel=new JLabel(); picturelabel.setIcon(new ImageIcon("ch1.jpg")); picturelabel.setBounds(700,80,500,300); content.add(picturelabel);*/ ImageIcon i = new ImageIcon(file); lblPhoto.setIcon(i); } public static void main(String args[]){ Photoes pho=new Photoes(); } public void bPrevious_actionPerformed(ActionEvent e) { if(x>1) { x--; this.viewPhotoes(); } } public void bNext_actionPerformed(ActionEvent e) { x++; this.viewPhotoes(); } public void this_windowOpened(WindowEvent e) { JOptionPane.showConfirmDialog((Component) null,"This photo viewer supports only jpg images named 1.jpg,2.jpg,3.jpg.... \nand those images must be in the same directory where the java class file in\n\t<<<800*600 JPEGs fits well to the window>>>","Important Massage",JOptionPane.DEFAULT_OPTION); } } class Photoes_this_windowAdapter extends WindowAdapter { private Photoes adaptee; Photoes_this_windowAdapter(Photoes adaptee) { this.adaptee = adaptee; } public void windowOpened(WindowEvent e) { adaptee.this_windowOpened(e); } } class Photoes_bNext_mouseAdapter extends MouseAdapter { private Photoes adaptee; Photoes_bNext_mouseAdapter(Photoes adaptee) { this.adaptee = adaptee; } } class Photoes_bNext_actionAdapter implements ActionListener { private Photoes adaptee; Photoes_bNext_actionAdapter(Photoes adaptee) { this.adaptee = adaptee; } public void actionPerformed(ActionEvent e) { adaptee.bNext_actionPerformed(e); } } class Photoes_bPrevious_actionAdapter implements ActionListener { private Photoes adaptee; Photoes_bPrevious_actionAdapter(Photoes adaptee) { this.adaptee = adaptee; } public void actionPerformed(ActionEvent e) { adaptee.bPrevious_actionPerformed(e); } }
how can i use this code in the best way ? and thnx •
•
•
•
what is this (File f=new File(file)
However I can help you, write it on your own.
You need a Swing component, something like a JFrame of JPanel, put a JLabel onto it (big enough), onto which you can show your images. To auto run the slide show you change the image on the JLabel after periodic intervals using the Thread.sleep() method. (If you know what it is!)
If you want to develop a more complex slide show, where a user can hit the "prev"/"next" button, you can have this functionality built-in in your application by arranging the images to be shown in a particular order and then running through them back or forth as suggested by the user. You can then start the sleep interval on every hit of the prev/next button anew so that each image is displayed for only a specified time duration. To provide more features such as stopping the auto changing of an image, you can make the Thread stop so that it doen't flip images on it's own. To allow the user to set a custom or pre-specified interval for changing the current image you can make use of checkboxes (for pre-specified time intervals) such as 2 secs, 5 secs, 10 secs etc or to allow the user to set a custom interval you can use a textbox where the user is supposed to enter a value for the interval in seconds and then make use of the checkbox/textbox value as a parameter for the Thread.sleep method.
Last edited by verruckt24; Mar 9th, 2009 at 1:00 am.
Get up every morning and take a look at the Forbes' list of richest people. If your name doesn't appear.... GET TO WORK !!!
•
•
Join Date: Apr 2008
Posts: 53
Reputation:
Solved Threads: 2
hi
I suggest you to drow an image on JPanel because if it put on JLable the lable size will set autometically as image size.
1).Create a Innerclass which extends JPanel
2).then override a paintComponent Method that contain Image object
3).Check weather panel exist or not
4.)then if panel not exist add that panel
5).every time you change image repeat (3,4) code
then as verruckt24 sayed you can change the image on panel using Thread or by any swing actionPerformed event Code
I suggest you to drow an image on JPanel because if it put on JLable the lable size will set autometically as image size.
1).Create a Innerclass which extends JPanel
2).then override a paintComponent Method that contain Image object
3).Check weather panel exist or not
4.)then if panel not exist add that panel
5).every time you change image repeat (3,4) code
then as verruckt24 sayed you can change the image on panel using Thread or by any swing actionPerformed event Code
•
•
Join Date: Apr 2008
Posts: 53
Reputation:
Solved Threads: 2
If the image resolution is more then specified critarea image lable automatic increas it's size and all other component of JFrame will become hidden or unmannaged.
i have also that problem one month ago.that's why i use Stretching of image. however it has one disadvantage that it takes some moter time then JLable cause it drows the image on panel.
i have also that problem one month ago.that's why i use Stretching of image. however it has one disadvantage that it takes some moter time then JLable cause it drows the image on panel.
•
•
•
•
If the image resolution is more then specified critarea image lable automatic increas it's size and all other component of JFrame will become hidden or unmannaged.
i have also that problem one month ago.that's why i use Stretching of image. however it has one disadvantage that it takes some moter time then JLable cause it drows the image on panel.
@OP : Mark the thread solve if it is.
Last edited by verruckt24; Mar 9th, 2009 at 11:32 pm.
Get up every morning and take a look at the Forbes' list of richest people. If your name doesn't appear.... GET TO WORK !!!
•
•
Join Date: May 2009
Posts: 1
Reputation:
Solved Threads: 0
•
•
•
•
Well, thats what happens when you put yourself into a habit of "finding out code" instead of writing it yourself - you are stumped by the most basic and rudimentary things. As something I am personally against, I won't help you understanding this code as it isn't written by you.
However I can help you, write it on your own.
You need a Swing component, something like a JFrame of JPanel, put a JLabel onto it (big enough), onto which you can show your images. To auto run the slide show you change the image on the JLabel after periodic intervals using the Thread.sleep() method. (If you know what it is!)
If you want to develop a more complex slide show, where a user can hit the "prev"/"next" button, you can have this functionality built-in in your application by arranging the images to be shown in a particular order and then running through them back or forth as suggested by the user. You can then start the sleep interval on every hit of the prev/next button anew so that each image is displayed for only a specified time duration. To provide more features such as stopping the auto changing of an image, you can make the Thread stop so that it doen't flip images on it's own. To allow the user to set a custom or pre-specified interval for changing the current image you can make use of checkboxes (for pre-specified time intervals) such as 2 secs, 5 secs, 10 secs etc or to allow the user to set a custom interval you can use a textbox where the user is supposed to enter a value for the interval in seconds and then make use of the checkbox/textbox value as a parameter for the Thread.sleep method.
I did what you suggested exactly. My action listener tries to set the the panel to a different image but nothing changes.
Could you suggest something else please?
Thank you
Show us your code, so that we might help you better. Also this thread has already been marked as solved, so start a new thread.
Last edited by verruckt24; May 4th, 2009 at 2:39 am.
Get up every morning and take a look at the Forbes' list of richest people. If your name doesn't appear.... GET TO WORK !!!
![]() |
Similar Threads
- javaScript Picture Slide Show (JavaScript / DHTML / AJAX)
- help with scrolling, clickable slide show (JavaScript / DHTML / AJAX)
- adding keylistener (Java)
- Java assignment help :/ (Java)
- Java Applets (Java)
Other Threads in the Java Forum
- Previous Thread: hi
- Next Thread: Drawing using data from a 3d Array Confusion, Please Help!
| Thread Tools | Search this Thread |
911 actionlistener addressbook android api append applet application array arrays automation binary blackberry block bluetooth character chat class client code component consumer csv database desktop developmenthelp eclipse error fractal ftp game givemetehcodez graphics gui html ide image integer j2me j2seprojects japplet java javaarraylist javac javaee javaprojects jni jpanel julia lego linked linux list loops mac map method methods mobile netbeans newbie number objects online oriented panel printf problem program programming project projects properties recursion replaydirector reporting researchinmotion rotatetext rsa scanner se server set singleton sms sort sql string swing test textfields threads time title tree tutorial-sample ubuntu update windows working





