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

📄 test.java

📁 swing 教程,与大家分享一下,哈哈,希望大家多多指教
💻 JAVA
字号:
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
import java.util.*;

import com.sun.java.swing.plaf.motif.MotifLookAndFeel;
import com.sun.java.swing.plaf.windows.WindowsLookAndFeel;
import javax.swing.plaf.metal.MetalLookAndFeel;

import javax.swing.plaf.ColorUIResource;

public class Test extends JApplet {
	public void init() {
		Container contentPane = getContentPane();

		contentPane.add(new ControlPanel(), BorderLayout.NORTH);
		contentPane.add(new ComponentPanel(), 
						BorderLayout.CENTER);
	}
	class ComponentPanel extends JPanel {
		public ComponentPanel() {
			JList list;
			JScrollBar sb;

			setBorder(
				BorderFactory.createTitledBorder("Components"));

			add(new JCheckBox("check Me"));
			add(new JRadioButton("radio button"));
			add(new JButton("button"));
			add(new JLabel("A Label:"));
			add(new JTextField("text field"));
			add(new JScrollPane(list = new JList(new Object[] {
							"item 1", "item 2", "item 3",
							"item 4", "item 5", "item 6",
							"item 7", "item 8", "item 9",
							})));
			add(sb = new JScrollBar(SwingConstants.HORIZONTAL));
			sb.setPreferredSize(new Dimension(150,17));

			add(sb = new JScrollBar(SwingConstants.VERTICAL));
			sb.setPreferredSize(new Dimension(20,175));

			list.setVisibleRowCount(5);
		}
	}
	class ControlPanel extends JPanel {
		JCheckBox checkBox = new JCheckBox("UIResource");
		JRadioButton motifButton = new JRadioButton("Motif"),
					 windowsButton = new JRadioButton("Windows"),
					 metalButton = new JRadioButton("Metal");

		public ControlPanel() {
			ActionListener listener = new RadioHandler();
			ButtonGroup group = new ButtonGroup();

			group.add(motifButton);
			group.add(windowsButton);
			group.add(metalButton);

			motifButton.addActionListener(listener);
			windowsButton.addActionListener(listener);
			metalButton.addActionListener(listener);

			add(motifButton);
			add(windowsButton);
			add(metalButton);
		}
		class RadioHandler implements ActionListener {
			public void actionPerformed(ActionEvent e) {
				JRadioButton src = (JRadioButton)e.getSource();

				try {
					if(src == motifButton)
						UIManager.setLookAndFeel(
							"com.sun.java.swing.plaf." +
							"motif.MotifLookAndFeel");

					else if(src == windowsButton)
						UIManager.setLookAndFeel(
							"com.sun.java.swing.plaf." +
							"windows.WindowsLookAndFeel");

					else if(src == metalButton)
						UIManager.setLookAndFeel(
						  "javax.swing.plaf.metal." +
						  "MetalLookAndFeel");
				}
				catch(Exception ex) {
					ex.printStackTrace();
				}
				SwingUtilities.updateComponentTreeUI(
												getContentPane());
			}
		}
	}
}

⌨️ 快捷键说明

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