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

📄 debuglayout.java

📁 java 完全探索的随书源码
💻 JAVA
字号:
// DebugLayout.java

import java.awt.*;

class DebugLayout implements LayoutManager
{
   public void addLayoutComponent (String name, Component comp)
   {
      System.out.println ("addLayoutComponent called");
      System.out.println ("name = " + name);
      System.out.println ("comp = " + comp);
   }

   public void removeLayoutComponent (Component comp)
   {
      System.out.println ("removeLayoutComponent called");
      System.out.println ("comp = " + comp);
   }

   public Dimension preferredLayoutSize (Container parent)
   {
      System.out.println ("preferredLayoutSize called");
      System.out.println ("parent = " + parent);
      return parent.getSize ();
   }

   public Dimension minimumLayoutSize (Container parent)
   {
      System.out.println ("minimumLayoutSize called");
      System.out.println ("parent = " + parent);
      return parent.getSize ();
   }

   public void layoutContainer (Container parent)
   {
      System.out.println ("layoutContainer called");
      System.out.println ("parent = " + parent);

      Component [] c = parent.getComponents ();

      if (c.length == 0)
          return;

      Dimension size = parent.getSize ();
      Insets in = parent.getInsets ();

      // Compute actual width and height by subtracting parent's
      // insets.

      int width = size.width - in.left - in.right;
      int height = size.height - in.top - in.bottom;

      // Each component will be laid out as a square.

      int cxy = (int) (Math.sqrt (width * height / c.length));

      int x = in.left;
      int y = in.top;

      for (int i = 0; i < c.length; i++)
      {
           if (c [i].isVisible ())
               c [i].setBounds (x, y, cxy, cxy);

           x += cxy;
           if (x >= width)
           {
               x = in.left;
               y += cxy;
           }
      }
   }
}

⌨️ 快捷键说明

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