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

📄 plafdemo.java

📁 点击按钮切换JAVA的显示样式
💻 JAVA
字号:
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;

/**
 * A  panel vith buttons to change the pluggable look and feel
 */
class PlafPanel extends JPanel
{
	public PlafPanel()
	{
		makeButton("Metal", "javax.swing.plaf.metal.MetalLookAndFeel");
		makeButton("Motif", "com.sun.java.swing.plaf.motif.MotifLookAndFeel");
		makeButton("Windows", "com.sun.java.swing.plaf.windows.WindowsLookAndFeel");
	}
	/**
     * Makes a button to change the pluggable look and feel
     *@param name the button name
     *@param plafName the name of the look and feel
     */	
    void makeButton(String name, final String plafName)
    {
    	//add button to panel
    	JButton button = new JButton(name);//问题,这个局部变量button,不会消失吗?
    	add(button);	
    	//set button action
    	button.addActionListener(
    		new ActionListener()
    		{
    			public void actionPerformed(ActionEvent event)
    			{
    				//button action:switch to the new look and feel
    				try
    				{
    					UIManager.setLookAndFeel(plafName);
    					SwingUtilities.updateComponentTreeUI(PlafPanel.this);	
    				}	
    				catch(Exception e)
    				{
    					
    				}
    			}
       		});
    }
    
    
}
/**
 * A frame with a button panel for changing look and feel
 */
class PlafFrame extends JFrame
{
	public static final int DEFAULT_WIDTH = 300;
	public static final int DEFAULT_HEIGHT = 200;
	public PlafFrame()
	{
		setTitle("PlafTest");
		setSize(DEFAULT_WIDTH, DEFAULT_HEIGHT);
		//add panel to frame
		PlafPanel panel = new PlafPanel();
		getContentPane().add(panel);	
	}	
	
}

public class PlafDemo
{
	public static void main(String args[])
	{
		PlafFrame frame = new PlafFrame();
		frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
		frame.show();		
	}
}

⌨️ 快捷键说明

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