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

📄 richjsframe.java

📁 Java自定义窗体JsFrame。简介见:http://jason0086.spaces.live.com/Blog/cns!A797D0C5C0C13C92!518.entry
💻 JAVA
字号:
package com.hfkj.jsframe.example; 

import java.awt.Toolkit;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.ComponentAdapter;
import java.awt.event.ComponentEvent;
import java.awt.event.WindowEvent;
import java.awt.event.WindowStateListener;
import java.io.File;
import java.util.ArrayList;

import javax.swing.JLabel;
import javax.swing.JMenu;
import javax.swing.JMenuBar;
import javax.swing.JMenuItem;
import javax.swing.JTextField;
import javax.swing.SwingUtilities;
import javax.swing.UIManager;
import javax.swing.UnsupportedLookAndFeelException;

import com.hfkj.jsframe.frame.JsFrame;
import com.hfkj.jsframe.frame.JsFrameLayout;
import com.sun.jna.examples.WindowUtils;

/**
 * A rich extended version of <code>JsFrame</code>:
 * <p>
 * <img src="doc-files/RichJsFrame.gif" alt="Diagram of a rich extended version of JsFrame.">
 * 
 * @version 1.0 01/05/09
 * @author Jason (MSN:www.jason0086.com@hotmail.com)
 */
public class RichJsFrame extends JsFrame {

	private static final long serialVersionUID = -6081458881391488180L;
	
	public static void main(String[] args) {
    	new RichJsFrame();
    }
    
    public RichJsFrame() {
    	super("RichJsFrame");
		this.setSize(900, 700);
		this.setLocation(150, 50);
		this.setVisible(true);
        // setup the icon for this frame
    	this.setIconImage(Toolkit.getDefaultToolkit().createImage(RichJsFrame.class.getResource("/img/logo.png")));
        // setup the menu portion for this frame
        JMenuBar xJmb = new JMenuBar();
        JMenu xJmn = new JMenu("Theme");
        xJmb.add(xJmn);
        JMenuItem xJmi = null;
		File[] fs = this.getFiles(new File("theme"), ".theme");
		final JsFrame frame = this; 
		if (fs != null) {
			int iThemeListSize = fs.length;
			for (int i=0; i<iThemeListSize; i++) {
				final String themeName = fs[i].getName().substring(0, fs[i].getName().lastIndexOf("."));
				xJmi = new JMenuItem(themeName);
				xJmi.addActionListener(
					new ActionListener() {
						public void actionPerformed(ActionEvent e) {
							try {
								UIManager.setLookAndFeel(NimRodLfUtils.getLookAndFeel("theme" + File.separator + themeName + ".theme"));
								SwingUtilities.updateComponentTreeUI(frame);
								frame.changeLookAndFeel();
							} catch (UnsupportedLookAndFeelException e1) {
								// TODO Auto-generated catch block
								e1.printStackTrace();
							}
						}
					}
				);
				xJmn.add(xJmi);
			}
		}
        this.add(xJmb, JsFrameLayout.MENU);
        // setup the content portion for this frame
        this.add(new JTextField("content"), JsFrameLayout.CONTENT);
        // setup the state portion for this frame
        this.add(new JLabel("state"), JsFrameLayout.STATE);
        /**
         * Setups the window mask based on the shape set in the corresponding <code>JsFrameBorder</code> for this frame.
         * The area inside the mask shape will be displayed normally, while that outside will be transparent.
         * @see com.hfkj.jsframe.border.JsFrameBorder#getMaskShape()
         */
		WindowUtils.setWindowMask(frame, frame.getBorder().getMaskShape());
    	// add the window state listener
    	this.addWindowStateListener(
    		new WindowStateListener() {
				public void windowStateChanged(WindowEvent e) {
					WindowUtils.setWindowMask(frame, frame.getBorder().getMaskShape());
				}
    		}
    	);
    	// add the component listener
    	this.addComponentListener(
    		new ComponentAdapter() {
				public void componentResized(ComponentEvent e) {
			    	WindowUtils.setWindowMask(frame, frame.getBorder().getMaskShape());
				}
    		}
    	);
        this.setVisible(true);
    }
    
	private File[] getFiles(final File dir, final String filter) {
		File[] fs = dir.listFiles();
		if ( (filter == null) 
				|| (filter.equals("")) ) {
			return fs;
		}
		String str = null;
		ArrayList<File> list = new ArrayList<File>();
		if (fs == null) {
			return null;
		}
		int fsLen = fs.length;
		for (int i=0; i<fsLen; i++) {
			if (fs[i].isDirectory()) {
				list.add(fs[i]);
			}
			else {
				str = fs[i].getName();
				if ( (str.lastIndexOf(filter) != -1) 
						&& (str.lastIndexOf(filter) + filter.length() == str.length()) ) {
					list.add(fs[i]);
				}
			}
		}
		if ( (list == null) 
				|| (list.size() == 0) ) {
			return null;
		}
		File[] fsReturn = new File[list.size()];
		int listLen = list.size();
		for (int i=0; i<listLen; i++) {
			fsReturn[i] = list.get(i);
		}
		return fsReturn;
	}
    
}     

⌨️ 快捷键说明

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