debugwintest.java

来自「生产者消费者 生产者消费者」· Java 代码 · 共 61 行

JAVA
61
字号
/**
 * @version 1.20 06 May 1997
 * @author Cay Horstmann
 */


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

public class DebugWinTest extends JFrame 
   implements ActionListener
{  public DebugWinTest()
   {  setTitle("DebugWinTest");
      setSize(400, 400);
      addWindowListener(new WindowAdapter()
         {  public void windowClosing(WindowEvent e)
            {  System.exit(0);
            }
         } );

      pane = new JPanel();

      yellowButton = new JButton("Yellow");
      pane.add(yellowButton);
      yellowButton.addActionListener(this); 

      blueButton = new JButton("Blue");
      pane.add(blueButton);
      blueButton.addActionListener(this); 

      redButton = new JButton("Red");
      pane.add(redButton);
      redButton.addActionListener(this);

      getContentPane().add(pane);
   }
   
   public void actionPerformed(ActionEvent evt)
   {  dw.print("Event = " + evt);
      Object source = evt.getSource();
      Color color = getBackground();
      if (source == yellowButton) color = Color.yellow;
      else if (source == blueButton) color = Color.blue;
      else if (source == redButton ) color = Color.red;
      setBackground(color);
      repaint();
   }
   
   public static void main(String[] args)
   {  JFrame f = new DebugWinTest();
      f.show();
   }

   private JPanel pane;
   private JButton yellowButton;
   private JButton blueButton;
   private JButton redButton; 
   private DebugWin dw = new DebugWin();
}

⌨️ 快捷键说明

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