swingapplication.java.polystyle.backup

来自「我在学习JAVA的讲义」· BACKUP 代码 · 共 58 行

BACKUP
58
字号
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;

public class SwingApplication
	{
	private static String labelPrefix = "Number of buton clicks:";
	private int           numClicks = 0;

	public Component createComponents()
		{
		final JLabel label = new JLabel(labelPrefix + "0   ");
		JButton      button = new JButton("I'm a Swing button!");
		button.setMnemonic(KeyEvent.VK_I);
		button.addActionListener(new ActionListener()
			{
			public void actionPerformed(ActionEvent e)
				{
				numClicks++;
				label.setText(labelPrefix + numClicks);
				}
			});

		JPanel pane = new JPanel();
		pane.setBorder(BorderFactory.createEmptyBorder(30, 30, 10, 30));
		pane.setLayout(new GridLayout(0, 1));
		pane.add(button);
		pane.add(label);
		return pane;
		}

	public static void main(String args [])
		{
		try
			{
			UIManager.setLookAndFeel(UIManager.getCrossPlatformLookAndFeelClassName());
			}
		catch (Exception e)
			{
			}

		JFrame frame = new JFrame("SwingApplication");
		SwingApplication app = new SwingApplication();
		Component        contents = app.createComponents();
		frame.getContentPane().add(contents, BorderLayout.CENTER);
		frame.addWindowListener(new WindowAdapter()
			{
			public void windowClosing(WindowEvent e)
				{
				System.exit(0);
				}
			});

		frame.pack();
		frame.setVisible(true);
		}
	}

⌨️ 快捷键说明

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