⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 bounceexpressframe.java

📁 通过设置线程的优先级
💻 JAVA
字号:
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;

class BounceExpressFrame extends JFrame
{  public BounceExpressFrame()
   {  setSize(300, 200);
      setTitle("Bounce");

      addWindowListener(new WindowAdapter()
         {  public void windowClosing(WindowEvent e)
            {  System.exit(0);
            }
         } );

      Container contentPane = getContentPane();
      canvas = new JPanel();
      contentPane.add(canvas, "Center");
      JPanel p = new JPanel();
      addButton(p, "Start",
         new ActionListener()
         {  public void actionPerformed(ActionEvent evt)
            {  for (int i = 0; i < 5; i++)
               {  Ball b = new Ball(canvas, Color.black);
                  b.setPriority(Thread.NORM_PRIORITY);
                  b.start();
               }
            }
         });

      addButton(p, "Express",
         new ActionListener()
         {  public void actionPerformed(ActionEvent evt)
            {  for (int i = 0; i < 5; i++)
               {  Ball b = new Ball(canvas, Color.red);
                  b.setPriority(Thread.NORM_PRIORITY + 2);
                  b.start();
               }
            }
         });

      addButton(p, "Close",
         new ActionListener()
         {  public void actionPerformed(ActionEvent evt)
            {  canvas.setVisible(false);
               System.exit(0);
            }
         });
      contentPane.add(p, "South");
   }

   public void addButton(Container c, String title,
      ActionListener a)
   {  JButton b = new JButton(title);
      c.add(b);
      b.addActionListener(a);
   }

   private JPanel canvas;
}
	

⌨️ 快捷键说明

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