Results 1 to 6 of 6
Thread: Java Slideshow in BlueJ...Help!
- 06-22-2010, 11:46 AM #1
Member
- Join Date
- Jun 2010
- Posts
- 3
- Rep Power
- 0
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,
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?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); } }
Thanks.
- 06-22-2010, 01:00 PM #2
main is not a good name for a class. Try a more descriptive name and upper case first letter.create if possible a second class called main whereby the file can be opened using dos
What is "dos" and why do you want to use it?
What is the purpose of the timer and timercount?
- 06-22-2010, 03:48 PM #3
- Join Date
- Jul 2007
- Location
- Colombo, Sri Lanka
- Posts
- 11,374
- Blog Entries
- 1
- Rep Power
- 18
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.
- 06-23-2010, 02:44 PM #4
Member
- Join Date
- Jun 2010
- Posts
- 3
- Rep Power
- 0
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)); }
- 06-23-2010, 03:38 PM #5
Add some debugging code to see if you are finding the image file and creating an image in changeImage()
- 06-24-2010, 04:16 AM #6
- Join Date
- Jul 2007
- Location
- Colombo, Sri Lanka
- Posts
- 11,374
- Blog Entries
- 1
- Rep Power
- 18
Yeah, did you debug the code?
Did you get the correct path here?Java Code:pictureLabel = new JLabel(); pictureLabel.setIcon(new ImageIcon(PATH + "Pic01.jpg"));
Similar Threads
-
BlueJ help
By Cid17 in forum New To JavaReplies: 2Last Post: 06-29-2009, 07:38 PM -
Java Applet Help with BlueJ
By moofs in forum New To JavaReplies: 0Last Post: 01-15-2009, 04:24 AM -
Applet Slideshow in web browser
By Urgle in forum New To JavaReplies: 0Last Post: 12-01-2008, 04:30 AM -
help using BlueJ
By zoe in forum New To JavaReplies: 1Last Post: 08-07-2007, 06:07 AM -
BlueJ 2.2.0
By JavaBean in forum Java SoftwareReplies: 0Last Post: 07-07-2007, 02:28 PM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks