类java.awt.Button源码实例Demo

下面列出了怎么用java.awt.Button的API类实例代码及写法,或者点击链接到github查看源代码。

源代码1 项目: openjdk-8   文件: 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);
}
 
源代码2 项目: dragonwell8_jdk   文件: 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));
    }
}
 
源代码3 项目: 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);
}
 
源代码4 项目: openjdk-jdk9   文件: 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);
}
 
源代码5 项目: openjdk-8   文件: 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));
    }
}
 
源代码6 项目: openjdk-jdk8u-backup   文件: 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 :(");
    }
}
 
源代码7 项目: mmscomputing   文件: SaneAppletExample.java
public void init(){
  setLayout(new GridLayout(1,3));
  selectButton = new Button("select");
  add(selectButton);
  selectButton.addActionListener(this);

  acquireButton = new Button("acquire");
  add(acquireButton);
  acquireButton.addActionListener(this);

  cancelButton = new Button("cancel next scan");
  add(cancelButton);
  cancelButton.addActionListener(this);

  filename=System.getProperty("user.home")+"/test.jpg";

  scanner=Scanner.getDevice();
  scanner.addListener(this);
}
 
源代码8 项目: jdk8u-jdk   文件: 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);
}
 
源代码9 项目: openjdk-jdk8u-backup   文件: 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));
    }
}
 
源代码10 项目: TencentKona-8   文件: 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 :(");
    }
}
 
源代码11 项目: mmscomputing   文件: TwainTiffAppletExample.java
public void init(){
    setLayout(new GridLayout(0,2));
    selectButton = new Button("select");
    add(selectButton);
    selectButton.addActionListener(this);

    acquireButton = new Button("acquire");
    add(acquireButton);
    acquireButton.addActionListener(this);

    scanner=Scanner.getDevice();
    scanner.addListener(this);

    writer = (ImageWriter)ImageIO.getImageWritersByFormatName("tif").next();
    System.out.println(writer.getClass().getName()); 
//  should be: uk.co.mmscomputing.imageio.tiff.TIFFImageWriter
  }
 
源代码12 项目: 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.");
    }
}
 
源代码13 项目: TencentKona-8   文件: 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);
}
 
源代码14 项目: hottub   文件: 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));
    }
}
 
源代码15 项目: openjdk-jdk9   文件: 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.");
    }
}
 
@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);
}
 
源代码17 项目: jdk8u60   文件: 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);
}
 
源代码18 项目: JavaExercises   文件: HelloSwingPaint.java
HelloSwingPaint() {
    setTitle("Hello Swing!");
    setDefaultCloseOperation(EXIT_ON_CLOSE);
    setSize(500, 400);
    setLocationRelativeTo(null);

    Canvas canvas = new Canvas();
    canvas.setBackground(Color.white);

    Button btnExit = new Button("Exit");
    btnExit.addActionListener(e -> System.exit(0));

    add(canvas, BorderLayout.CENTER);
    add(btnExit, BorderLayout.SOUTH);
    setVisible(true);
}
 
源代码19 项目: openjdk-jdk8u   文件: FocusTransitionTest.java
private static void createAndShowGUI() {
    frame = new Frame("Test Frame");

    textField1 = new TextField(5);

    button = new Button("Go");
    button.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent e) {
            textField1.requestFocusInWindow();
            startUpdate();
        }
    });

    frame.setLayout(new FlowLayout());
    frame.setSize(400, 200);
    frame.add(textField1);
    frame.add(new TextField(5));
    frame.add(new TextField(5));
    frame.add(button);
    frame.setVisible(true);
}
 
源代码20 项目: openjdk-jdk8u   文件: 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 :(");
    }
}
 
源代码21 项目: 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);
}
 
源代码22 项目: openjdk-jdk8u-backup   文件: FocusTransitionTest.java
private static void createAndShowGUI() {
    frame = new Frame("Test Frame");

    textField1 = new TextField(5);

    button = new Button("Go");
    button.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent e) {
            textField1.requestFocusInWindow();
            startUpdate();
        }
    });

    frame.setLayout(new FlowLayout());
    frame.setSize(400, 200);
    frame.add(textField1);
    frame.add(new TextField(5));
    frame.add(new TextField(5));
    frame.add(button);
    frame.setVisible(true);
}
 
