943,822 Members | Top Members by Rank

Ad:
  • Java Discussion Thread
  • Marked Solved
  • Views: 3812
  • Java RSS
Mar 8th, 2009
0

java slide show

Expand Post »
hi all ..i need help plz ...where can i find a java code(not Javascript) for an image slide show ...made in GUI ...if someone knows ..plz help ..and thnx in advance
Similar Threads
Reputation Points: 10
Solved Threads: 1
Junior Poster
weblover is offline Offline
131 posts
since Feb 2009
Mar 8th, 2009
0

Re: java slide show

hi ..i found out this code
Java Syntax (Toggle Plain Text)
  1. import java.awt.*;
  2. import javax.swing.*;
  3. import java.io.*;
  4. import javax.swing.border.*;
  5. import java.awt.event.*;
  6. import java.awt.Rectangle;
  7.  
  8.  
  9. public class Photoes extends JFrame {
  10.  
  11. static int x=1;
  12.  
  13. JButton bNext = new JButton();
  14. JButton bPrevious = new JButton();
  15. TitledBorder titledBorder1 = new TitledBorder("");
  16. JLabel lblPhoto = new JLabel();
  17. TitledBorder titledBorder2 = new TitledBorder("");
  18.  
  19.  
  20. public Photoes() {
  21.  
  22. try {
  23. jbInit();
  24. }
  25.  
  26. catch (Exception e) {
  27.  
  28. }
  29. }
  30.  
  31.  
  32. private void jbInit() throws Exception {
  33.  
  34. getContentPane().setLayout(null);
  35. this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
  36. this.setResizable(false);
  37. this.setTitle("Simple Photo Viewer");
  38. this.setBounds(50,10,810,740);
  39. this.setVisible(true);
  40. this.addWindowListener(new Photoes_this_windowAdapter(this));
  41.  
  42. lblPhoto.setFont(new java.awt.Font("Arial", Font.BOLD, 30));
  43. lblPhoto.setHorizontalAlignment(JLabel.CENTER);
  44. lblPhoto.setBorder(titledBorder2);
  45. lblPhoto.setBounds(new Rectangle(10, 10, 800, 600));
  46.  
  47.  
  48. bNext.setBounds(new Rectangle(610, 636, 118, 46));
  49. bNext.setToolTipText("Show next image");
  50. bNext.setText("Next");
  51. bNext.addMouseListener(new Photoes_bNext_mouseAdapter(this));
  52. bNext.addActionListener(new Photoes_bNext_actionAdapter(this));
  53. bNext.setMnemonic('N');
  54.  
  55. bPrevious.setBounds(new Rectangle(371, 636, 111, 46));
  56. bPrevious.setToolTipText("Show Previous Photo");
  57. bPrevious.setText("Previous");
  58. bPrevious.addActionListener(new Photoes_bPrevious_actionAdapter(this));
  59. bPrevious.setMnemonic('P');
  60.  
  61.  
  62.  
  63. this.getContentPane().add(lblPhoto);
  64. this.getContentPane().add(bNext);
  65. this.getContentPane().add(bPrevious);
  66. this.viewPhotoes();
  67. }
  68.  
  69.  
  70. public void viewPhotoes(){
  71.  
  72.  
  73. String file = Integer.toString(x) + ".jpg";
  74. File f = new File(file);
  75. if (!f.exists()) {
  76. JOptionPane.showConfirmDialog((Component)null,
  77. "Photo " + f.getName() + " not available.Re-viewing files again.",
  78. "File not found.",
  79. JOptionPane.PLAIN_MESSAGE);
  80. x=0;
  81. }
  82.  
  83. /*JLabel picturelabel=new JLabel();
  84.   picturelabel.setIcon(new ImageIcon("ch1.jpg"));
  85.   picturelabel.setBounds(700,80,500,300);
  86.   content.add(picturelabel);*/
  87. ImageIcon i = new ImageIcon(file);
  88. lblPhoto.setIcon(i);
  89. }
  90.  
  91.  
  92. public static void main(String args[]){
  93.  
  94. Photoes pho=new Photoes();
  95. }
  96.  
  97.  
  98. public void bPrevious_actionPerformed(ActionEvent e) {
  99.  
  100. if(x>1) {
  101. x--;
  102. this.viewPhotoes();
  103. }
  104. }
  105.  
  106.  
  107. public void bNext_actionPerformed(ActionEvent e) {
  108.  
  109. x++;
  110. this.viewPhotoes();
  111. }
  112.  
  113.  
  114. public void this_windowOpened(WindowEvent e) {
  115.  
  116. 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);
  117. }
  118. }
  119.  
  120.  
  121.  
  122.  
  123.  
  124.  
  125.  
  126.  
  127. class Photoes_this_windowAdapter extends WindowAdapter {
  128.  
  129. private Photoes adaptee;
  130.  
  131.  
  132. Photoes_this_windowAdapter(Photoes adaptee) {
  133.  
  134. this.adaptee = adaptee;
  135. }
  136.  
  137.  
  138. public void windowOpened(WindowEvent e) {
  139.  
  140. adaptee.this_windowOpened(e);
  141. }
  142. }
  143.  
  144.  
  145.  
  146. class Photoes_bNext_mouseAdapter extends MouseAdapter {
  147.  
  148.  
  149. private Photoes adaptee;
  150.  
  151. Photoes_bNext_mouseAdapter(Photoes adaptee) {
  152.  
  153. this.adaptee = adaptee;
  154. }
  155. }
  156.  
  157.  
  158.  
  159. class Photoes_bNext_actionAdapter implements ActionListener {
  160.  
  161.  
  162. private Photoes adaptee;
  163.  
  164. Photoes_bNext_actionAdapter(Photoes adaptee) {
  165.  
  166. this.adaptee = adaptee;
  167. }
  168.  
  169.  
  170. public void actionPerformed(ActionEvent e) {
  171.  
  172. adaptee.bNext_actionPerformed(e);
  173. }
  174. }
  175.  
  176.  
  177.  
  178. class Photoes_bPrevious_actionAdapter implements ActionListener {
  179.  
  180. private Photoes adaptee;
  181.  
  182. Photoes_bPrevious_actionAdapter(Photoes adaptee) {
  183.  
  184. this.adaptee = adaptee;
  185. }
  186.  
  187.  
  188. public void actionPerformed(ActionEvent e) {
  189.  
  190. adaptee.bPrevious_actionPerformed(e);
  191. }
  192. }
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
Reputation Points: 10
Solved Threads: 1
Junior Poster
weblover is offline Offline
131 posts
since Feb 2009
Mar 9th, 2009
1

