例如,亚马逊有关于要约的幻灯片,我们单击任何图像。它将我们引向相应页面...这背后的逻辑是什么。 谁能帮忙.. 当我创建幻灯片
package tryButton;
import java.awt.Color;
import java.awt.Image;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.*;
public class Slider extends JFrame{
JLabel pic;
Timer tm;
int x = 0;
//Images Path In Array
String[] list = {
"/home/akshay/Documents/images/image1.jpeg",//0
"/home/akshay/Documents/images/image2.jpeg",//1
"/home/akshay/Documents/images/image3.jpg",//2
"/home/akshay/Documents/images/image4.jpg",//3
"/home/akshay/Documents/images/image5.jpg",//4
"/home/akshay/Documents/images/image6.png",//5
//"C:/Users/samsng/Desktop/jv7.jpg"//6
};
public Slider(){
//super("Java SlideShow");
pic = new JLabel();
pic.setBounds(40, 30, 700, 300);
//Call The Function SetImageSize
SetImageSize(5);
//set a timer
tm = new Timer(2000,new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
SetImageSize(x);
x += 1;
if(x >= list.length )
x = 0;
}
});
add(pic);
tm.start();
setLayout(null);
setSize(800, 400);
getContentPane().setBackground(Color.decode("#bdb67b"));
setLocationRelativeTo(null);
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
setVisible(true);
}
//create a function to resize the image
public void SetImageSize(int i){
ImageIcon icon = new ImageIcon(list[i]);
Image img = icon.getImage();
Image newImg = img.getScaledInstance(pic.getWidth(), pic.getHeight(), Image.SCALE_SMOOTH);
ImageIcon newImc = new ImageIcon(newImg);
pic.setIcon(newImc);
}
public static void main(String[] args){
new Slider();
}
}
我想如果我单击幻灯片中的任何图像,它将把我定向到特定页面