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

📄 tileaction.java

📁 java swing 开发代码
💻 JAVA
字号:
// TileAction.java// An action that tiles all internal frames when requested.//package	jswing.ch09;import javax.swing.*;import java.awt.event.*;import java.awt.*;import java.beans.*;public class TileAction extends AbstractAction {  private JDesktopPane desk; // the desktop to work with  public TileAction(JDesktopPane desk) {    super("Tile Frames");    this.desk = desk;  }  public void actionPerformed(ActionEvent ev) {    // How many frames do we have?    JInternalFrame[] allframes = desk.getAllFrames();    int count = allframes.length;    if (count == 0) return;    // Determine the necessary grid size    int sqrt = (int)Math.sqrt(count);    int rows = sqrt;    int cols = sqrt;    if (rows * cols < count) {      cols++;      if (rows * cols < count) {        rows++;      }    }    // Define some initial values for size & location.    Dimension size = desk.getSize();    int w = size.width / cols;    int h = size.height / rows;    int x = 0;    int y = 0;    // Iterate over the frames, deiconifying any iconified frames and then    // relocating & resizing each.    for (int i = 0; i < rows; i++) {      for (int j = 0; j < cols && ((i * cols) + j < count); j++) {        JInternalFrame f = allframes[(i * cols) + j];        if (!f.isClosed() && f.isIcon()) {          try {            f.setIcon(false);          }          catch (PropertyVetoException ignored) {}        }        desk.getDesktopManager().resizeFrame(f, x, y, w, h);        x += w;      }      y += h; // start the next row      x = 0;    }  }}

⌨️ 快捷键说明

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