473,473 Members | 2,141 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

help on image slider

16 New Member
Anyone who understand the codes below, can you please kindly explain to me by adding comments.. thanks in advance

Expand|Select|Wrap|Line Numbers
  1.  
  2. // <applet code="ImageSlider" width="400" height="400"></applet>
  3. import java.awt.*;
  4. import java.awt.image.BufferedImage;
  5. import java.io.*;
  6. import javax.imageio.ImageIO;
  7. import javax.swing.*;
  8. import javax.swing.event.*;
  9.  
  10. public class ImageSlider extends JApplet implements ChangeListener {
  11. BufferedImage[] images;
  12. JLabel label;
  13.  
  14. public void init() {
  15. images = getImages();
  16. getContentPane().setLayout(new BorderLayout());
  17. getContentPane().add(getLabelComponent());
  18. getContentPane().add(getSlider(), "Last");
  19. }
  20.  
  21. public void stateChanged(ChangeEvent e) {
  22. JSlider slider = (JSlider)e.getSource();
  23. int index = slider.getValue() -1;
  24. label.setIcon(new ImageIcon(images[index]));
  25. }
  26.  
  27. private JScrollPane getLabelComponent() {
  28. label = new JLabel(new ImageIcon(images[0]));
  29. label.setHorizontalAlignment(JLabel.CENTER);
  30. return new JScrollPane(label);
  31. }
  32.  
  33. private JSlider getSlider() {
  34. JSlider slider = new JSlider(1, 4, 1);
  35. slider.setPaintTicks(true);
  36. slider.setPaintLabels(true);
  37. slider.setMajorTickSpacing(1);
  38. slider.setSnapToTicks(true);
  39. slider.addChangeListener(this);
  40. return slider;
  41. }
  42.  
  43. private BufferedImage[] getImages() {
  44. BufferedImage[] images = new BufferedImage[4];
  45. for(int j = 0; j < images.length; j++) {
  46. try {
  47. String path = "images/t" + (j+1) + ".gif";
  48. images[j] = ImageIO.read(new File(path));
  49. } catch(IOException e) {
  50. System.out.println("Read error: " + e.getMessage());
  51. }
  52. }
  53. return images;
  54. }
  55. }
  56.  
  57.  
Jun 25 '07 #1
20 3686
r035198x
13,262 MVP
Anyone who understand the codes below, can you please kindly explain to me by adding comments.. thanks in advance

Expand|Select|Wrap|Line Numbers
  1.  
  2. // <applet code="ImageSlider" width="400" height="400"></applet>
  3. import java.awt.*;
  4. import java.awt.image.BufferedImage;
  5. import java.io.*;
  6. import javax.imageio.ImageIO;
  7. import javax.swing.*;
  8. import javax.swing.event.*;
  9.  
  10. public class ImageSlider extends JApplet implements ChangeListener {
  11. BufferedImage[] images;
  12. JLabel label;
  13.  
  14. public void init() {
  15. images = getImages();
  16. getContentPane().setLayout(new BorderLayout());
  17. getContentPane().add(getLabelComponent());
  18. getContentPane().add(getSlider(), "Last");
  19. }
  20.  
  21. public void stateChanged(ChangeEvent e) {
  22. JSlider slider = (JSlider)e.getSource();
  23. int index = slider.getValue() -1;
  24. label.setIcon(new ImageIcon(images[index]));
  25. }
  26.  
  27. private JScrollPane getLabelComponent() {
  28. label = new JLabel(new ImageIcon(images[0]));
  29. label.setHorizontalAlignment(JLabel.CENTER);
  30. return new JScrollPane(label);
  31. }
  32.  
  33. private JSlider getSlider() {
  34. JSlider slider = new JSlider(1, 4, 1);
  35. slider.setPaintTicks(true);
  36. slider.setPaintLabels(true);
  37. slider.setMajorTickSpacing(1);
  38. slider.setSnapToTicks(true);
  39. slider.addChangeListener(this);
  40. return slider;
  41. }
  42.  
  43. private BufferedImage[] getImages() {
  44. BufferedImage[] images = new BufferedImage[4];
  45. for(int j = 0; j < images.length; j++) {
  46. try {
  47. String path = "images/t" + (j+1) + ".gif";
  48. images[j] = ImageIO.read(new File(path));
  49. } catch(IOException e) {
  50. System.out.println("Read error: " + e.getMessage());
  51. }
  52. }
  53. return images;
  54. }
  55. }
  56.  
  57.  
