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

public void init() {
    System.out.println("Code base = " + getCodeBase());
    System.out.println("Document base = " + getDocumentBase());

    System.out.println("\ninit () called");
    System.out.println("isActive () returns " + isActive());

    Button b = new Button("Visit www.java2s.com");
    b.addActionListener(this);
    add(b);/*from w w  w  . ja va  2  s .  c  o  m*/

    b = new Button("Audio");
    b.addActionListener(this);
    add(b);

    String imageName = getParameter("image");

    if (imageName != null)
        im = getImage(getCodeBase(), imageName);
}

From source file:PopupDemo.java

public PopupDemo() {
    MenuBar mb = new MenuBar();
    setMenuBar(mb);// w w w .j  av a2  s.  co m
    Menu m = new Menu("file");
    mb.add(m);
    MenuItem item = new MenuItem("file-1");
    item.addActionListener(this);
    m.add(item);
    item = new MenuItem("file-2");
    m.add(item);

    setSize(100, 100);
    setLayout(new BorderLayout());

    Label l = new Label("label");
    addPopup(l, "label");
    add(l, "North");

    Panel p = new Panel();
    addPopup(p, "Panel");
    add(p, "Center");

    Button b = new Button("button");
    addPopup(b, "button");
    add(b, "South");
}

From source file:TreeLinkTest.java

public void init() {
    tl = new TreeLayout();
    setLayout(tl);/*from   w w  w.j  a  v a  2 s  . com*/
    Button root = new Button("This is the root");
    add("Root", root);
    tl.setRoot(root);
    Component x = new Label("A random label");
    add("label", x);
    tl.setParent(x, root);
    Component y;
    y = new TextField("Add any component");
    add("comp", y);
    tl.setParent(y, root);
    x = new List();
    ((List) x).add("List entry");
    ((List) x).add("Similarly useless list entry");
    add("list", x);
    tl.setParent(x, root);
    x = new Button("Extremely long and unnecessary button title");
    add("button", x);
    tl.setParent(x, y);
    x = new MyCanvas(getImage(getDocumentBase(), "icons/tools.gif"));
    add("image", x);
    tl.setParent(x, y);
}

From source file:ListenerReuse.java

public ListenerReuse() {
    Button b = new Button("Save");
    add(b);//from www.j  av  a2 s. c o m
    MenuBar mb = new MenuBar();
    setMenuBar(mb);
    Menu fm = new Menu("File");
    mb.add(fm);
    MenuItem mi = new MenuItem("Save");
    fm.add(mi);

    // Construct the ActionListener, and keep a reference to it.
    ActionListener saver = new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            System.out.println("Saving your file...");
            // In real life we would call the doSave() method
            // in the main class, something like this:
            // mainProg.doSave();
        }
    };
    // Register the actionListener with the Button
    b.addActionListener(saver);
    // And now register the same actionListener with the MenuItem
    mi.addActionListener(saver);
    pack();
}

From source file:GetApplets.java

public void init() {
    Button b = new Button("Click to call getApplets()");
    b.addActionListener(this);

    setLayout(new BorderLayout());
    add("North", b);

    textArea = new TextArea(5, 40);
    textArea.setEditable(false);//from   ww  w. j a  v a  2s. c om
    add("Center", textArea);

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

From source file:GUIMediaStatistics.java

/**********************************************************************
* Construct the GUIMediaStatistics object, constructing the various
* components and laying them out on the screen.
**********************************************************************/
public GUIMediaStatistics() {
    super("GUIMediaStatistics");
    setLayout(new BorderLayout());

    addWindowListener(new WindowAdapter() {
        public void windowClosing(WindowEvent e) {
            System.exit(0);/*  www  .  j a  v a2s  .  co  m*/
        }
    });

    Panel filePanel = new Panel();

    filePanel.add(new Label("File:"));
    mediaField = new TextField(40);
    filePanel.add(mediaField);

    browseButton = new Button("browse...");
    filePanel.add(browseButton);
    browseButton.addActionListener(this);

    getStatsButton = new Button("get stats...");
    filePanel.add(getStatsButton);
    getStatsButton.addActionListener(this);

    add(filePanel, "North");

    results = new TextArea(80, 10);
    results.setEditable(false);
    add(results, "Center");
}

From source file:GUIManagerQuery.java

/***************************************************************************
 * Construct the GUIManagerQuery object, constructing the various components
 * and laying them out on the screen.//from w w  w.jav  a2 s.c  o m
 **************************************************************************/
public GUIManagerQuery() {
    super("GUIManagerQuery");
    setLayout(new BorderLayout());

    addWindowListener(new WindowAdapter() {
        public void windowClosing(WindowEvent e) {
            System.exit(0);
        }
    });

    versionLabel = new Label("JMF v" + Manager.getVersion());
    add(versionLabel, "North");

    Panel lower = new Panel();
    lower.add(new Label("Content/Protocol"));
    contentsField = new TextField(32);
    lower.add(contentsField);
    add(lower, "South");

    results = new TextArea(20, 80);
    results.setEditable(false);
    add(results, "Center");

    Panel controls = new Panel();
    controls.setLayout(new GridBagLayout());
    GridBagConstraints gbc = new GridBagConstraints();

    hintsButton = new Button("Hints");
    gbc.gridx = 0;
    gbc.gridy = 0;
    controls.add(hintsButton, gbc);
    hintsButton.addActionListener(this);

    playersButton = new Button("Players");
    gbc.gridy = 1;
    controls.add(playersButton, gbc);
    playersButton.addActionListener(this);

    processorsButton = new Button("Processors");
    gbc.gridy = 2;
    controls.add(processorsButton, gbc);
    processorsButton.addActionListener(this);

    sourcesButton = new Button("DataSources");
    gbc.gridy = 3;
    controls.add(sourcesButton, gbc);
    sourcesButton.addActionListener(this);

    add(controls, "East");
}

From source file:Whistle.java

public void init() {
    super.init();

    String url = getParameter("clipURL");
    try {/*w ww .  j a va  2s. co m*/
        theURL = new URL(getDocumentBase(), url);
    } catch (MalformedURLException e) {
        urlExceptionWasThrown = true;
    }

    if (!urlExceptionWasThrown) {
        yeehaa = getAudioClip(theURL);
        setLayout(new BorderLayout());
        add("Center", new Button("Whistle"));
    } else {
        setLayout(new BorderLayout());
        add("Center", new Label("Sorry, No Audio"));
    }
}

From source file:CardLayDemo1.java

public void init() {

    panel = new Panel();
    cardlay = new CardLayout();
    b1 = new Button("Next");
    b1.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent evt) {
            if (++cardno >= NCARDS)
                cardno = 0;/*from ww w. j  av a 2 s .c  om*/
            cardlay.show(panel, labels[cardno]);
        }
    });
    labels[0] = "Card One";
    labels[1] = "Card Two";
    labels[2] = "Card Three";
    labels[3] = "Card Four";

    panel.setLayout(cardlay);
    for (int i = 0; i < NCARDS; i++)
        panel.add(labels[i], new Label(labels[i]));
    cardlay.show(panel, labels[0]);

    setLayout(new BorderLayout());
    add("Center", panel);
    add("South", b1);
}

From source file:FileViewer.java

/**
 * The real constructor. Create a FileViewer object to display the specified
 * file from the specified directory//w ww.  ja va  2 s .  c om
 */
public FileViewer(String directory, String filename) {
    super(); // Create the frame

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

    // Create a TextArea to display the contents of the file in
    textarea = new TextArea("", 24, 80);
    textarea.setFont(new Font("MonoSpaced", Font.PLAIN, 12));
    textarea.setEditable(false);
    this.add("Center", textarea);

    // Create a bottom panel to hold a couple of buttons in
    Panel p = new Panel();
    p.setLayout(new FlowLayout(FlowLayout.RIGHT, 10, 5));
    this.add(p, "South");

    // Create the buttons and arrange to handle button clicks
    Font font = new Font("SansSerif", Font.BOLD, 14);
    Button openfile = new Button("Open File");
    Button close = new Button("Close");
    openfile.addActionListener(this);
    openfile.setActionCommand("open");
    openfile.setFont(font);
    close.addActionListener(this);
    close.setActionCommand("close");
    close.setFont(font);
    p.add(openfile);
    p.add(close);

    this.pack();

    // Figure out the directory, from filename or current dir, if necessary
    if (directory == null) {
        File f;
        if ((filename != null) && (f = new File(filename)).isAbsolute()) {
            directory = f.getParent();
            filename = f.getName();
        } else
            directory = System.getProperty("user.dir");
    }

    this.directory = directory; // Remember the directory, for FileDialog
    setFile(directory, filename); // Now load and display the file
}