Results 1 to 6 of 6
  1. #1
    MarkL410 is offline Member
    Join Date
    Jun 2010
    Posts
    3
    Rep Power
    0

    Default Java Slideshow in BlueJ...Help!

    Hi,

    I am completely new to Java and signed up for the forums because I am in serious need of assistance please...

    I am trying to create an image slideshow in BlueJ...here is my code so far,

    Java Code:
    import java.awt.*;
    import java.awt.event.*;
    import javax.swing.*;
    
    /**
     * Write a description of class SlideShow here.
     * 
     * @author (your name) 
     * @version (a version number or a date)
     */
    public class SlideShow implements ActionListener
    {
       private JFrame frame;
       private JLabel pictureLabel;
       private JTextField field;
       private JButton clickButton;
       private static final String PATH = "Pictures";
       
       
        /**
         * Constructor for objects of class SlideShow
         */
        public SlideShow()
        {
           makeFrame();
        }
    
        /**
         * An example of a method - replace this comment with your own
         * 
         * @param  y   a sample parameter for a method
         * @return     the sum of x and y 
         */
        private void makeFrame()
        {
            frame = new JFrame ("Slide Show");
            
            JMenuBar menubar = new JMenuBar();
            frame.setJMenuBar(menubar);
            
            JMenu fileMenu = new JMenu ("Select Picture");
            menubar.add(fileMenu);
            
            JMenuItem thisItem = new JMenuItem("Pic01.jpg");
            thisItem.addActionListener(this);
            fileMenu.add(thisItem);
            
            JMenuItem thatItem = new JMenuItem("Pic02.jpg");
            thatItem.addActionListener(this);
            fileMenu.add(thatItem);
            
            JMenuItem otherItem = new JMenuItem("Pic03.jpg");
            otherItem.addActionListener(this);
            fileMenu.add(otherItem);
            
            Container contentPane = frame.getContentPane();
            
            JLabel label = new JLabel("The World Cup's Greatest Players");
            
            pictureLabel = new JLabel();
            pictureLabel.setIcon(new ImageIcon(PATH + "Pic01.jpg"));
            
            
            clickButton = new JButton ("Change Picture");
            clickButton.addActionListener(this);
    
           
            
            frame.pack();
            frame.setVisible(true);
            
        }
        
        
        
     
        
        
            
    }
    I realise for the slideshow to work properly I need to add a timer, timercount and I am also going to create if possible a second class called main whereby the file can be opened using dos. I am completely stuck on where to go next, could somebody point me in the right direction?

    Thanks.

  2. #2
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    SW Missouri
    Posts
    17,332
    Rep Power
    25

    Default

    create if possible a second class called main whereby the file can be opened using dos
    main is not a good name for a class. Try a more descriptive name and upper case first letter.
    What is "dos" and why do you want to use it?

    What is the purpose of the timer and timercount?

  3. #3
    Eranga's Avatar
    Eranga is offline Moderator
    Join Date
    Jul 2007
    Location
    Colombo, Sri Lanka
    Posts
    11,372
    Blog Entries
    1
    Rep Power
    20

    Default

    Do you want to rotate within the image list on a timer? Can you explain bit more, because in your code I cannot see any dynamic changes as your title talking about slide show.

  4. #4
    MarkL410 is offline Member
    Join Date
    Jun 2010
    Posts
    3
    Rep Power
    0

    Default

    Ok I have put in the code I was needing but a new problem has come up in that the pictures are not showing on the application. Here is the updated code...

    Java Code:
    import java.awt.*;
    import java.awt.event.*;
    import javax.swing.*;
    
    /**
     * Write a description of class SlideShow here.
     * 
     * @author (your name) 
     * @version (a version number or a date)
     */
    public class SlideShow implements ActionListener
    {
       private JFrame frame;
       private JLabel pictureLabel;
       private JTextField field;
       private JButton clickButton;
       private static final String PATH = "Pictures";
       private int timerCount;
       private Timer myTimer;
       
       
        /**
         * Constructor for objects of class SlideShow
         */
        public SlideShow()
        {
           makeFrame();
           timerCount = 0;
           myTimer = new Timer(3000,this);
           myTimer.start();
        }
    
        /**
         * An example of a method - replace this comment with your own
         * 
         * @param  y   a sample parameter for a method
         * @return     the sum of x and y 
         */
        private void makeFrame()
        {
            frame = new JFrame ("Slide Show");
            
            JMenuBar menubar = new JMenuBar();
            frame.setJMenuBar(menubar);
            
            JMenu fileMenu = new JMenu ("Select Picture");
            menubar.add(fileMenu);
            
            JMenuItem thisItem = new JMenuItem("Pic01.jpg");
            thisItem.addActionListener(this);
            fileMenu.add(thisItem);
            
            JMenuItem thatItem = new JMenuItem("Pic02.jpg");
            thatItem.addActionListener(this);
            fileMenu.add(thatItem);
            
            JMenuItem otherItem = new JMenuItem("Pic03.jpg");
            otherItem.addActionListener(this);
            fileMenu.add(otherItem);
            
            Container contentPane = frame.getContentPane();
            contentPane.setLayout(new BorderLayout());
            
            JLabel label = new JLabel("The World Cup's Greatest Players");
            contentPane.add(label, BorderLayout.WEST);
            
            field = new JTextField(15);
            contentPane.add(field, BorderLayout.CENTER);
            
            pictureLabel = new JLabel();
            pictureLabel.setIcon(new ImageIcon(PATH + "Pic01.jpg"));
            contentPane.add(pictureLabel, BorderLayout.NORTH);
            clickButton = new JButton ("Change Picture");
            clickButton.addActionListener(this);
            contentPane.add(clickButton, BorderLayout.SOUTH);
            
            frame.pack();
            frame.setVisible(true);
            
        }
        
        public void actionPerformed(ActionEvent event)
        {
            if (event.getSource() == myTimer)
            {  timerCount++;
               if (timerCount > 9)
                  timerCount = 0;
               changePicture("Pic01" + timerCount + ".jpg");
            }
            else if (event.getSource() == clickButton)
              changePicture(field.getText());
            else
              field.setText(event.getActionCommand());
           
            }
            
        public void changePicture(String pictureFileId)
        {
            pictureLabel.setIcon(new ImageIcon(PATH + pictureFileId));
        }

  5. #5
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    SW Missouri
    Posts
    17,332
    Rep Power
    25

    Default

    Add some debugging code to see if you are finding the image file and creating an image in changeImage()

  6. #6
    Eranga's Avatar
    Eranga is offline Moderator
    Join Date
    Jul 2007
    Location
    Colombo, Sri Lanka
    Posts
    11,372
    Blog Entries
    1
    Rep Power
    20

    Default

    Yeah, did you debug the code?

    Java Code:
    pictureLabel = new JLabel();
            pictureLabel.setIcon(new ImageIcon(PATH + "Pic01.jpg"));
    Did you get the correct path here?

Similar Threads

  1. BlueJ help
    By Cid17 in forum New To Java
    Replies: 2
    Last Post: 06-29-2009, 07:38 PM
  2. Java Applet Help with BlueJ
    By moofs in forum New To Java
    Replies: 0
    Last Post: 01-15-2009, 04:24 AM
  3. Applet Slideshow in web browser
    By Urgle in forum New To Java
    Replies: 0
    Last Post: 12-01-2008, 04:30 AM
  4. help using BlueJ
    By zoe in forum New To Java
    Replies: 1
    Last Post: 08-07-2007, 06:07 AM
  5. BlueJ 2.2.0
    By JavaBean in forum Java Software
    Replies: 0
    Last Post: 07-07-2007, 02:28 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •