class MainFrame extends JFrame implements TreeSelectionListener {
public JPanel viewPanel = new JPanel(new GridLayout(0, 4, 20, 20)); public JPanel includeviewPanel = new JPanel(new BorderLayout()); public JLabel label = new JLabel("选定:"); public JLabel stateLabel = new JLabel("未选定"); public JPanel statePanel = new JPanel(); FileNameExtensionFilter imageFilter = new FileNameExtensionFilter(null, "jpeg", "jpg", "png", "gif"); JFileChooser imageChooser = new JFileChooser(); public File copyFile; public File cutFile; public File directFile; public File[] imagePath; public JScrollPane scrollPane; public static JLabel previewLabel; public static JPanel previewPanel; public JPanel toolPanel; public JPanel treePanel; public JComboBox style;
public JMenuBar myMenuBar() { JMenuBar menuBar = new JMenuBar(); JMenu file = new JMenu("文件(F)", true); file.setMnemonic('F'); JMenu edit = new JMenu("编辑(E)", true); edit.setMnemonic('E'); JMenu help = new JMenu("帮助(H)", true); help.setMnemonic('H'); JMenuItem open = new JMenuItem("打开(O)", 'O'); open.setMnemonic('O'); open.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) { openFile(); } }); JMenuItem close = new JMenuItem("退出(C)", 'C'); close.setMnemonic('C'); close.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) { System.exit(0); } }); file.add(open); file.add(close); JMenuItem cut = new JMenuItem("剪切(T)", 'T'); cut.setMnemonic('T'); cut.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) { if ((stateLabel.getText()).equals("未选定")) { JOptionPane.showMessageDialog(null, "未选定文件"); } else { cut(stateLabel.getText()); } } }); JMenuItem copy = new JMenuItem("复制(Y)", 'Y'); copy.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) { if ((stateLabel.getText()).equals("未选定")) { JOptionPane.showMessageDialog(null, "未选定文件"); } else { copy(stateLabel.getText()); } } }); copy.setMnemonic('Y'); JMenuItem paste = new JMenuItem("粘贴(P)", 'P'); paste.setMnemonic('P'); paste.addActionListener(new ActionListener() {
public void openFile() { imageChooser.setFileFilter(imageFilter); int i = imageChooser.showOpenDialog(this); if (i == JFileChooser.APPROVE_OPTION) { File selectedFile = imageChooser.getSelectedFile(); if (imageChooser.getSelectedFile() != null) { String imageFile = selectedFile.toString(); ImageFrame imageFrame = new ImageFrame(imageFile); } selectedFile = null; } }
public JToolBar myToolBar() { JToolBar toolBar = new JToolBar(); JButton open = new JButton(new ImageIcon("icon/openIcon.png")); open.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) { openFile(); } }); JButton cut = new JButton(new ImageIcon("icon/cutIcon.png")); cut.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) { if ((stateLabel.getText()).equals("未选定")) { JOptionPane.showMessageDialog(null, "未选定文件"); } else { cut(stateLabel.getText()); } } }); JButton copy = new JButton(new ImageIcon("icon/copyIcon.png")); copy.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) { if ((stateLabel.getText()).equals("未选定")) { JOptionPane.showMessageDialog(null, "未选定文件"); } else { copy(stateLabel.getText()); } } }); JButton paste = new JButton(new ImageIcon("icon/pasteIcon.png")); paste.addActionListener(new ActionListener() {
public Image img = null; public File aPath; public JPanel viewPanel; public static File[] imagePath; public ImageIcon[] smallPicture; public JButton[] picButton; public ImageFrame imageFrame; public static JLabel stateLabel; public JScrollPane scrollBar; public static JButton choosedImage; public static JButton[] allButton;
public LoadImage(JPanel viewPanel,JScrollPane scrollPane, File[] imagePath, final JLabel stateLabel) { this.viewPanel = viewPanel; this.scrollBar = scrollPane; LoadImage.imagePath = imagePath; LoadImage.stateLabel = stateLabel; smallPicture = new ImageIcon[imagePath.length]; picButton = new JButton[imagePath.length]; allButton = picButton; for (int i = 0; i < imagePath.length; i++) { picButton[i] = new JButton(); picButton[i].addMouseListener(new MouseAdapter() {
private BufferedImage bufferedimage; private int Scalse;
DrawImage(Image image,int Value) { //按原图画出图像大小 int w = image.getWidth(null); int h = image.getHeight(null); float bi = w > h ? (float) h / (float) w : (float) w / (float) h; if (w > h) { w = Value; h = (int) (Value * bi); } else if (h > w) { h = Value; w = (int) (Value * bi); } else { w = Value; h = Value; } bufferedimage = new BufferedImage(w, h, BufferedImage.TYPE_INT_ARGB); Graphics2D g2D = bufferedimage.createGraphics(); g2D.setRenderingHint(RenderingHints.KEY_INTERPOLATION, RenderingHints.VALUE_INTERPOLATION_BILINEAR); g2D.drawImage(image, 0, 0, w, h, null); g2D.dispose(); }
DrawImage(Image image, int Width, int Height, int S) {//画出指定大小的图 Scalse = S; bufferedimage = new BufferedImage(Width * Scalse, Height * Scalse, BufferedImage.TYPE_INT_ARGB); Graphics2D g2D = bufferedimage.createGraphics(); g2D.setRenderingHint(RenderingHints.KEY_INTERPOLATION, RenderingHints.VALUE_INTERPOLATION_BILINEAR); g2D.drawImage(image, 0, 0, Width * Scalse, Height * Scalse, null); g2D.dispose(); }
public Image getImage() { return this.bufferedimage; } }
/* * To change this template, choose Tools | Templates * and open the template in the editor. */
public class ImageFrame extends JFrame implements ActionListener{
public JPanel imagePanel; public JPanel buttonPanel; public JPanel statePanel; public JLabel imageLabel; public JLabel stateLabel; public JButton before; public JButton play; public JButton stop; public JButton next; public JButton bigger; public JButton smaller; public File picFile; public Image img; public ImageIcon imageIcon; public String fileParent; FileNameExtensionFilter imageFilter = new FileNameExtensionFilter(null, "jpeg", "jpg", "png", "gif"); JFileChooser imageChooser = new JFileChooser(); public File filePath[]; public File imagePath[]; public int imageFileNumber = 0; public int locationImage = 0; public static ImageFrame myImageFrame; private PlayTimer playTimer; public Image[] imageOffer; public int scale = 8; public JScrollPane imageScrollPane;