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

📄 ch06_04.java

📁 learn to use eclipse by example
💻 JAVA
字号:
/*
 * Created on Nov 3, 2003
 *
 * To change the template for this generated file go to
 * Window>Preferences>Java>Code Generation>Code and Comments
 */
package org.eclipsebook.ch06;

import java.awt.*;
import javax.swing.*;
import java.awt.event.*;

/**
 * @author Steven Holzner
 *
 * To change the template for this generated type comment go to
 * Window>Preferences>Java>Code Generation>Code and Comments
 */
public class Ch06_04 extends JFrame {
	JRadioButton b1 = new JRadioButton("Metal"),
	b2 = new JRadioButton("Motif"),
	b3 = new JRadioButton("Windows");

	public Ch06_04() {
		super("Swing application");

		Container contentPane = getContentPane();
		contentPane.add(new Panel(), BorderLayout.CENTER);
	}

	public static void main(String args[]) 
	{
		final JFrame f = new Ch06_04();

		f.setBounds(100, 100, 300, 300);
		f.setVisible(true);
		f.setDefaultCloseOperation(DISPOSE_ON_CLOSE);
		
		f.addWindowListener(new WindowAdapter() {
			public void windowClosing(WindowEvent e) {
				System.exit(0);
			}
		});
	}

	class Panel extends JPanel implements ActionListener
	{
		public Panel() 
		{
			add(new JButton("JButton"));
			add(new JTextField("JTextField"));
			add(new JCheckBox("JCheckBox"));
			add(new JRadioButton("JRadioButton"));
			add(new JLabel("JLabel"));
			add(new JList(new String[] {
				"JList Item 1", "JList Item 2", "JList Item 3"}));
			add(new JScrollBar(SwingConstants.HORIZONTAL));

			ButtonGroup group = new ButtonGroup();
			group.add(b1);
			group.add(b2);
			group.add(b3);

			b1.addActionListener(this);
			b2.addActionListener(this);
			b3.addActionListener(this);

			add(b1);
			add(b2);
			add(b3);
		}

		public void actionPerformed(ActionEvent e) 
		{
			JRadioButton src = (JRadioButton)e.getSource();

			try {
				if((JRadioButton)e.getSource() == b1)
					UIManager.setLookAndFeel(
					  "javax.swing.plaf.metal.MetalLookAndFeel");
				else if((JRadioButton)e.getSource() == b2)
					UIManager.setLookAndFeel(
						"com.sun.java.swing.plaf.motif.MotifLookAndFeel");
				else if((JRadioButton)e.getSource() == b3)
					UIManager.setLookAndFeel(
						"com.sun.java.swing.plaf.windows.WindowsLookAndFeel");
			}
			catch(Exception ex) {}

			SwingUtilities.updateComponentTreeUI(getContentPane());
		}
	}
}

⌨️ 快捷键说明

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