當前位置: 首頁>>代碼示例>>Java>>正文


Java Frame.pack方法代碼示例

本文整理匯總了Java中java.awt.Frame.pack方法的典型用法代碼示例。如果您正苦於以下問題:Java Frame.pack方法的具體用法?Java Frame.pack怎麽用?Java Frame.pack使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在java.awt.Frame的用法示例。


在下文中一共展示了Frame.pack方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: main

import java.awt.Frame; //導入方法依賴的package包/類
public static void main(final String[] args) {
    final Dimension expected = new Dimension(300, 300);
    final Frame frame = new Frame();
    final ScrollPane sp = new ScrollPane();
    sp.setSize(expected);
    frame.add(sp);
    frame.pack();
    frame.setLocationRelativeTo(null);
    frame.setVisible(true);
    sleep();
    final Dimension size = frame.getSize();
    if (size.width < expected.width || size.height < expected.height) {
        throw new RuntimeException(
                "Expected size: >= " + expected + ", actual size: " + size);
    }
    frame.dispose();
}
 
開發者ID:AdoptOpenJDK,項目名稱:openjdk-jdk10,代碼行數:18,代碼來源:ScrollPanePreferredSize.java

示例2: main

import java.awt.Frame; //導入方法依賴的package包/類
public static void main(final String[] args) {
    final Frame frame = new Frame();
    final TextArea ta = new TextArea();
    frame.add(ta);
    frame.pack();
    frame.setVisible(true);
    sleep();
    final Dimension before = frame.getSize();
    frame.pack();
    final Dimension after = frame.getSize();
    if (!after.equals(before)) {
        throw new RuntimeException(
                "Expected size: " + before + ", actual size: " + after);
    }
    frame.dispose();
}
 
開發者ID:lambdalab-mirror,項目名稱:jdk8u-jdk,代碼行數:17,代碼來源:TextAreaTwicePack.java

示例3: main

import java.awt.Frame; //導入方法依賴的package包/類
public static void main(String args[]) throws Exception {
    Frame frame = new Frame("Frame Minimize Test");
    Button b = new Button("Focus ownder");
    frame.add("South", b);
    frame.pack();
    frame.setVisible(true);
    Util.waitForIdle(null);
    if (!b.hasFocus()) {
        throw new RuntimeException("button is not a focus owner after showing :(");
    }
    frame.setExtendedState(Frame.ICONIFIED);
    Util.waitForIdle(null);
    frame.setExtendedState(Frame.NORMAL);
    Util.waitForIdle(null);
    if (!b.hasFocus()) {
        throw new RuntimeException("button is not a focus owner after restoring :(");
    }
}
 
開發者ID:AdoptOpenJDK,項目名稱:openjdk-jdk10,代碼行數:19,代碼來源:FrameMinimizeTest.java

示例4: Unit

import java.awt.Frame; //導入方法依賴的package包/類
public Unit(){
    getBestSize();

    net = new Net(new int[]{4,5,4}, true);
    graph = new TimeGraph(net,0,GAME_HEIGHT-200,GAME_WIDTH, 200, "errorRate");

    frame = new Frame();
    canvas = new Canvas();

    canvas.setPreferredSize(new Dimension(canvasWidth, canvasHeight));
    canvas.addKeyListener(new InputHandler());
    canvas.addMouseListener(new InputHandler());
    canvas.addMouseMotionListener(new InputHandler());

    frame.add(canvas);

    frame.pack();
    frame.setResizable(false);
    frame.setLocationRelativeTo(null);

    frame.addWindowListener(new WindowAdapter(){
        @Override
        public void windowClosing(WindowEvent e){
            Test.quit(net);
        }
    });

    frame.setVisible(true);
    gc = canvas.getGraphicsConfiguration();
    vImage = gc.createCompatibleVolatileImage(GAME_WIDTH, GAME_HEIGHT);

}
 
開發者ID:dstallenberg,項目名稱:SimpleRecurrentNetwork,代碼行數:33,代碼來源:Unit.java

示例5: main

import java.awt.Frame; //導入方法依賴的package包/類
public static void main(String args[]) {
    Frame f = new Frame("DitherTest");
    DitherTest ditherTest = new DitherTest();
    ditherTest.init();
    f.add("Center", ditherTest);
    f.pack();
    f.setVisible(true);
    ditherTest.start();
}
 
開發者ID:SunburstApps,項目名稱:OpenJSharp,代碼行數:10,代碼來源:DitherTest.java

示例6: main

import java.awt.Frame; //導入方法依賴的package包/類
public static void main(String[] args) throws InterruptedException, java.lang.reflect.InvocationTargetException
{
    final Frame frame = new Frame("the test");
    frame.setLayout(new FlowLayout());
    final Button btn1 = new Button("button 1");
    frame.add(btn1);
    frame.add(new Button("button 2"));
    frame.add(new Button("button 3"));
    frame.pack();
    frame.setVisible(true);

    Robot r = Util.createRobot();
    Util.waitForIdle(r);
    Util.clickOnComp(btn1, r);
    Util.waitForIdle(r);
    KeyboardFocusManager kfm = KeyboardFocusManager.getCurrentKeyboardFocusManager();
    if (kfm.getFocusOwner() != btn1) {
        throw new RuntimeException("test error: can not set focus on " + btn1 + ".");
    }

    EventQueue.invokeAndWait(new Runnable() {
            public void run() {
                final int n_comps = frame.getComponentCount();
                for (int i = 0; i < n_comps; ++i) {
                    frame.getComponent(i).setVisible(false);
                }
            }
        });
    Util.waitForIdle(r);
    final Component focus_owner = kfm.getFocusOwner();

    if (focus_owner != null && !focus_owner.isVisible()) {
        throw new RuntimeException("we have invisible focus owner");
    }
    System.out.println("test passed");
    frame.dispose();
}
 
開發者ID:lambdalab-mirror,項目名稱:jdk8u-jdk,代碼行數:38,代碼來源:RequestFocusAndHideTest.java

示例7: main

import java.awt.Frame; //導入方法依賴的package包/類
public static void main(String[] args) {
    final DrawXORModeTest c = new DrawXORModeTest();

    final Frame f = new Frame("XOR mode test");
    f.add(c);
    f.pack();

    f.setVisible(true);

    try {
        c.checkResult();
    } finally {
        f.dispose();
    }
}
 
開發者ID:AdoptOpenJDK,項目名稱:openjdk-jdk10,代碼行數:16,代碼來源:DrawXORModeTest.java

示例8: SharedMemoryPixmapsTest

import java.awt.Frame; //導入方法依賴的package包/類
/** Creates a new instance of SharedMemoryPixmapsTest */
public SharedMemoryPixmapsTest() {
    testFrame = new Frame("SharedMemoryPixmapsTest");
    testFrame.add(new TestComponent());
    testFrame.setUndecorated(true);
    testFrame.setResizable(false);
    testFrame.pack();
    testFrame.setLocationRelativeTo(null);
    testFrame.setVisible(true);
    testFrame.toFront();
}
 
開發者ID:lambdalab-mirror,項目名稱:jdk8u-jdk,代碼行數:12,代碼來源:SharedMemoryPixmapsTest.java

示例9: frameTest

import java.awt.Frame; //導入方法依賴的package包/類
private static void frameTest() {
    Panel panel =new Panel();

    print = new Button("PageDialog");
    print.setActionCommand("PageDialog");
    print.addActionListener((e) -> {
        PrinterJob job = PrinterJob.getPrinterJob();
            PrintRequestAttributeSet aset = new HashPrintRequestAttributeSet();
            t.start();
            start = true;
            PageFormat pf = job.pageDialog(aset);
    });

    panel.add(print);

    frame = new Frame("Test Frame");
    frame.setLayout (new BorderLayout ());
    frame.add(panel,"South");
    frame.pack();
    frame.setVisible(true);

    t = new Thread (() -> {
        if (start) {
            try {
                Thread.sleep(5000);
            } catch (InterruptedException ex) {}
            frame.dispose();
        }
    });
}
 
開發者ID:AdoptOpenJDK,項目名稱:openjdk-jdk10,代碼行數:31,代碼來源:TestPageDlgFrameAssociation.java

示例10: testFrame

import java.awt.Frame; //導入方法依賴的package包/類
static void testFrame(boolean isUndecorated) throws Exception {
    Frame frame = new Frame();
    try {
        Robot robot = new Robot();
        robot.setAutoDelay(100);

        frame.setUndecorated(isUndecorated);
        GraphicsConfiguration gc = GraphicsEnvironment.getLocalGraphicsEnvironment()
                .getDefaultScreenDevice().getDefaultConfiguration();
        Rectangle bounds = gc.getBounds();
        Insets insets = Toolkit.getDefaultToolkit().getScreenInsets(gc);
        int x = bounds.x + insets.left;
        int y = bounds.y + insets.top;
        int width = bounds.width - insets.left - insets.right;
        int height = bounds.height - insets.top - insets.bottom;
        Rectangle rect = new Rectangle(x, y, width, height);
        frame.pack();
        frame.setBounds(rect);
        frame.setVisible(true);
        robot.waitForIdle();
        robot.delay(500);

        if (frame.getWidth() <= width / 2
                || frame.getHeight() <= height / 2) {
            throw new RuntimeException("Frame size is small!");
        }

        if (!isUndecorated && frame.getExtendedState() != Frame.MAXIMIZED_BOTH) {
            throw new RuntimeException("Frame state does not equal"
                    + " MAXIMIZED_BOTH!");
        }
    } finally {
        frame.dispose();
    }
}
 
開發者ID:AdoptOpenJDK,項目名稱:openjdk-jdk10,代碼行數:36,代碼來源:MaximizedToUnmaximized.java

示例11: main

import java.awt.Frame; //導入方法依賴的package包/類
public static void main(String[] args) {
    System.setProperty("sun.java2d.pmoffscreen", "true");
    System.setProperty("sun.java2d.ddforcevram", "true");
    String name = "red.jpg";

    f = new Frame();
    f.pack();

    if (f.getGraphicsConfiguration().getColorModel().getPixelSize() < 16) {
        System.err.println("8-bit display mode detected, dithering issues possible, "+
                           "considering test passed.");
        f.dispose();
        return;
    }


    for (String arg : args) {
        if (arg.equals("-write")) {
            writeTestImage(name);
            System.exit(0);
        } else if (arg.equals("-show")) {
            showRes = true;
        } else if (arg.equals("-low")) {
            lowCompression = true;
            name ="red_low.jpg";
            System.err.println("Using low jpeg compression");
        } else if (arg.equals("-help")) {
            usage();
        } else {
            final String filename = arg;
            testsStarted++;
            new Thread(new Runnable() {
                public void run() {
                    new JPEGsNotAcceleratedTest(filename);
                }
            }).start();
        }
    }

    if (testsStarted == 0) {
        writeTestImage(name);
        testsStarted++;
        new JPEGsNotAcceleratedTest(name);
    }


    synchronized (JPEGsNotAcceleratedTest.class) {
        while (testsFinished < testsStarted) {
            try {
                JPEGsNotAcceleratedTest.class.wait(100);
            } catch (InterruptedException e) {
                failed = true; break;
            }
        }
    }

    f.dispose();
    if (failed) {
        throw new RuntimeException("Test failed");
    }

    System.err.println("Passed.");
}
 
開發者ID:AdoptOpenJDK,項目名稱:openjdk-jdk10,代碼行數:64,代碼來源:JPEGsNotAcceleratedTest.java

示例12: main

import java.awt.Frame; //導入方法依賴的package包/類
public static void main(String[] args) {
    boolean show = false;
    for (String arg : args) {
        if ("-show".equals(arg)) {
            show = true;
        }
    }

    String arch = System.getProperty("os.arch");
    boolean isOglEnabled = Boolean.getBoolean("sun.java2d.opengl");
    skipOglTextureTest = isOglEnabled && ("sparc".equals(arch));
    System.out.println("Skip OpenGL texture test: " + skipOglTextureTest);

    DrawImageBilinear test = new DrawImageBilinear();
    Frame frame = new Frame();
    frame.add(test);
    frame.pack();
    frame.setVisible(true);

    // Wait until the component's been painted
    synchronized (test) {
        while (!done) {
            try {
                test.wait();
            } catch (InterruptedException e) {
                throw new RuntimeException("Failed: Interrupted");
            }
        }
    }

    GraphicsConfiguration gc = frame.getGraphicsConfiguration();
    if (gc.getColorModel() instanceof IndexColorModel) {
        System.out.println("IndexColorModel detected: " +
                           "test considered PASSED");
        frame.dispose();
        return;
    }

    if (!show) {
        frame.dispose();
    }
    if (capture == null) {
        throw new RuntimeException("Failed: capture is null");
    }

    // Test background color
    int pixel = capture.getRGB(5, 5);
    if (pixel != 0xffffffff) {
        throw new RuntimeException("Failed: Incorrect color for " +
                                   "background");
    }

    // Test pixels
    testRegion(capture, new Rectangle(10, 10, 40, 40));
    testRegion(capture, new Rectangle(80, 10, 40, 40));
    testRegion(capture, new Rectangle(150, 10, 40, 40));
}
 
開發者ID:AdoptOpenJDK,項目名稱:openjdk-jdk10,代碼行數:58,代碼來源:DrawImageBilinear.java

示例13: createInstructionUI

import java.awt.Frame; //導入方法依賴的package包/類
private void createInstructionUI() {
    mainFrame = new Frame("Drag and drop link from web browser");
    layout = new GridBagLayout();
    mainControlPanel = new Panel(layout);
    resultButtonPanel = new Panel(layout);

    GridBagConstraints gbc = new GridBagConstraints();
    String instructions
            = "INSTRUCTIONS:"
            + "\n   1. Open any browser."
            + "\n   2. Select and drag URL from the browser page and "
            + "drop it on the panel"
            + "\n   3. If test fails, then a popup message will be displayed,"
            + " click Ok and \n       click Fail button."
            + "\n   5. Otherwise test passed. Click Pass button.";

    instructionTextArea = new TextArea();
    instructionTextArea.setText(instructions);
    instructionTextArea.setEnabled(false);
    instructionTextArea.setBackground(Color.white);

    gbc.gridx = 0;
    gbc.gridy = 0;
    gbc.fill = GridBagConstraints.HORIZONTAL;
    mainControlPanel.add(instructionTextArea, gbc);

    passButton = new Button("Pass");
    passButton.setName("Pass");
    passButton.addActionListener(this);

    failButton = new Button("Fail");
    failButton.setName("Fail");
    failButton.addActionListener(this);

    gbc.gridx = 0;
    gbc.gridy = 0;
    resultButtonPanel.add(passButton, gbc);
    gbc.gridx = 1;
    gbc.gridy = 0;
    resultButtonPanel.add(failButton, gbc);
    gbc.gridx = 0;
    gbc.gridy = 1;
    mainControlPanel.add(resultButtonPanel, gbc);

    mainFrame.add(mainControlPanel);
    mainFrame.pack();
    mainFrame.setVisible(true);
}
 
開發者ID:AdoptOpenJDK,項目名稱:openjdk-jdk10,代碼行數:49,代碼來源:DragLinkFromBrowser.java

示例14: createInstructionUI

import java.awt.Frame; //導入方法依賴的package包/類
private void createInstructionUI() {
    mainFrame = new Frame("Updating TrayIcon Popup Menu Item Test");
    layout = new GridBagLayout();
    mainControlPanel = new Panel(layout);
    resultButtonPanel = new Panel(layout);

    GridBagConstraints gbc = new GridBagConstraints();
    String instructions
            = "INSTRUCTIONS:"
            + "\n   1. Click on the System Tray Icon"
            + "\n   2. Click on any of the displayed Menu items"
            + "\n   3. Repeat step 1 and count the number of items in the "
            + "Menu"
            + "\n   4. The number of items in the Menu should increase by 1"
            + "\n   5. Repeating steps 1, 2 and 3 should not break 4th step"
            + "\n   6. Click Fail if the 4th step is broken, Otherwise "
            + "click Pass ";

    instructionTextArea = new TextArea();
    instructionTextArea.setText(instructions);
    instructionTextArea.setEnabled(false);
    instructionTextArea.setBackground(Color.white);

    gbc.gridx = 0;
    gbc.gridy = 0;
    gbc.fill = GridBagConstraints.HORIZONTAL;
    mainControlPanel.add(instructionTextArea, gbc);

    passButton = new Button("Pass");
    passButton.setName("Pass");
    passButton.addActionListener(this);

    failButton = new Button("Fail");
    failButton.setName("Fail");
    failButton.addActionListener(this);

    gbc.gridx = 0;
    gbc.gridy = 0;
    resultButtonPanel.add(passButton, gbc);
    gbc.gridx = 1;
    gbc.gridy = 0;
    resultButtonPanel.add(failButton, gbc);
    gbc.gridx = 0;
    gbc.gridy = 1;
    mainControlPanel.add(resultButtonPanel, gbc);

    mainFrame.add(mainControlPanel);
    mainFrame.pack();
    mainFrame.setVisible(true);
}
 
開發者ID:AdoptOpenJDK,項目名稱:openjdk-jdk10,代碼行數:51,代碼來源:UpdatePopupMenu.java

示例15: createInstructionUI

import java.awt.Frame; //導入方法依賴的package包/類
private void createInstructionUI() {
    instructionFrame = new Frame("Native Print Dialog and Page Dialog");
    layout = new GridBagLayout();
    mainControlPanel = new Panel(layout);
    resultButtonPanel = new Panel(layout);

    GridBagConstraints gbc = new GridBagConstraints();
    String instructions
            = "\nINSTRUCTIONS:\n"
            + "\n   1. Click on the 'show a native print dialog' button. A "
            + "native print dialog will come up."
            + "\n   2. Click on the 'Cancel' button on Mac OS X or "
            + "'close'(X) on other paltforms. Dialog will be closed."
            + "\n   3. After the dialog is closed another window should "
            + "become the active window."
            + "\n   4. If there no any active window then the test has "
            + "failed. Click on 'Fail' Button."
            + "\n   5. Click on the 'show a native page dialog' button. A "
            + "native page dialog will come up."
            + "\n   6. Click on the 'Cancel' button on Mac OS X or "
            + "'close'(X) on other paltforms. Dialog will be closed."
            + "\n   7. After the dialog is closed another window should "
            + "become the active window."
            + "\n   8. If there no any active window then the test has "
            + "failed. Click on 'Fail' Button."
            + "\n   9. Test Passed. Click on 'Pass' Button.";

    instructionTextArea = new TextArea(13, 80);
    instructionTextArea.setText(instructions);
    instructionTextArea.setEnabled(false);
    instructionTextArea.setBackground(Color.white);

    gbc.gridx = 0;
    gbc.gridy = 0;
    gbc.weightx = 0.5;
    gbc.fill = GridBagConstraints.HORIZONTAL;
    mainControlPanel.add(instructionTextArea, gbc);

    passButton = new Button("Pass");
    passButton.setName("Pass");
    passButton.addActionListener((ActionListener) this);

    failButton = new Button("Fail");
    failButton.setName("Fail");
    failButton.addActionListener((ActionListener) this);

    setButtonEnable(false);

    gbc.gridx = 0;
    gbc.gridy = 0;
    resultButtonPanel.add(passButton, gbc);
    gbc.gridx = 1;
    gbc.gridy = 0;
    resultButtonPanel.add(failButton, gbc);
    gbc.gridx = 0;
    gbc.gridy = 1;
    mainControlPanel.add(resultButtonPanel, gbc);

    instructionFrame.add(mainControlPanel);
    instructionFrame.pack();
    instructionFrame.setVisible(true);
}
 
開發者ID:AdoptOpenJDK,項目名稱:openjdk-jdk10,代碼行數:63,代碼來源:RestoreActiveWindowTest.java


注:本文中的java.awt.Frame.pack方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。