Why not read an Applet and a Swing tutorial, then you can even comment it yourself.
Jun 25 '07 #2
fatfatpopo
16 New Member
Why not read an Applet and a Swing tutorial, then you can even comment it yourself.
I had read it, but still don't quit understand.So im here to see anyone who can give me any assistance.
Jun 26 '07 #3
r035198x
13,262 MVP
I had read it, but still don't quit understand.So im here to see anyone who can give me any assistance.
Which part do you not understand then?
Jun 26 '07 #4
fatfatpopo
16 New Member
Which part do you not understand then?

Do you have any tutorial guide to recommend for all these codes? Other than javasun.. Thanks
Jun 26 '07 #5
r035198x
13,262 MVP
Do you have any tutorial guide to recommend for all these codes? Other than javasun.. Thanks
Sun's swing tutorial is the best one for it and that's the only one I'll recommend.
Jun 26 '07 #6
fatfatpopo
16 New Member
Which part do you not understand then?
I don't really understand the code below.. But i know is setting the layout in the applet.

Expand|Select|Wrap|Line Numbers
  1. getContentPane().setLayout(new BorderLayout());
  2. getContentPane().add(getLabelComponent());
  3. getContentPane().add(getSlider(), "Last");
  4.  
Jun 26 '07 #7
r035198x
13,262 MVP
I don't really understand the code below.. But i know is setting the layout in the applet.

Expand|Select|Wrap|Line Numbers
  1. getContentPane().setLayout(new BorderLayout());
  2. getContentPane().add(getLabelComponent());
  3. getContentPane().add(getSlider(), "Last");
  4.  
The first line sets the layout to be BorderLayout, the next two lines add two things first a JScrollPane and then a JSlider. Both of these are discussed in the swing tutorial link that I gave you. The methods getLabelComponent() and getSlider() which reaturn these components are there in the ImageSlider applet that you have.
Jun 26 '07 #8
fatfatpopo
16 New Member
The first line sets the layout to be BorderLayout, the next two lines add two things first a JScrollPane and then a JSlider. Both of these are discussed in the swing tutorial link that I gave you. The methods getLabelComponent() and getSlider() which reaturn these components are there in the ImageSlider applet that you have.

I would like to ask regarding "getLabelComponent() ", how i know what name should i put after "get"
Jun 26 '07 #9
r035198x
13,262 MVP
I would like to ask regarding "getLabelComponent() ", how i know what name should i put after "get"
It depends on what you've called the method in the class. See my reply #8 again.
Jun 26 '07 #10
fatfatpopo
16 New Member
It depends on what you've called the method in the class. See my reply #8 again.
Kindly tell me what is going on in the codes below

Expand|Select|Wrap|Line Numbers
  1. for(int j = 0; j < images.length; j++) {
  2.             try {
  3.                 String path = "images/t" + (j+1) + ".gif";
  4.                 images[j] = ImageIO.read(new File(path));
  5.             } catch(IOException e) {
  6.                 System.out.println("Read error: " + e.getMessage());
  7.  
Jun 27 '07 #11
r035198x
13,262 MVP
Kindly tell me what is going on in the codes below

Expand|Select|Wrap|Line Numbers
  1. for(int j = 0; j < images.length; j++) {
  2.             try {
  3.                 String path = "images/t" + (j+1) + ".gif";
  4.                 images[j] = ImageIO.read(new File(path));
  5.             } catch(IOException e) {
  6.                 System.out.println("Read error: " + e.getMessage());
  7.  
Dry run it on a piece of paper with sample values and tell us what you think it's doing.
Jun 27 '07 #12
fatfatpopo
16 New Member
Dry run it on a piece of paper with sample values and tell us what you think it's doing.

Can anyone tell me, how come im not able to view it at the browser? Thanks alot..
Jun 28 '07 #13
r035198x
13,262 MVP
Can anyone tell me, how come im not able to view it at the browser? Thanks alot..
Did you manage to run it on some simple editor like Textpad?
How are you running it on the browser and what does it do when you run it?
Jun 28 '07 #14
fatfatpopo
16 New Member
Did you manage to run it on some simple editor like Textpad?
How are you running it on the browser and what does it do when you run it?

Do you know what does the error mean?
Below is the error message shown in Java Console:


java.security.AccessControlException: access denied (java.io.FilePermission images\t1.gif read)
at java.security.AccessControlContext.checkPermission (Unknown Source)
at java.security.AccessController.checkPermission(Unk nown Source)
at java.lang.SecurityManager.checkPermission(Unknown Source)
at java.lang.SecurityManager.checkRead(Unknown Source)
at java.io.File.canRead(Unknown Source)
at javax.imageio.ImageIO.read(Unknown Source)
at ImageSlider.getImages(ImageSlider.java:48)
at ImageSlider.init(ImageSlider.java:15)
at sun.applet.AppletPanel.run(Unknown Source)
at java.lang.Thread.run(Unknown Source)
Jun 29 '07 #15
r035198x
13,262 MVP
Do you know what does the error mean?
Below is the error message shown in Java Console:


java.security.AccessControlException: access denied (java.io.FilePermission images\t1.gif read)
at java.security.AccessControlContext.checkPermission (Unknown Source)
at java.security.AccessController.checkPermission(Unk nown Source)
at java.lang.SecurityManager.checkPermission(Unknown Source)
at java.lang.SecurityManager.checkRead(Unknown Source)
at java.io.File.canRead(Unknown Source)
at javax.imageio.ImageIO.read(Unknown Source)
at ImageSlider.getImages(ImageSlider.java:48)
at ImageSlider.init(ImageSlider.java:15)
at sun.applet.AppletPanel.run(Unknown Source)
at java.lang.Thread.run(Unknown Source)
Read an applet tutorial and find out about how to display images on an applet. Applets are not allowed to open files on your computer unless they are signed. You need to use a URL and the code base for the path of the images.
Jun 29 '07 #16
fatfatpopo
16 New Member
Read an applet tutorial and find out about how to display images on an applet. Applets are not allowed to open files on your computer unless they are signed. You need to use a URL and the code base for the path of the images.
hmmm. i cannot signed for my applet because they give it to company but im only individual.
Jun 29 '07 #17
r035198x
13,262 MVP
hmmm. i cannot signed for my applet because they give it to company but im only individual.
Read my reply again. If you read the tutorial you will know how to display the images without needing to sign the applet.
Jun 29 '07 #18
fatfatpopo
16 New Member
Read my reply again. If you read the tutorial you will know how to display the images without needing to sign the applet.

Can tell me what changes must i make? because i view it very nicely at my appletviewer.. Thanks again
Jun 29 '07 #19
r035198x
13,262 MVP
Can tell me what changes must i make? because i view it very nicely at my appletviewer.. Thanks again
Please read* my responses.

*Reading - an extinct art that students used to get information (paraphrased from Jos)

We're not going anywhere here. I really would like it for you to read those tutorials.
Jun 29 '07 #20
fatfatpopo
16 New Member
Please read* my responses.

*Reading - an extinct art that students used to get information (paraphrased from Jos)

We're not going anywhere here. I really would like it for you to read those tutorials.
I have read from java tutorial and lots more.. But im quite confused over my problem.. If not i won't have stucked in the problem for so long..
Jun 29 '07 #21

Sign in to post your reply or Sign up for a free account.

Similar topics

1
by: Jason Charalambides | last post by:
I need to assign a slider to determine a percentage value for a certain variable in my program. I decided to use a slider so that the user will be able to manually set a value between 0.000... to...
5
by: Milagro | last post by:
Hi, I'm a perl/C programmer but a Javascript problem has been dumped into my lap. A client of mine has a freeware javascript on their site which shows a series of pictures on a web page in a...
1
by: dlarsson | last post by:
Music CD experts: So, here's my problem. I burned (or tried to burn) my first audio or music CD on my computer using Windows Media Player. I "Rip-ed" the tracks from a source CD and...
0
by: Brian Henry | last post by:
Ok I've never implemented a snap location before so I dont really know what im doing wrong here... anyways, I am making a custom slider control that takes dates as its values instead of integers......
0
by: PieMan2004 | last post by:
Greetings, Ive came across problems while doing a tutorial work piece. i've to design a toobar ( yup a JToolBar ) with 5 buttons inside it, that will do certain functions for a JSlider.( set...
5
by: murrayatuptowngallery | last post by:
I would like to have a slider or mouse position click capture means of collecting a user input from a scale or ruler-like graphic. I found some code snippets for mouse position capture on...
10
by: cjparis | last post by:
Hello everyone. If anyone can give me a hand I would be gratefull Am doing a site which requires a moving element and have used DHTML to do it. Have a simple Browser detect script to sort IE...
8
by: Philklc | last post by:
I'm working on a website which will use the Slider control from YUI. It runs when onDOMReady is executed. But my website has a global header that must be put on all pages, which has a site...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
1
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
0
muto222
php
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.