Example usage for java.awt Button Button

List of usage examples for java.awt Button Button

Introduction

In this page you can find the example usage for java.awt Button Button.

Prototype

public Button(String label) throws HeadlessException 

Source Link

Document

Constructs a button with the specified label.

Usage

From source file:MainClass.java

MainClass() {
    super("MainClass");
    setSize(200, 200);//from w  w w  .  j  a va 2s.  co  m

    fc = new FileDialog(this, "Choose a file", FileDialog.LOAD);
    fc.setDirectory("C:\\");

    Button b;
    add(b = new Button("Browse...")); // Create and add a Button
    b.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            fc.setVisible(true);
            String fn = fc.getFile();
            if (fn == null)
                System.out.println("You cancelled the choice");
            else
                System.out.println("You chose " + fn);
        }
    });
}

From source file:Main.java

Main() {
    this.setLayout(new GridBagLayout());
    GridBagConstraints c = new GridBagConstraints();
    c.fill = GridBagConstraints.HORIZONTAL;
    c.weightx = 1.0;/*from  w ww .  j a  v a  2s  .c o  m*/

    this.add(new Button("Resizable"), c);
    c = new GridBagConstraints();
    c.weightx = 0.0;

    this.add(new Button("Not Resizable"));
    this.pack();
}

From source file:HBoxWithGlue.java

public HBoxWithGlue() {
    super("Box & Glue Frame");
    setSize(350, 100);/*  w w w  .j a va 2s.  com*/
    Box box = Box.createHorizontalBox();
    setContentPane(box);
    box.add(Box.createHorizontalGlue());
    for (int i = 0; i < 3; i++) {
        Button b = new Button("B" + i);
        box.add(b);
    }
    box.add(Box.createHorizontalGlue());
    setDefaultCloseOperation(EXIT_ON_CLOSE);
    setVisible(true);
}

From source file:HBoxWithStrut.java

public HBoxWithStrut() {
    super("Box & Strut Frame");
    setSize(370, 80);/*from  ww w . j a  v a  2  s . c  o  m*/
    Box box = Box.createHorizontalBox();
    setContentPane(box);
    for (int i = 0; i < 3; i++) {
        Button b = new Button("B" + i);
        box.add(b);
    }

    // Add a spacer between the first three buttons and the last three
    box.add(Box.createHorizontalStrut(10));
    for (int i = 3; i < 6; i++) {
        Button b = new Button("B" + i);
        box.add(b);
    }
    setDefaultCloseOperation(EXIT_ON_CLOSE);
    setVisible(true);
}

From source file:HBox.java

public HBox() {
    super("Horizontal Box Test Frame");
    setSize(200, 100);//ww w.j  a v  a2  s  .c o  m
    Panel box = new Panel();

    // Use BoxLayout.Y_AXIS below if you want a vertical box
    box.setLayout(new BoxLayout(box, BoxLayout.X_AXIS));
    setContentPane(box);
    for (int i = 0; i < 3; i++) {
        Button b = new Button("B" + i);
        box.add(b);
    }
    setDefaultCloseOperation(EXIT_ON_CLOSE);
    setVisible(true);
}

From source file:CircleLayoutTest.java

public CircleLayoutTest() {
    setTitle("CircleLayoutTest");
    setSize(300, 300);//from   w ww . jav a  2 s . c  om
    addWindowListener(new WindowAdapter() {
        public void windowClosing(WindowEvent e) {
            System.exit(0);
        }
    });

    getContentPane().setLayout(new CircleLayout());
    getContentPane().add(new Button("3"));
    getContentPane().add(new Button("4"));
    getContentPane().add(new Button("5"));
    getContentPane().add(new Button("6"));
    getContentPane().add(new Button("7"));
    getContentPane().add(new Button("8"));
    getContentPane().add(new Button("9"));
    getContentPane().add(new Button("10"));
    getContentPane().add(new Button("11"));
    getContentPane().add(new Button("12"));
    getContentPane().add(new Button("1"));
    getContentPane().add(new Button("2"));
}

From source file:Scribble.java

/** Initialize the button and the Graphics object */
public void init() {
    erase_button = new Button("Erase");
    this.add(erase_button);
    g = this.getGraphics();
    this.requestFocus(); // Ask for keyboard focus so we get key events
}

From source file:ToolbarFrame1.java

public ToolbarFrame1() {
    super("Toolbar Example (AWT)");
    setSize(450, 250);//  w ww.  j  a  v  a 2 s  .  c  om
    addWindowListener(new WindowAdapter() {
        public void windowClosing(WindowEvent e) {
            System.exit(0);
        }
    });

    ActionListener printListener = new ActionListener() {
        public void actionPerformed(ActionEvent ae) {
            System.out.println(ae.getActionCommand());
        }
    };

    Panel toolbar = new Panel();
    toolbar.setLayout(new FlowLayout(FlowLayout.LEFT));

    cutButton = new Button("Cut");
    cutButton.addActionListener(printListener);
    toolbar.add(cutButton);

    copyButton = new Button("Copy");
    copyButton.addActionListener(printListener);
    toolbar.add(copyButton);

    pasteButton = new Button("Paste");
    pasteButton.addActionListener(printListener);
    toolbar.add(pasteButton);

    add(toolbar, BorderLayout.NORTH);
}

From source file:ClipMe.java

ClipMe() {
    super("Clipping Example");
    add(tf = new TextField("Welcome"), "North");
    add(ta = new TextArea(), "Center");
    ta.setEditable(false);/* w  ww  .jav  a2 s  . c  o m*/
    Panel p = new Panel();
    p.add(copy = new Button("Copy"));
    p.add(paste = new Button("Paste"));
    add(p, "South");
    setSize(250, 250);
}

From source file:MainClass.java

public MainClass() {
    super("Clipboard Test");
    GridBagLayout gridbag = new GridBagLayout();
    GridBagConstraints c = new GridBagConstraints();
    setLayout(gridbag);//from w ww. j av  a 2 s  .  com

    srcText = new TextArea(8, 32);
    c.gridwidth = 2;
    c.anchor = GridBagConstraints.CENTER;
    gridbag.setConstraints(srcText, c);
    add(srcText);

    copyButton = new Button("Copy Above");
    copyButton.setActionCommand("copy");
    copyButton.addActionListener(this);
    c.gridy = 1;
    c.gridwidth = 1;
    gridbag.setConstraints(copyButton, c);
    add(copyButton);

    pasteButton = new Button("Paste Below");
    pasteButton.setActionCommand("paste");
    pasteButton.addActionListener(this);
    pasteButton.setEnabled(false);
    c.gridx = 1;
    gridbag.setConstraints(pasteButton, c);
    add(pasteButton);

    dstText = new TextArea(8, 32);
    c.gridx = 0;
    c.gridy = 2;
    c.gridwidth = 2;
    gridbag.setConstraints(dstText, c);
    add(dstText);

    pack();
}