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:SaveDialog.java

/** Construct the object including its GUI */
public SaveDialog() {
    super("SaveDialog");
    Container cp = getContentPane();
    cp.setLayout(new FlowLayout());
    cp.add(new Label("Press this button to see the Quit dialog: "));
    cp.add(quitButton = new Button("Quit"));
    quitButton.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            System.out.println("In Exit Button's action handler");
            if (okToQuit()) {
                setVisible(false);/*from   w w  w  .j  av  a  2s.c om*/
                dispose();
                System.exit(0);
            }
        }
    });
    addWindowListener(new WindowAdapter() {
        public void windowClosing(WindowEvent e) {
            setVisible(false);
            dispose();
            System.exit(0);
        }
    });

    pack();
}

From source file:SoundExample.java

public void init() {
    playOnce = new Button("Bark!");
    playOnce.addActionListener(this);
    add(playOnce);/*from  w  w  w  .  ja  v a  2 s. com*/

    startLoop = new Button("Start sound loop");
    stopLoop = new Button("Stop sound loop");
    stopLoop.setEnabled(false);
    startLoop.addActionListener(this);
    add(startLoop);
    stopLoop.addActionListener(this);
    add(stopLoop);

    reload = new Button("Reload sounds");
    reload.addActionListener(this);
    add(reload);

    startLoadingSounds();
}

From source file:TryCGI.java

public void init() {
    add(goButton = new Button("Go for it!"));
    goButton.addActionListener(this);
}

From source file:ClipboardTest.java

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

    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();
}

From source file:ShowDocApplet.java

/** Initialize the Applet */
public void init() {
    setBackground(Color.gray);/*from   w  w  w . ja va 2 s.c  o  m*/
    try {
        targetURL = new URL(targetString);
    } catch (MalformedURLException mfu) {
        throw new IllegalArgumentException("ShowDocApplet got bad URL " + targetString);
    }
    Button b = new Button("View Secret");
    add(b);
    b.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            getAppletContext().showDocument(targetURL);
        }
    });
}

From source file:GraphPaperLayout.java

public static void main(String[] a) {
    JFrame frame = new JFrame();
    frame.setLayout(new GraphPaperLayout(new Dimension(5, 5)));
    // Add a 1x1 Rect at (0,0)
    frame.add(new Button("1"), new Rectangle(0, 0, 1, 1));
    // Add a 2x1 Rect at (2,0)
    frame.add(new Button("2"), new Rectangle(2, 0, 2, 1));
    // Add a 1x2 Rect at (1,1)
    frame.add(new Button("3"), new Rectangle(1, 1, 1, 2));
    // Add a 2x2 Rect at (3,2)
    frame.add(new Button("4"), new Rectangle(3, 2, 2, 2));
    // Add a 1x1 Rect at (0,4)
    frame.add(new Button("5"), new Rectangle(0, 4, 1, 1));
    // Add a 1x2 Rect at (2,3)
    frame.add(new Button("6"), new Rectangle(2, 3, 1, 2));
    frame.pack();// w  w  w. j  a v  a  2s . c om
    frame.setVisible(true);

}

From source file:width.java

 public void init() {
     GridBagLayout gridBag = new GridBagLayout();
     GridBagConstraints c = new GridBagConstraints();

     setLayout(gridBag);/*from w  ww  .j a  va2  s .c  o  m*/

     Label receiverLabel = new Label("Receiver name:", 
                                     Label.RIGHT);
     gridBag.setConstraints(receiverLabel, c);
     add(receiverLabel);

     nameField = new TextField(getParameter("RECEIVERNAME"),
                                            10);
     c.fill = GridBagConstraints.HORIZONTAL;
     gridBag.setConstraints(nameField, c);
     add(nameField);
     nameField.addActionListener(this);

     Button button = new Button("Send message");
     c.gridwidth = GridBagConstraints.REMAINDER; //end row
     c.anchor = GridBagConstraints.WEST; //stick to the 
                                         //text field
     c.fill = GridBagConstraints.NONE; //keep the button 
                                       //small
     gridBag.setConstraints(button, c);
     add(button);
     button.addActionListener(this);

     status = new TextArea(5, 60);
     status.setEditable(false);
     c.anchor = GridBagConstraints.CENTER; //reset to the default
     c.fill = GridBagConstraints.BOTH; //make this big
     c.weightx = 1.0;
     c.weighty = 1.0;
     gridBag.setConstraints(status, c);
     add(status);

     myName = getParameter("NAME");
     Label senderLabel = new Label("(My name is " + myName + ".)",
                                   Label.CENTER);
     c.weightx = 0.0;
     c.weighty = 0.0;
     gridBag.setConstraints(senderLabel, c);
     add(senderLabel);

newline = System.getProperty("line.separator");
 }

From source file:FileLister.java

/**
 * Constructor: create the GUI, and list the initial directory.
 *///  w ww.  j  av  a 2s.co m
public FileLister(String directory, FilenameFilter filter) {
    super("File Lister"); // Create the window
    this.filter = filter; // Save the filter, if any

    // Destroy the window when the user requests it
    addWindowListener(new WindowAdapter() {
        public void windowClosing(WindowEvent e) {
            dispose();
        }
    });

    list = new List(12, false); // Set up the list
    list.setFont(new Font("MonoSpaced", Font.PLAIN, 14));
    list.addActionListener(this);
    list.addItemListener(this);

    details = new TextField(); // Set up the details area
    details.setFont(new Font("MonoSpaced", Font.PLAIN, 12));
    details.setEditable(false);

    buttons = new Panel(); // Set up the button box
    buttons.setLayout(new FlowLayout(FlowLayout.RIGHT, 15, 5));
    buttons.setFont(new Font("SansSerif", Font.BOLD, 14));

    up = new Button("Up a Directory"); // Set up the two buttons
    close = new Button("Close");
    up.addActionListener(this);
    close.addActionListener(this);

    buttons.add(up); // Add buttons to button box
    buttons.add(close);

    this.add(list, "Center"); // Add stuff to the window
    this.add(details, "North");
    this.add(buttons, "South");
    this.setSize(500, 350);

    listDirectory(directory); // And now list initial directory.
}

From source file:jotp.java

public void init() {

    setBackground(Color.white);/*from ww w. j a va2s  .c o m*/
    setLayout(new GridLayout(6, 1));

    Panel panel1 = new Panel();
    add(panel1);
    Font titlefont = new Font("TimesRoman", Font.BOLD, 14);
    panel1.setFont(titlefont);
    panel1.add(new Label(String.valueOf(version) + ": The Java OTP (aka S/Key) calculator!"));
    Panel panel2 = new Panel();
    panel2.setLayout(new FlowLayout());
    add(panel2);
    panel2.add(new Label("Challenge (e.g. \"55 latour1\"):"));
    chaltf = new TextField(24);
    panel2.add(chaltf);

    Panel panel3 = new Panel();
    panel3.setLayout(new FlowLayout());
    add(panel3);
    panel3.add(new Label("Secret Password:"));
    pwtf = new TextField(24);
    pwtf.setEchoCharacter('*');
    panel3.add(pwtf);

    Panel panel4 = new Panel();
    panel4.setLayout(new FlowLayout());
    add(panel4);

    panel4.add(new Button(String.valueOf(md4label)));
    panel4.add(new Button(String.valueOf(md5label)));

    Panel panel6 = new Panel();
    panel6.setLayout(new FlowLayout());
    add(panel6);
    panel6.add(new Label("One-Time Password:", Label.LEFT));
    otptf = new TextField(40);
    panel6.add(otptf);

    Panel panel7 = new Panel();
    add(panel7);
    panel7.add(new Label("jotp by Harry Mantakos, " + "http://www.cs.umd.edu/~harry/jotp"));
}

From source file:MultiView.java

protected void addCanvas3D(Canvas3D c3d) {
    add(c3d);/*from www  .  ja v a  2s . c o  m*/

    // IFF we have created the first view
    // also add a button to allow more views
    // to be created
    if (m_nNumViews == 1) {
        Button button = new Button("Add View");
        button.addActionListener(this);
        add(button);
    }

    doLayout();
}