buggybuttonpanel.java
来自「经典教材:java核心技术卷1、卷2的所有源代码」· Java 代码 · 共 44 行
JAVA
44 行
/**
@version 1.21 2002-07-06
@author Cay Horstmann
*/
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
class BuggyButtonPanel extends JPanel
{
public BuggyButtonPanel()
{
ActionListener listener = new ButtonListener();
JButton yellowButton = new JButton("Yellow");
add(yellowButton);
yellowButton.addActionListener(listener);
JButton blueButton = new JButton("Blue");
add(blueButton);
blueButton.addActionListener(listener);
JButton redButton = new JButton("Red");
add(redButton);
redButton.addActionListener(listener);
}
private class ButtonListener implements ActionListener
{
public void actionPerformed(ActionEvent event)
{
String arg = event.getActionCommand();
if (arg.equals("yellow"))
setBackground(Color.yellow);
else if (arg.equals("blue"))
setBackground(Color.blue);
else if (arg.equals("red"))
setBackground(Color.red);
}
}
}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?