java slide show

Thread Solved

Join Date: Feb 2009
Posts: 98
Reputation: weblover is an unknown quantity at this point 
Solved Threads: 1
weblover weblover is offline Offline
Junior Poster in Training

java slide show

 
0
  #1
Mar 8th, 2009
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
Reply With Quote Quick reply to this message  
Join Date: Feb 2009
Posts: 98
Reputation: weblover is an unknown quantity at this point 
Solved Threads: 1
weblover weblover is offline Offline
Junior Poster in Training

Re: java slide show

 
0
  #2
Mar 8th, 2009
hi ..i found out this code
  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
Reply With Quote Quick reply to this message  
Join Date: Nov 2008
Posts: 823
Reputation: verruckt24 is a jewel in the rough verruckt24 is a jewel in the rough verruckt24 is a jewel in the rough verruckt24 is a jewel in the rough 
Solved Threads: 73
verruckt24's Avatar
verruckt24 verruckt24 is offline Offline
Practically a Posting Shark

Re: java slide show

 
1
  #3
Mar 9th, 2009
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.
Get up every morning and take a look at the Forbes' list of richest people. If your name doesn't appear.... GET TO WORK !!!
Reply With Quote Quick reply to this message  
Join Date: Apr 2008
Posts: 53
Reputation: hell_tej is an unknown quantity at this point 
Solved Threads: 2
hell_tej hell_tej is offline Offline
Junior Poster in Training

Re: java slide show

 
0
  #4
Mar 9th, 2009
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
Reply With Quote Quick reply to this message  
Join Date: Nov 2008
Posts: 823
Reputation: verruckt24 is a jewel in the rough verruckt24 is a jewel in the rough verruckt24 is a jewel in the rough verruckt24 is a jewel in the rough 
Solved Threads: 73
verruckt24's Avatar
verruckt24 verruckt24 is offline Offline
Practically a Posting Shark

Re: java slide show

 
0
  #5
Mar 9th, 2009
if it put on JLable the lable size will set autometically as image size.
Whats wrong with that ?
Get up every morning and take a look at the Forbes' list of richest people. If your name doesn't appear.... GET TO WORK !!!
Reply With Quote Quick reply to this message  
Join Date: Apr 2008
Posts: 53
Reputation: hell_tej is an unknown quantity at this point 
Solved Threads: 2
hell_tej hell_tej is offline Offline
Junior Poster in Training

Re: java slide show

 
0
  #6
Mar 9th, 2009
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.
Reply With Quote Quick reply to this message  
Join Date: Feb 2009
Posts: 98
Reputation: weblover is an unknown quantity at this point 
Solved Threads: 1
weblover weblover is offline Offline
Junior Poster in Training

Re: java slide show

 
0
  #7
Mar 9th, 2009
thnx all ..i tried a code and i change in it a bit .......and it's working very well ...thnx very much
Reply With Quote Quick reply to this message  
Join Date: Nov 2008
Posts: 823
Reputation: verruckt24 is a jewel in the rough verruckt24 is a jewel in the rough verruckt24 is a jewel in the rough verruckt24 is a jewel in the rough 
Solved Threads: 73
verruckt24's Avatar
verruckt24 verruckt24 is offline Offline
Practically a Posting Shark

Re: java slide show

 
0
  #8
Mar 9th, 2009
Originally Posted by hell_tej View Post
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.
Get up every morning and take a look at the Forbes' list of richest people. If your name doesn't appear.... GET TO WORK !!!
Reply With Quote Quick reply to this message  
Join Date: May 2009
Posts: 1
Reputation: anwar2009 is an unknown quantity at this point 
Solved Threads: 0
anwar2009 anwar2009 is offline Offline
Newbie Poster

Re: java slide show

 
0
  #9
May 3rd, 2009
Originally Posted by verruckt24 View Post
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
Reply With Quote Quick reply to this message  
Join Date: Nov 2008
Posts: 823
Reputation: verruckt24 is a jewel in the rough verruckt24 is a jewel in the rough verruckt24 is a jewel in the rough verruckt24 is a jewel in the rough 
Solved Threads: 73
verruckt24's Avatar
verruckt24 verruckt24 is offline Offline
Practically a Posting Shark

Re: java slide show

 
0
  #10
May 4th, 2009
Originally Posted by anwar2009 View Post
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 !!!
Reply With Quote Quick reply to this message  
Reply

This thread has been marked solved.
Perhaps start a new thread instead?
Message:



Similar Threads
Other Threads in the Java Forum
Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC