corejava第7版
This commit is contained in:
1 parent
e89542a214
commit
fa8d1a5860
493 files changed
+105995
No files matched your search
@@ -0,0 +1,43 @@
|
||||
/**
|
||||
@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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user