源代码23 项目: openjdk-8-source   文件: 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 :(");
    }
}
 
源代码24 项目: openjdk-jdk9   文件: ButtonOperator.java
/**
 * Maps {@code Button.addActionListener(ActionListener)} through queue
 */
public void addActionListener(final ActionListener actionListener) {
    runMapping(new MapVoidAction("addActionListener") {
        @Override
        public void map() {
            ((Button) getSource()).addActionListener(actionListener);
        }
    });
}
 
源代码25 项目: swift-k   文件: GIPApplet.java
public EmailConfirmationDialog(Frame parent, String[] messages, String textArea) {

        super(parent, true);
        setTitle("Confirmation Dialog");

        Font font = new Font("Courier", Font.PLAIN, 12);
        setFont(font);
        
        int rows = messages.length;
        Panel textPanel = new Panel();
        textPanel.setLayout(new GridLayout(rows,1));
        for(int i = 0; i < rows; i++){
            textPanel.add(new Label(messages[i]));
        }
        add("North", textPanel);

        Panel textAreaPanel = new Panel();
        TextArea ta = new TextArea(12,60);
        ta.setText(textArea);
        textAreaPanel.add(ta);
        add("Center", textAreaPanel);
        
        Panel p = new Panel();
        p.setLayout(new FlowLayout());
        Button yes = new Button("Yes");
        yes.addActionListener(this);
        p.add(yes);
        Button no = new Button("No");
        no.addActionListener(this);
        p.add(no);
        add("South", p);
        
        setLocation(100, 200);
        pack();

    }
 
源代码26 项目: hottub   文件: ContainerAIOOBE.java
public static void main(final String[] args) throws Exception {
    ZContainer z = new ZContainer();
    z.add(new Button());

    ByteArrayOutputStream baos = new ByteArrayOutputStream();
    ObjectOutputStream oos = new ObjectOutputStream(baos);
    oos.writeObject(z);
    oos.flush();
    oos.close();

    byte[] array = baos.toByteArray();
    ObjectInputStream ois = new ObjectInputStream(new ByteArrayInputStream(array));

    // Reading the object must not throw ArrayIndexOutOfBoundsException
    ZContainer zz = (ZContainer) ois.readObject();

    if (zz.getComponentCount() != 1) {
        throw new Exception("deserialized object must have 1 component");
    }
    if (!(zz.getComponent(0) instanceof Button)) {
        throw new Exception("deserialized object must contain Button component");
    }
    if (zz.getComponents().length != 0) {
        throw new Exception("deserialized object returns non-empty array");
    }
    System.out.println("Test passed");
}
 
源代码27 项目: jdk8u-dev-jdk   文件: ContainerAIOOBE.java
public static void main(final String[] args) throws Exception {
    ZContainer z = new ZContainer();
    z.add(new Button());

    ByteArrayOutputStream baos = new ByteArrayOutputStream();
    ObjectOutputStream oos = new ObjectOutputStream(baos);
    oos.writeObject(z);
    oos.flush();
    oos.close();

    byte[] array = baos.toByteArray();
    ObjectInputStream ois = new ObjectInputStream(new ByteArrayInputStream(array));

    // Reading the object must not throw ArrayIndexOutOfBoundsException
    ZContainer zz = (ZContainer) ois.readObject();

    if (zz.getComponentCount() != 1) {
        throw new Exception("deserialized object must have 1 component");
    }
    if (!(zz.getComponent(0) instanceof Button)) {
        throw new Exception("deserialized object must contain Button component");
    }
    if (zz.getComponents().length != 0) {
        throw new Exception("deserialized object returns non-empty array");
    }
    System.out.println("Test passed");
}
 
源代码28 项目: openjdk-8-source   文件: 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();
}
 
源代码29 项目: openjdk-jdk9   文件: 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);
        }
    });
}
 
源代码30 项目: 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);
}
 
 类所在包
 同包方法