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
weblover 0 Junior Poster
hi ..i found out this code
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);
}
}
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
verruckt24 438 Posting Shark
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.
BestJewSinceJC commented: good advice +4
hell_tej 5 Junior Poster in Training
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
verruckt24 438 Posting Shark
if it put on JLable the lable size will set autometically as image size.
Whats wrong with that ?
hell_tej 5 Junior Poster in Training
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.
weblover 0 Junior Poster
thnx all ..i tried a code and i change in it a bit .......and it's working very well ...thnx very much
verruckt24 438 Posting Shark
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.
anwar2009 0 Newbie Poster
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
verruckt24 438 Posting Shark
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.
Be a part of the DaniWeb community
We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.