jframewithbuttons.java

来自「java编程开发技巧与实例的编译测试通过的所有例程」· Java 代码 · 共 59 行

JAVA
59
字号
import java.awt.FlowLayout;
import java.awt.Container;
import java.awt.event.*;
import javax.swing.*;

public class JFrameWithButtons extends JFrame implements ActionListener
{
	private JButton windLook	=	new JButton("widnow");
	private JButton unixLook	=	new JButton("unix");
	private JButton javaLook	=	new JButton("java");
	private JLabel	label		=	new JLabel("welcome to swing", SwingConstants.CENTER);
	private class WindowCloser extends WindowAdapter
	{
		public void windowClosing(WindowEvent we)
		{	System.exit(0);	}
	}
	public JFrameWithButtons()
	{
		super("jframe with buttons.");
		Container content	=	getContentPane();
		content.setLayout(new FlowLayout());
		content.add(label);
		content.add(windLook);
		windLook.addActionListener(this);
		content.add(unixLook);
		unixLook.addActionListener(this);
		content.add(javaLook);
		javaLook.addActionListener(this);
		addWindowListener(new WindowCloser());
		validate();
		pack();
		setVisible(true);
	}
	public void actionPerformed(ActionEvent ae)
	{
		String look	=	"javax.swing.plaf.metal.MetalLookAndFeel";
		if (ae.getSource() == javaLook)
			look = "javax.swing.plaf.metal.MetalLookAndFeel";
		else if (ae.getSource() == windLook)
			look = "com.sun.java.swing.plaf.windows.WindowsLookAndFeel";
		else if (ae.getSource() == unixLook)
			look = "com.sun.java.swing.plaf.motif.MotifLookAndFeel";
		try
		{
			UIManager.setLookAndFeel(look);
			SwingUtilities.updateComponentTreeUI(this);
			pack();
		}
		catch	(Exception e)
		{
			System.err.println("Exception: " + e);
		}
	}
	public static void main(String args[])
	{
		JFrameWithButtons jfb	=	new JFrameWithButtons();
	}
}

⌨️ 快捷键说明

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