Re: java slide show

Quote ...
what is this (File f=new File(file)
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.
Last edited by verruckt24; Mar 9th, 2009 at 1:00 am.
Reputation Points: 485
Solved Threads: 89
Posting Shark
verruckt24 is offline Offline
944 posts
since Nov 2008
Mar 9th, 2009
0

Re: java slide show

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
Reputation Points: 15
Solved Threads: 3
Junior Poster in Training
hell_tej is offline Offline
53 posts
since Apr 2008
Mar 9th, 2009
0

Re: java slide show

Quote ...
if it put on JLable the lable size will set autometically as image size.
Whats wrong with that ?
Reputation Points: 485
Solved Threads: 89
Posting Shark
verruckt24 is offline Offline
944 posts
since Nov 2008
Mar 9th, 2009
0

Re: java slide show

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.
Reputation Points: 15
Solved Threads: 3
Junior Poster in Training
hell_tej is offline Offline
53 posts
since Apr 2008
Mar 9th, 2009
0

Re: java slide show

thnx all ..i tried a code and i change in it a bit .......and it's working very well ...thnx very much
Reputation Points: 10
Solved Threads: 1
Junior Poster
weblover is offline Offline
131 posts
since Feb 2009
Mar 9th, 2009
0

Re: java slide show

Click to Expand / Collapse  Quote originally posted by hell_tej ...
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.
You can always restrict the size of the JLabel to disallow it to grow more than a specified size.

@OP : Mark the thread solve if it is.
Last edited by verruckt24; Mar 9th, 2009 at 11:32 pm.
Reputation Points: 485
Solved Threads: 89
Posting Shark
verruckt24 is offline Offline
944 posts
since Nov 2008
May 3rd, 2009
0

Re: java slide show

Click to Expand / Collapse  Quote originally posted by verruckt24 ...
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
Reputation Points: 10
Solved Threads: 0
Newbie Poster
anwar2009 is offline Offline
1 posts
since May 2009
May 4th, 2009
0

Re: java slide show

Click to Expand / Collapse  Quote originally posted by anwar2009 ...
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.
Reputation Points: 485
Solved Threads: 89
Posting Shark
verruckt24 is offline Offline
944 posts
since Nov 2008

This thread is solved

Either the thread starter or a moderator has marked this thread as solved. You can most likely trust the responses and answers given. There is most likely no reason for any further responses to be posted here. If you have a related question, please start a new thread in this forum instead.

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in Java Forum Timeline: hi
Next Thread in Java Forum Timeline: Drawing using data from a 3d Array Confusion, Please Help!





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC