Java 类java.awt.Button 实例源码

项目:KernelHive    文件:InfrastructureBrowser.java   
public InfrastructureBrowser(final MainFrame frame, final String title) {
    super(frame);
    this.setName(title);
    setLayout(new BorderLayout());

    graphPanel = new InfrastructureGraphPanel(frame);
    add(graphPanel, BorderLayout.CENTER);

    Button refreshButton = new Button("Refresh");
    refreshButton.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent e) {
            loadInfrastructure();
        }
    });
    add(refreshButton, BorderLayout.SOUTH);

    service = new WebServiceHelper().getMonitoringService();

    SwingUtilities.invokeLater(new Runnable() {
        @Override
        public void run() {
            loadInfrastructure();
        }
    });
}
项目:OpenJSharp    文件:WPrinterJob.java   
private void init(Component parent, String  title, String message,
                  String buttonText) {
    Panel p = new Panel();
    add("Center", new Label(message));
    Button btn = new Button(buttonText);
    btn.addActionListener(this);
    p.add(btn);
    add("South", p);
    pack();

    Dimension dDim = getSize();
    if (parent != null) {
        Rectangle fRect = parent.getBounds();
        setLocation(fRect.x + ((fRect.width - dDim.width) / 2),
                    fRect.y + ((fRect.height - dDim.height) / 2));
    }
}
项目:jdk8u-jdk    文件:bug7097771.java   
public static void main(final String[] args) throws AWTException {
    final bug7097771 frame = new bug7097771();
    frame.setSize(300, 300);
    frame.setLocationRelativeTo(null);
    final Button button = new Button();
    button.addActionListener(frame);
    frame.add(button);
    frame.setVisible(true);
    sleep();
    frame.setEnabled(false);
    button.setEnabled(false);
    button.setEnabled(true);
    sleep();
    Util.clickOnComp(button, new Robot());
    sleep();
    frame.dispose();
    if (action) {
        throw new RuntimeException("Button is not disabled.");
    }
}
项目:jdk8u-jdk    文件:FrameMinimizeTest.java   
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 :(");
    }
}
项目:jdk8u-jdk    文件:FileDialogForPackages.java   
@Override
public void init() {
    if (OSInfo.getOSType() != OSInfo.OSType.MACOSX) {
        Sysout.createDialogWithInstructions(new String[]{
                "Press PASS, this test is for MacOS X only."});
        return;
    }

    System.setProperty("apple.awt.use-file-dialog-packages", "true");

    setLayout(new GridLayout(1, 1));

    fd = new FileDialog(new Frame(), "Open");
    fd.setDirectory(APPLICATIONS_FOLDER);

    showBtn = new Button("Show File Dialog");
    showBtn.addActionListener(this);
    add(showBtn);
    String[] instructions = {
            "1) Click on 'Show File Dialog' button. A file dialog will come up.",
            "2) Navigate to the Applications folder if not already there",
            "3) Check that the application bundles can be selected and can not be navigated",
            "4) If it's true then the test passed, otherwise it failed."};
    Sysout.createDialogWithInstructions(instructions);
}
项目:anti-fanmei    文件:FunPlot.java   
private void init()
{
    f = new Frame("Demo");
    bt1 = new Button("SIN");
    bt2 = new Button("COS");
    bt3 = new Button("EXIT");
    mc = new MyCanvas();
    p = new Panel();


    f.setBounds(100, 100, 500, 500);
    f.setLayout(new BorderLayout());

    p.add(bt1);
    p.add(bt2);
    p.add(bt3);
    f.add(p, BorderLayout.NORTH);
    f.add(mc, BorderLayout.CENTER);

    addEvent();
    f.setVisible(true);
}
项目:openjdk-jdk10    文件:WPrinterJob.java   
private void init(Component parent, String  title, String message,
                  String buttonText) {
    Panel p = new Panel();
    add("Center", new Label(message));
    Button btn = new Button(buttonText);
    btn.addActionListener(this);
    p.add(btn);
    add("South", p);
    pack();

    Dimension dDim = getSize();
    if (parent != null) {
        Rectangle fRect = parent.getBounds();
        setLocation(fRect.x + ((fRect.width - dDim.width) / 2),
                    fRect.y + ((fRect.height - dDim.height) / 2));
    }
}
项目:openjdk-jdk10    文件:HighResTest.java   
public TestDialog(Frame frame, String name)    {
    super(frame, name);
    int scrollBoth = TextArea.SCROLLBARS_BOTH;
    instructionsText = new TextArea("", 15, maxStringLength, scrollBoth);
    add("North", instructionsText);

    messageText = new TextArea("", 5, maxStringLength, scrollBoth);
    add("Center", messageText);

    passB = new Button("pass");
    passB.setActionCommand("pass");
    passB.addActionListener(this);
    buttonP.add("East", passB);

    failB = new Button("fail");
    failB.setActionCommand("fail");
    failB.addActionListener(this);
    buttonP.add("West", failB);

    add("South", buttonP);
    pack();

    show();
}
项目:openjdk-jdk10    文件:UpdatePopupMenu.java   
@Override
public void actionPerformed(ActionEvent ae) {
    if (ae.getSource() instanceof Button) {
        Button btn = (Button) ae.getSource();
        switch (btn.getName()) {
            case "Pass":
                testPassed = true;
                isInterrupted = true;
                mainThread.interrupt();
                break;

            case "Fail":
                testPassed = false;
                isInterrupted = true;
                mainThread.interrupt();
                break;
        }
    }
}
项目:openjdk-jdk10    文件:DragEventSource.java   
public TestDialog( Frame frame, String name )
{
    super( frame, name );
    int scrollBoth = TextArea.SCROLLBARS_BOTH;
    instructionsText = new TextArea( "", 15, maxStringLength, scrollBoth );
    add( "North", instructionsText );

    messageText = new TextArea( "", 5, maxStringLength, scrollBoth );
    add("Center", messageText);

    passB = new Button( "pass" );
    passB.setActionCommand( "pass" );
    passB.addActionListener( this );
    buttonP.add( "East", passB );

    failB = new Button( "fail" );
    failB.setActionCommand( "fail" );
    failB.addActionListener( this );
    buttonP.add( "West", failB );

    add( "South", buttonP );
    pack();

    setVisible(true);
}
项目:openjdk-jdk10    文件:MultiMonPrintDlgTest.java   
private void executeTest() {

        GraphicsDevice defDev = GraphicsEnvironment.getLocalGraphicsEnvironment().getDefaultScreenDevice();
        int x = 0;
        Frame f = null;
        for (x = 0; x < gd.length; x ++) {
            if (gd[x] != defDev) {
                secFrame = new Frame("Screen " + x + " - secondary", gd[x].getDefaultConfiguration());
                f = secFrame;
            } else {
                primaryFrame = new Frame("Screen " + x + " - primary", gd[x].getDefaultConfiguration());
                f = primaryFrame;
            }
            Button b = new Button("Print");
            b.addActionListener(this);
            f.add("South", b);
            f.addWindowListener (new WindowAdapter() {
                public void windowClosing(WindowEvent we) {
                    ((Window) we.getSource()).dispose();
                }
            });
            f.setSize(200, 200);
            f.setVisible(true);
        }
    }
项目:openjdk-jdk10    文件:bug7097771.java   
public static void main(final String[] args) throws AWTException {
    final bug7097771 frame = new bug7097771();
    frame.setSize(300, 300);
    frame.setLocationRelativeTo(null);
    final Button button = new Button();
    button.addActionListener(frame);
    frame.add(button);
    frame.setVisible(true);
    Robot robot = new Robot();
    sleep(robot);
    frame.setEnabled(false);
    button.setEnabled(false);
    button.setEnabled(true);
    sleep(robot);
    Util.clickOnComp(button, robot);
    sleep(robot);
    frame.dispose();
    if (action) {
        throw new RuntimeException("Button is not disabled.");
    }
}
项目:openjdk-jdk10    文件:LightweightEventTest.java   
private static void constructTestUI() {
    // here, create the items that will be tested for correct behavior
    HeavyComponent = new EventBug();
    Button b = (Button) HeavyComponent.add("Center", new Button("Heavy"));

    LightComponent = new EventBug();
    BorderedLabel b1 = (BorderedLabel) LightComponent.add("Center",
            new BorderedLabel("Lite"));

    HeavyComponent.addListeners(b);
    LightComponent.addListeners(b1);

    LightComponent.setLocation(200, 0);
    HeavyComponent.setVisible(true);
    LightComponent.setVisible(true);
}
项目:openjdk-jdk10    文件:ContainerOrderFTPTest.java   
public void performTest() {
    int count = 0;
    Component comp = coftp.getFirstComponent(frame);
    String traversal = "";
    do {
        comp = coftp.getComponentAfter(frame, comp);
        if (comp instanceof Button) {
            traversal += ((Button)comp).getLabel();
        } else if (comp instanceof Frame) {
            traversal += ((Frame)comp).getTitle();
        }
        count++;
    } while(count < 3);

    if (!expectedTraversal.equals(traversal)) {
        dispose();
        throw new RuntimeException("Incorrect Traversal. Expected : "
            + expectedTraversal + "Actual : " + traversal);
    }
}
项目:openjdk-jdk10    文件:FrameMinimizeTest.java   
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 :(");
    }
}
项目:openjdk-jdk10    文件:DragLinkFromBrowser.java   
@Override
public void actionPerformed(ActionEvent ae) {
    if (ae.getSource() instanceof Button) {
        Button btn = (Button) ae.getSource();
        switch (btn.getName()) {
            case "Pass":
                testPassed = true;
                isInterrupted = true;
                mainThread.interrupt();
                break;

            case "Fail":
                testFailed("Dragging link from web browser Failed");
                break;
        }
    }
}
项目:openjdk-jdk10    文件:ScrollSelectionTest.java   
public TestDialog(Frame frame, String name) {
    super(frame, name);
    int scrollBoth = TextArea.SCROLLBARS_BOTH;
    instructionsText = new TextArea("", 15, maxStringLength, scrollBoth);
    add("North", instructionsText);

    messageText = new TextArea("", 5, maxStringLength, scrollBoth);
    add("Center", messageText);

    buttonP = new Panel();
    passB = new Button("pass");
    passB.setActionCommand("pass");
    passB.addActionListener(this);
    buttonP.add("East", passB);

    failB = new Button("Fail");
    failB.setActionCommand("fail");
    failB.addActionListener(this);
    buttonP.add("West", failB);

    add("South", buttonP);
    pack();
    setVisible(true);
}
项目:openjdk-jdk10    文件:AltGraphModifierTest.java   
public TestDialog(Frame frame, String name) {
    super(frame, name);
    int scrollBoth = TextArea.SCROLLBARS_BOTH;
    instructionsText = new TextArea("", 15, maxStringLength, scrollBoth);
    add("North", instructionsText);

    messageText = new TextArea("", 5, maxStringLength, scrollBoth);
    add("Center", messageText);

    buttonP = new Panel();
    failB = new Button("Fail");
    failB.setActionCommand("fail");
    failB.addActionListener(this);
    buttonP.add("Center", failB);

    add("South", buttonP);
    pack();
    setVisible(true);
}
项目:openjdk-jdk10    文件:FileDialogForPackages.java   
@Override
public void init() {
    if (OSInfo.getOSType() != OSInfo.OSType.MACOSX) {
        Sysout.createDialogWithInstructions(new String[]{
                "Press PASS, this test is for MacOS X only."});
        return;
    }

    System.setProperty("apple.awt.use-file-dialog-packages", "true");

    setLayout(new GridLayout(1, 1));

    fd = new FileDialog(new Frame(), "Open");
    fd.setDirectory(APPLICATIONS_FOLDER);

    showBtn = new Button("Show File Dialog");
    showBtn.addActionListener(this);
    add(showBtn);
    String[] instructions = {
            "1) Click on 'Show File Dialog' button. A file dialog will come up.",
            "2) Navigate to the Applications folder if not already there",
            "3) Check that the application bundles can be selected and can not be navigated",
            "4) If it's true then the test passed, otherwise it failed."};
    Sysout.createDialogWithInstructions(instructions);
}
项目:openjdk-jdk10    文件:FileDialogForDirectories.java   
@Override
public void init() {
    if (OSInfo.getOSType() != OSInfo.OSType.MACOSX) {
        Sysout.createDialogWithInstructions(new String[]{
                "Press PASS, this test is for MacOS X only."});
        return;
    }

    System.setProperty("apple.awt.fileDialogForDirectories", "true");

    setLayout(new GridLayout(1, 1));

    fd = new FileDialog(new Frame(), "Open");

    showBtn = new Button("Show File Dialog");
    showBtn.addActionListener(this);
    add(showBtn);
    String[] instructions = {
            "1) Click on 'Show File Dialog' button. A file dialog will come up.",
            "2) Check that files can't be selected.",
            "3) Check that directories can be selected.",
            "4) Repeat steps 1 - 3 a few times for different files and directories.",
            "5) If it's true then the test passed, otherwise it failed."};
    Sysout.createDialogWithInstructions(instructions);
}
项目:openjdk-jdk10    文件:Test6991580.java   
public TestDialog( Frame frame, String name )
{
  super( frame, name );
  int scrollBoth = TextArea.SCROLLBARS_BOTH;
  instructionsText = new TextArea( "", 15, maxStringLength, scrollBoth );
  add( "North", instructionsText );

  messageText = new TextArea( "", 5, maxStringLength, scrollBoth );
  add("Center", messageText);

  passB = new Button( "pass" );
  passB.setActionCommand( "pass" );
  passB.addActionListener( this );
  buttonP.add( "East", passB );

  failB = new Button( "fail" );
  failB.setActionCommand( "fail" );
  failB.addActionListener( this );
  buttonP.add( "West", failB );

  add( "South", buttonP );
  pack();

  show();
}
项目:openjdk-jdk10    文件:Test6411624.java   
public TestDialog( Frame frame, String name )
{
  super( frame, name );
  int scrollBoth = TextArea.SCROLLBARS_BOTH;
  instructionsText = new TextArea( "", 15, maxStringLength, scrollBoth );
  add( "North", instructionsText );

  messageText = new TextArea( "", 5, maxStringLength, scrollBoth );
  add("Center", messageText);

  passB = new Button( "pass" );
  passB.setActionCommand( "pass" );
  passB.addActionListener( this );
  buttonP.add( "East", passB );

  failB = new Button( "fail" );
  failB.setActionCommand( "fail" );
  failB.addActionListener( this );
  buttonP.add( "West", failB );

  add( "South", buttonP );
  pack();

  show();
}
项目:openjdk-jdk10    文件:Test4218609.java   
public TestDialog( Frame frame, String name )
{
  super( frame, name );
  int scrollBoth = TextArea.SCROLLBARS_BOTH;
  instructionsText = new TextArea( "", 15, maxStringLength, scrollBoth );
  add( "North", instructionsText );

  messageText = new TextArea( "", 5, maxStringLength, scrollBoth );
  add("Center", messageText);

  passB = new Button( "pass" );
  passB.setActionCommand( "pass" );
  passB.addActionListener( this );
  buttonP.add( "East", passB );

  failB = new Button( "fail" );
  failB.setActionCommand( "fail" );
  failB.addActionListener( this );
  buttonP.add( "West", failB );

  add( "South", buttonP );
  pack();

  show();
}
项目:openjdk-jdk10    文件:Test5032020.java   
public TestDialog( Frame frame, String name )
{
  super( frame, name );
  int scrollBoth = TextArea.SCROLLBARS_BOTH;
  instructionsText = new TextArea( "", 15, maxStringLength, scrollBoth );
  add( "North", instructionsText );

  messageText = new TextArea( "", 5, maxStringLength, scrollBoth );
  add("Center", messageText);

  passB = new Button( "pass" );
  passB.setActionCommand( "pass" );
  passB.addActionListener( this );
  buttonP.add( "East", passB );

  failB = new Button( "fail" );
  failB.setActionCommand( "fail" );
  failB.addActionListener( this );
  buttonP.add( "West", failB );

  add( "South", buttonP );
  pack();

  show();
}
项目:openjdk-jdk10    文件:Test4997635.java   
public TestDialog( Frame frame, String name )
{
  super( frame, name );
  int scrollBoth = TextArea.SCROLLBARS_BOTH;
  instructionsText = new TextArea( "", 15, maxStringLength, scrollBoth );
  add( "North", instructionsText );

  messageText = new TextArea( "", 5, maxStringLength, scrollBoth );
  add("Center", messageText);

  passB = new Button( "pass" );
  passB.setActionCommand( "pass" );
  passB.addActionListener( this );
  buttonP.add( "East", passB );

  failB = new Button( "fail" );
  failB.setActionCommand( "fail" );
  failB.addActionListener( this );
  buttonP.add( "West", failB );

  add( "South", buttonP );
  pack();

  show();
}
项目:incubator-netbeans    文件:ButtonBeanInfo.java   
/** @return Propertydescriptors */
@Override
protected PropertyDescriptor[] createPDs() throws IntrospectionException {
    return new PropertyDescriptor[] {
        new PropertyDescriptor("actionCommand", Button.class), // NOI18N
        new PropertyDescriptor("label", Button.class) // NOI18N
    };
}
项目:incubator-netbeans    文件:InstanceDataObjectTest.java   
/** Test whether instances survive garbage collection.
 */
public void testSameWithGC () throws Exception {
    Object ser = new Button();

    FileObject prim = InstanceDataObject.create (folder, "MyName", ser, null).getPrimaryFile ();
    String name = prim.getName ();
    String ext = prim.getExt ();
    prim = null;

    System.gc ();
    System.gc ();
    System.gc ();
    System.gc ();
    System.gc ();
    System.gc ();
    System.gc ();
    System.gc ();
    System.gc ();

    FileObject fo = folder.getPrimaryFile ().getFileObject (name, ext);
    assertTrue ("MyName.settings not found", fo != null);

    DataObject obj = DataObject.find (fo);

    InstanceCookie ic = (InstanceCookie)getCookie (obj, InstanceCookie.class);
    assertTrue ("Object: " + obj + " does not have instance cookie", ic != null);

    Object value = ic.instanceCreate ();
    if (value != ser) {
        fail ("Value is different than serialized: " + System.identityHashCode (ser) + " value: " + System.identityHashCode (value));
    }

    obj.delete ();
}
项目:incubator-netbeans    文件:InstanceDataObjectTest.java   
/** Tests whether createFromTemplate works correctly.
*/
public void testCreateFromTemplateForSettingsFile () throws Exception {
    Object ser = new Button();

    InstanceDataObject obj = InstanceDataObject.create (folder, "SomeName", ser, null);
    obj.setTemplate (true);

    DataObject newObj = obj.createFromTemplate(folder, "NewName");

    if (!newObj.getName().equals ("NewName")) {
        fail ("Wrong name of new data object: " + newObj.getName ());
    }

    InstanceCookie ic = (InstanceCookie)getCookie (newObj, InstanceCookie.class);

    if (ic == null) {
        fail ("No instance cookie for " + newObj);
    }

    if (ic.instanceCreate () != ser) {
        fail ("created instance is different than the original in template");
    }

    if (ic.instanceCreate () == obj.instanceCreate ()) {
        fail ("Instance of the new object is same as the current of the template");
    }
}
项目:incubator-netbeans    文件:InstanceDataObjectCopyTest.java   
private void doSettingsFileOnNonSFSAfterCopyShouldHaveEditor (boolean copy) throws Exception {
    clearWorkDir ();
    LocalFileSystem lfs = new LocalFileSystem ();
    lfs.setRootDirectory (getWorkDir ());

    FileObject set = createSettings (lfs.getRoot (), "x.settings");
    DataObject old = DataObject.find (set);
    Date d = set.lastModified();

    InstanceCookie ic = (InstanceCookie)old.getCookie(InstanceCookie.class);
    assertNotNull ("The cookie is there", ic);
    Object instance = ic.instanceCreate();
    assertNotNull ("It produces a result", instance);
    assertEquals ("It is Button", Button.class, instance.getClass ());

    FileObject tgt = FileUtil.createFolder(lfs.getRoot (), "moved");
    DataFolder fld = DataFolder.findFolder (tgt);

    DataObject obj = copy ? old.copy (fld) : old.createFromTemplate(fld);

    assertEquals ("No change in modifications", d, set.lastModified());
    assertEquals ("The same name", obj.getPrimaryFile().getNameExt (), set.getNameExt());

    assertEquals (InstanceDataObject.class, obj.getClass ());
    assertNotNull ("It has edit cookie", obj.getCookie (EditCookie.class));
    assertNotNull ("It has open cookie", obj.getCookie (OpenCookie.class));
    assertNotNull ("It has editor cookie", obj.getCookie (EditorCookie.class));

    Object o = obj.getNodeDelegate ().getPreferredAction ();
    assertEquals ("Default actions should be open on non-SFS", openAction, o);
}
项目:javase    文件:JTabbedPaneDemo.java   
public JTabbedPaneDemo() {
    tabbedPane = new JTabbedPane(JTabbedPane.TOP);
    // panel=new Panel();
    // panel.setBackground(Color.RED);
    // music=new JPanel();
    // music.setBackground(Color.green);
    tabbedPane.addTab("panel", new JLabel("标签"));
    tabbedPane.addTab("music", new Button("按钮"));
    add(tabbedPane);
    setBounds(500, 100, 500, 500);
    setVisible(true);
    setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
}
项目:javase    文件:ScrollPaneDemo.java   
ScrollPaneDemo() {
    panel = new JPanel(new GridLayout(10, 5));
    button = new Button[50];
    for (int i = 0; i < button.length; i++) {
        button[i] = new Button("按钮" + i);
        panel.add(button[i]);
    }
    scrollPane = new ScrollPane();
    scrollPane.add(panel);
    add(scrollPane, "Center");
    setBounds(300, 300, 200, 200);
    setVisible(true);
    setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
}
项目:javase    文件:SetBoxLayout.java   
public SetBoxLayout() {
    setLayout(new BoxLayout(getContentPane(), BoxLayout.LINE_AXIS));
    getContentPane().setBackground(Color.green);
    add(new Button("123"));
    add(new Button("123"));
    add(new Button("123"));
    setVisible(true);
    setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    setBounds(100, 50, 700, 400);
}
项目:openjdk-jdk10    文件:ButtonOperator.java   
/**
 * Maps {@code Button.removeActionListener(ActionListener)} through queue
 */
public void removeActionListener(final ActionListener actionListener) {
    runMapping(new MapVoidAction("removeActionListener") {
        @Override
        public void map() {
            ((Button) getSource()).removeActionListener(actionListener);
        }
    });
}
项目:jdk8u-jdk    文件:RequestFocusAndHideTest.java   
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();
}
项目:jdk8u-jdk    文件:MenuBarSetFont.java   
public static void main(final String[] args) throws Exception {

        if (sun.awt.OSInfo.getOSType() == sun.awt.OSInfo.OSType.MACOSX) {
            System.err.println("This test is not for OS X. Menu.setFont() is not supported on OS X.");
            return;
        }

        //Components initialization.
        frame.setMenuBar(mb);
        mb.setFont(new Font("Helvetica", Font.ITALIC, 5));

        final Button button = new Button("Click Me");
        button.addActionListener(new Listener());
        frame.setLayout(new CardLayout());
        frame.add(button, "First");
        frame.setSize(400, 400);
        frame.setVisible(true);
        sleep();

        final int fInsets = frame.getInsets().top;  //Frame insets without menu.
        addMenu();
        final int fMenuInsets = frame.getInsets().top; //Frame insets with menu.
        final int menuBarHeight = fMenuInsets - fInsets;
        // There is no way to change menubar height on windows. But on windows
        // we can try to split menubar in 2 rows.
        for (int i = 0; i < 100 && fMenuInsets == frame.getInsets().top; ++i) {
            // Fill whole menubar.
            addMenu();
        }

        mb.remove(0);
        frame.validate();
        sleep();

        // Test execution.
        // On XToolkit, menubar font should be changed to 60.
        // On WToolkit, menubar font should be changed to default and menubar
        // should be splitted in 2 rows.
        mb.setFont(new Font("Helvetica", Font.ITALIC, 60));
        sleep();

        final Robot r = new Robot();
        r.setAutoDelay(200);
        final Point pt = frame.getLocation();
        r.mouseMove(pt.x + frame.getWidth() / 2,
                    pt.y + fMenuInsets + menuBarHeight / 2);
        r.mousePress(InputEvent.BUTTON1_MASK);
        r.mouseRelease(InputEvent.BUTTON1_MASK);

        sleep();
        frame.dispose();

        if (clicked) {
            fail("Font was not changed");
        }
    }
项目:jdk8u-jdk    文件:Test4520754.java   
public static void main(String[] args) {
    // ensure that 4168475 does not regress
    test4168475(Component.class);
    // AWT classes (com.sun.beans.infos.ComponentBeanInfo)
    test(null, Button.class, Component.class, List.class, Menu.class, Panel.class);
    // Swing classes (dt.jar)
    test(null, JApplet.class, JButton.class, JCheckBox.class);
    // user defined classes
    test(Boolean.TRUE, Wombat.class, Foo.class, FooBar.class);
}
项目:openjdk-jdk10    文件:TestPageDlgFrameAssociation.java   
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();
        }
    });
}
项目:openjdk-jdk10    文件:TestPrintDlgFrameAssociation.java   
private static void frameTest() {
    Panel panel =new Panel();

    print = new Button("PrintDialog");
    print.setActionCommand("PrintDialog");
    print.addActionListener((e) -> {
        PrinterJob job = PrinterJob.getPrinterJob();
        PrintRequestAttributeSet aset = new HashPrintRequestAttributeSet();
        t.start();
        start = true;
        job.printDialog(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();
        }
    });
}
项目:openjdk-jdk10    文件:ButtonOperator.java   
/**
 * Maps {@code Button.setActionCommand(String)} through queue
 */
public void setActionCommand(final String string) {
    runMapping(new MapVoidAction("setActionCommand") {
        @Override
        public void map() {
            ((Button) getSource()).setActionCommand(string);
        }
    });
}
项目:openjdk-jdk10    文件:ButtonOperator.java   
/**
 * Maps {@code Button.getLabel()} through queue
 */
public String getLabel() {
    return (runMapping(new MapAction<String>("getLabel") {
        @Override
        public String map() {
            return ((Button) getSource()).getLabel();
        }
    }));
}