java图片浏览器代码 java实现浏览器( 三 )


if(sf==null || sf.length==0)return;
pl.setIcon(new ImageIcon(sf[index].getAbsolutePath()));
System.out.println(sf[index].getAbsolutePath());
}
}
java swing编写的图片浏览器不显示图片,这是文件选择器的代码关于样式显示不出来:1.检查样式的书写格式是否正确,如:style/style可能无效,尝试style type="text/css"/style 另外,检查样式代码中是否缺少结束标识符 。2.如果是引用的外部样式文件,检查下路径是否正确!3.部分样式无效,检查选择器是否正确,如样式定义为:#box,检查标签是否为:div id="box"/div,防止class和id混淆 。4.动态页面有时候需要多刷新几下更新缓存 。多刷新几下确保样式被重新加载 。5.样式兼容性,这个就比较特殊了,检查你的样式整体设计是否合理 。有时候浮动、高度等设置不当,导致页面无法正常显示,另外,标签或属性的书写错误也会导致样式执行失效 。
用java编写一个图片浏览器import java.awt.BorderLayout;
import java.awt.Graphics;
import java.awt.GridLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.io.File;
import java.util.ArrayList;
import javax.swing.ImageIcon;
import javax.swing.JButton;
import javax.swing.JFileChooser;
import javax.swing.JFrame;
import javax.swing.JMenu;
import javax.swing.JMenuBar;
import javax.swing.JMenuItem;
import javax.swing.JPanel;
public class ImageGallery extends JFrame implements ActionListener {
public static final int G_WIDTH = 400, G_HEIGHT = 620;
public static final int L_WIDTH = 1200, L_HEIGHT = 520;
public static final int MAX_R = 3, MAX_C = 2;
public static final int GRID = 1, LARGE = 2;
private JFileChooser chooser;
private JMenuBar toolBar;
private JMenu menu;
private JMenuItem open;
private ArrayListString paths;
private JPanel showingPanel, buttonPanel;
private int page = 1;
private int count = 0;
private int showType = GRID;
private int pageMax;
private JButton last, next, large, grid;
public ImageGallery() {
this.setTitle("Image gallery 0.1");
this.setBounds(100, 100, G_WIDTH, G_HEIGHT);
this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
toolBar = new JMenuBar();
chooser = new JFileChooser();
chooser.setCurrentDirectory(new java.io.File("."));
chooser.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY);
menu = new JMenu("File");
toolBar.add(menu);
open = new JMenuItem("open");
open.addActionListener(this);
menu.add(open);
paths = new ArrayListString();
this.setJMenuBar(toolBar);
showingPanel = new JPanel();
buttonPanel = new JPanel();
last = new JButton("last");
last.addActionListener(this);
next = new JButton("next");
next.addActionListener(this);
large = new JButton("large");
large.addActionListener(this);
grid = new JButton("grid");
grid.addActionListener(this);
buttonPanel.add(last);
buttonPanel.add(large);
buttonPanel.add(grid);
buttonPanel.add(next);
this.add(buttonPanel, BorderLayout.SOUTH);
this.add(showingPanel);
this.setVisible(true);
}
public void doOpen() {
int result = chooser.showOpenDialog(null);
if (result == JFileChooser.APPROVE_OPTION) {
String directory = chooser.getSelectedFile().getPath();
this.getAllImage(directory);
for (String s : this.paths) {
System.out.println(s);
}
this.showingImage();
}
}
public void getAllImage(String directory) {
paths.clear();
page = 1;
count = 0;
File file = new File(directory);
if (file.isDirectory()) {
String[] list = file.list();

推荐阅读