java中图片浏览器代码 java中图片浏览器代码有哪些

求一个java图片浏览器的源代码,拜托大家了?。。?/h2>给你代码java中图片浏览器代码 , 看一下注释,为是防止左右移动时鼠标是水平java中图片浏览器代码的移动,所以加了一个范轩,
在二十个象素内,认为是水平的 。
你看一下吧
还好你这个是鼠标按住移动,如果只是鼠移动就麻烦了
----------------------------------------
import java.awt.Graphics;
import java.awt.MouseInfo;
import java.awt.Point;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.MouseEvent;
import java.awt.event.MouseListener;
import java.io.File;
import javax.swing.ImageIcon;
import javax.swing.JButton;
import javax.swing.JFileChooser;
import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.filechooser.FileNameExtensionFilter;
public class App extends JFrame implements MouseListener, ActionListener {
int x = 0;
int y = 0;
File[] selectedFiles = null;
int fileIndex = 0;
int width = 200;
int height = 200;
public App() {
setDefaultCloseOperation(EXIT_ON_CLOSE);
setLocationRelativeTo(null);
setSize(400, 300);
setResizable(false);
getContentPane().setLayout(null);
JPanel panel = new ImagePanel();
panel.setBounds(12, 40, 370, 218);
getContentPane().add(panel);
addMouseListener(this);
JButton btnBrowse = new JButton("Browse");
btnBrowse.addActionListener(this);
btnBrowse.setBounds(12, 9, 91, 21);
getContentPane().add(btnBrowse);
setVisible(true);
}
public static void main(String[] args) {
new App();
}
public void actionPerformed(ActionEvent e) {
JFileChooser chooser = new JFileChooser();
chooser.setMultiSelectionEnabled(true);
FileNameExtensionFilter filter = new FileNameExtensionFilter(
"JPGGIF Images", "jpg", "gif");
// 设置文件类型
chooser.setFileFilter(filter);
// 打开选择器面板
int returnVal = chooser.showOpenDialog(this);
if (returnVal == JFileChooser.APPROVE_OPTION) {
selectedFiles = chooser.getSelectedFiles();
repaint();
}
}
public void mouseClicked(MouseEvent e) {
}
public void mouseEntered(MouseEvent e) {
}
public void mouseExited(MouseEvent e) {
}
public void mousePressed(MouseEvent e) {
Point point = MouseInfo.getPointerInfo().getLocation();
x = point.x;
y = point.y;
}
public void mouseReleased(MouseEvent e) {
Point point = MouseInfo.getPointerInfo().getLocation();
int thisX = point.x;
int thisY = point.y;
System.out.println("thisX=" + thisX + "" + "thisY=" + thisY);
if ((y - thisY20y - thisY0)
|| (y - thisY0y - thisY-20)) {
// Y 在20范围内移动认为是水平移动
if (xthisX) {
// right
if (selectedFiles != null
fileIndexselectedFiles.length - 1) {
fileIndex++;
}
} else {
// left
if (selectedFiles != nullfileIndex0) {
fileIndex--;
}
}
} else {
if (xthisX) {
// 右下
width += 20;
height += 20;
} else {
// 左上
width -= 20;
height -= 20;
}
}
repaint();
}
class ImagePanel extends JPanel {
public void paint(Graphics g) {
【java中图片浏览器代码 java中图片浏览器代码有哪些】super.paint(g);
if (selectedFiles != null) {
ImageIcon icon = new ImageIcon(selectedFiles[fileIndex]
.getPath());
g.drawImage(icon.getImage(), 0, 0, width, height, this);
}
}
}
}
请教java高手们 , 帮我写一个java编写的图片浏览器,功能如下:有自动浏览功能,每隔几秒图片自动翻页 。用//改编java中图片浏览器代码的java中图片浏览器代码,CopyOfImageViewer.java 打开一个有图片的文件夹就可浏览了 。

推荐阅读