⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 mypicdemo.java

📁 Java 简易小相册.帮你理解Drag and Drop 的功能.
💻 JAVA
字号:

import java.awt.BorderLayout;
import java.awt.Dimension;
import java.awt.GridLayout;
import java.awt.Image;

import javax.swing.BorderFactory;
import javax.swing.ImageIcon;
import javax.swing.JFrame;
import javax.swing.JPanel;

/*
 * Created on 2/07/2006
 *
 * TODO To change the template for this generated file go to
 * Window - Preferences - Java - Code Style - Code Templates
 */

/**
 * @author Xuesong Le
 * 
 * TODO To change the template for this generated type comment go to Window -
 * Preferences - Java - Code Style - Code Templates
 */
public class MyPicDemo extends JPanel
{

    private static final long serialVersionUID = 1L;

    MyPicComponent[]
                   picComps = null;
    
    int
    	NUM_PIC_COMP = 9;
    
       
    public MyPicDemo()
    {
        super(new BorderLayout());
        MyTransferHandler
        	picHandler = new MyTransferHandler();

        picComps = new  MyPicComponent[NUM_PIC_COMP];
       
        JPanel 
        	picPanel = new JPanel(new GridLayout(3, 3));
        
       // Initialize picComp
       for(int i=0; i< NUM_PIC_COMP; i++)
       {
           // Make MyPicComponent
           MyPicComponent
           	picComp = new MyPicComponent(null);
           // Make a FocusListener
           MyFocusListener
           	focusHandler = new MyFocusListener(picComp);
           // Make a Mouse Handler
           MyMouseHandler
           	mouseHandler = new MyMouseHandler(picComp);
           // Add to the picComp
           picComp.addFocusListener(focusHandler);
           picComp.addMouseListener(mouseHandler);
           picComp.addMouseMotionListener(mouseHandler);
           // Add TransferHandler
           picComp.setTransferHandler(picHandler);
           // Add to picPanel
           picPanel.add(picComp);
           picComps[i] = picComp;
           
       }// End for
        
       // Add Initial 6 Images
       for(int j=0; j<6; j++)
       {
           ImageIcon
           	imgIcon = new ImageIcon("images/" + j + ".jpg",null);
           Image
           	img = imgIcon.getImage();
           picComps[j].setImage(img);
       }// End for
       
       setPreferredSize(new Dimension(800,968));
       add(picPanel, BorderLayout.CENTER);
       setBorder(BorderFactory.createEmptyBorder(20,20,20,20));
       
    }
    
    /**
     * Create the GUI and show it. For thread safety, this method should be
     * invoked from the event-dispatching thread.
     */
    private static void createAndShowGUI()
    {
        //Make sure we have nice window decorations.
        JFrame.setDefaultLookAndFeelDecorated(true);

        //Create and set up the window.
        JFrame frame = new JFrame("MyPictureDemo");
        frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

        //Create and set up the menu bar and content pane.
        MyPicDemo demo = new MyPicDemo();
        demo.setOpaque(true); //content panes must be opaque
        frame.setContentPane(demo);

        //Display the window.
        frame.pack();
        frame.setVisible(true);
    }

    public static void main(String[] args)
    {
        //Schedule a job for the event-dispatching thread:
        //creating and showing this application's GUI.
        javax.swing.SwingUtilities.invokeLater(new Runnable() {
            public void run() {
                createAndShowGUI();
            }
        });
    }
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -