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

public void init() {

    // set up the main UI panel
    panelMain = new Panel();
    panelMain.setLayout(new BorderLayout(5, 5));

    // text entry components
    Panel panelEntry = new Panel();
    panelEntry.setLayout(new BorderLayout(5, 5));

    Panel panelURL = new Panel();
    panelURL.setLayout(new FlowLayout(FlowLayout.LEFT, 5, 5));
    Label labelURL = new Label("Starting URL: ", Label.RIGHT);
    panelURL.add(labelURL);//w  w  w .j  a va2 s  . c o m
    textURL = new TextField("", 40);
    panelURL.add(textURL);
    panelEntry.add("North", panelURL);

    Panel panelType = new Panel();
    panelType.setLayout(new FlowLayout(FlowLayout.LEFT, 5, 5));
    Label labelType = new Label("Content type: ", Label.RIGHT);
    panelType.add(labelType);
    choiceType = new Choice();
    choiceType.addItem("text/html");
    choiceType.addItem("audio/basic");
    choiceType.addItem("audio/au");
    choiceType.addItem("audio/aiff");
    choiceType.addItem("audio/wav");
    choiceType.addItem("video/mpeg");
    choiceType.addItem("video/x-avi");
    panelType.add(choiceType);
    panelEntry.add("South", panelType);

    panelMain.add("North", panelEntry);

    // list of result URLs
    Panel panelListButtons = new Panel();
    panelListButtons.setLayout(new BorderLayout(5, 5));

    Panel panelList = new Panel();
    panelList.setLayout(new BorderLayout(5, 5));
    Label labelResults = new Label("Search results");
    panelList.add("North", labelResults);
    Panel panelListCurrent = new Panel();
    panelListCurrent.setLayout(new BorderLayout(5, 5));
    listMatches = new List(10);
    panelListCurrent.add("North", listMatches);
    labelStatus = new Label("");
    panelListCurrent.add("South", labelStatus);
    panelList.add("South", panelListCurrent);

    panelListButtons.add("North", panelList);

    // control buttons
    Panel panelButtons = new Panel();
    Button buttonSearch = new Button(SEARCH);
    buttonSearch.addActionListener(this);
    panelButtons.add(buttonSearch);
    Button buttonStop = new Button(STOP);
    buttonStop.addActionListener(this);
    panelButtons.add(buttonStop);

    panelListButtons.add("South", panelButtons);

    panelMain.add("South", panelListButtons);

    add(panelMain);
    setVisible(true);

    repaint();

    // initialize search data structures
    vectorToSearch = new Vector();
    vectorSearched = new Vector();
    vectorMatches = new Vector();

    // set default for URL access
    URLConnection.setDefaultAllowUserInteraction(false);
}

From source file:BenchmarkApplet.java

public void init() {
      tgroup = Thread.currentThread().getThreadGroup();

      Font font = new Font("Courier", Font.PLAIN, 10);
      FontMetrics fm = getFontMetrics(font);
      int lines = Math.max(10, size().height / fm.getHeight() - 4);

      out = new TextArea(lines, spaces.length() + Benchmark.resolutionName.length());
      out.setFont(font);//from   w  w  w .  jav  a  2  s  .c o m
      out.setEditable(false);
      add(out);

      boolean toobig;
      do {
          testList = new List(--lines, true);
          add(testList, 0);
          validate();
          if (toobig = testList.size().height - out.size().height > 2)
              remove(testList);
      } while (toobig);
      for (int ii = 0; ii < tests.length; ii++)
          testList.addItem(tests[ii].getName());
      testList.select(0); // Calibration benchmark
      testList.select(1); // Mixed benchmark

      timeEstimate = new Label(getTimeEstimate());
      add(timeEstimate);

      add(doit = new Button("Run Benchmark"));
      add(abort = new Button("Stop"));
      add(clear = new Button("Clear"));
      abort.disable();
      clear.disable();

      add(console = new Checkbox("Console"));

      validate();
  }

From source file:MessageViewer.java

protected void addToolbar() {
    GridBagConstraints gb = new GridBagConstraints();
    gb.gridheight = 1;//from   w  w w .j a v  a 2 s  . c  o  m
    gb.gridwidth = 1;
    gb.fill = GridBagConstraints.NONE;
    gb.anchor = GridBagConstraints.WEST;
    gb.weightx = 0.0;
    gb.weighty = 0.0;
    gb.insets = new Insets(4, 4, 4, 4);

    // structure button
    gb.gridwidth = GridBagConstraints.REMAINDER; // only for the last one
    Button b = new Button("Structure");
    b.addActionListener(new StructureAction());
    add(b, gb);
}

From source file:MultipartViewer.java

protected void setupDisplay(Multipart mp) {
    // we display the first body part in a main frame on the left, and then
    // on the right we display the rest of the parts as attachments

    GridBagConstraints gc = new GridBagConstraints();
    gc.gridheight = GridBagConstraints.REMAINDER;
    gc.fill = GridBagConstraints.BOTH;
    gc.weightx = 1.0;//from  w  w  w  .ja  v a2  s.c  o  m
    gc.weighty = 1.0;

    // get the first part
    try {
        BodyPart bp = mp.getBodyPart(0);
        Component comp = getComponent(bp);
        add(comp, gc);

    } catch (MessagingException me) {
        add(new Label(me.toString()), gc);
    }

    // see if there are more than one parts
    try {
        int count = mp.getCount();

        // setup how to display them
        gc.gridwidth = GridBagConstraints.REMAINDER;
        gc.gridheight = 1;
        gc.fill = GridBagConstraints.NONE;
        gc.anchor = GridBagConstraints.NORTH;
        gc.weightx = 0.0;
        gc.weighty = 0.0;
        gc.insets = new Insets(4, 4, 4, 4);

        // for each one we create a button with the content type
        for (int i = 1; i < count; i++) { // we skip the first one 
            BodyPart curr = mp.getBodyPart(i);
            String label = null;
            if (label == null)
                label = curr.getFileName();
            if (label == null)
                label = curr.getDescription();
            if (label == null)
                label = curr.getContentType();

            Button but = new Button(label);
            but.addActionListener(new AttachmentViewer(curr));
            add(but, gc);
        }

    } catch (MessagingException me2) {
        me2.printStackTrace();
    }

}

From source file:ExposedFloat.java

public void init() {

    Panel buttonPanel = new PanelWithInsets(0, 0, 0, 0);
    buttonPanel.setLayout(new GridLayout(6, 2, 5, 5));
    buttonPanel.add(maximumButton);//from  w  ww . j  a  v a2  s.  c o m
    buttonPanel.add(minimumButton);
    buttonPanel.add(positiveInfinityButton);
    buttonPanel.add(negativeInfinityButton);
    buttonPanel.add(piButton);
    buttonPanel.add(notANumberButton);
    buttonPanel.add(new Button(multByZeroButtonString));
    buttonPanel.add(new Button(changeSignButtonString));
    buttonPanel.add(new Button(doubleButtonString));
    buttonPanel.add(new Button(halveButtonString));
    buttonPanel.add(new RepeaterButton(incrementButtonString));
    buttonPanel.add(new RepeaterButton(decrementButtonString));

    binaryField = new Label("00000000000000000000000000000000");
    signField = new Label("0");
    exponentField = new Label("00000000");
    mantissaField = new Label("000000000000000000000000");
    hexField = new Label("00000000");
    base2Field = new Label("0");
    base10Field = new Label("0");

    Font fieldFont = new Font("TimesRoman", Font.PLAIN, 12);
    binaryField.setFont(fieldFont);
    signField.setFont(fieldFont);
    exponentField.setFont(fieldFont);
    mantissaField.setFont(fieldFont);
    hexField.setFont(fieldFont);
    base2Field.setFont(fieldFont);
    base10Field.setFont(fieldFont);

    Panel numberPanel = new Panel();
    numberPanel.setBackground(Color.white);
    numberPanel.setLayout(new GridLayout(7, 1));
    numberPanel.add(signField);
    numberPanel.add(exponentField);
    numberPanel.add(mantissaField);
    Panel binaryPanel = new Panel();
    binaryPanel.setLayout(new BorderLayout());
    binaryPanel.add("Center", binaryField);
    numberPanel.add(binaryPanel);

    Panel hexPanel = new Panel();
    hexPanel.setLayout(new BorderLayout());
    hexPanel.add("Center", hexField);
    numberPanel.add(hexPanel);
    numberPanel.add(base2Field);
    numberPanel.add(base10Field);

    Panel labelPanel = new Panel();
    labelPanel.setBackground(Color.white);
    labelPanel.setLayout(new GridLayout(7, 1));
    Font labelFont = new Font("Helvetica", Font.ITALIC, 11);
    Label label = new Label(signString, Label.CENTER);
    label.setFont(labelFont);
    labelPanel.add(label);
    label = new Label(exponentString, Label.CENTER);
    label.setFont(labelFont);
    labelPanel.add(label);
    label = new Label(mantissaString, Label.CENTER);
    label.setFont(labelFont);
    labelPanel.add(label);
    label = new Label(binaryString, Label.CENTER);
    label.setFont(labelFont);
    labelPanel.add(label);
    label = new Label(hexString, Label.CENTER);
    label.setFont(labelFont);
    labelPanel.add(label);
    label = new Label(base2String, Label.CENTER);
    label.setFont(labelFont);
    labelPanel.add(label);
    label = new Label(base10String, Label.CENTER);
    label.setFont(labelFont);
    labelPanel.add(label);

    Panel dataPanel = new Panel();
    dataPanel.setLayout(new BorderLayout());
    dataPanel.add("West", labelPanel);
    dataPanel.add("Center", numberPanel);

    ColoredLabel title = new ColoredLabel(titleString, Label.CENTER, Color.cyan);
    title.setFont(new Font("Helvetica", Font.BOLD, 12));

    setBackground(Color.green);
    setLayout(new BorderLayout(5, 5));
    add("North", title);
    add("West", buttonPanel);
    add("Center", dataPanel);
}

From source file:SocketApplet.java

/** Initialize the GUI nicely. */
public void init() {
    Label aLabel;//from   w  w w . j a va  2s.  c  o m

    setLayout(new GridBagLayout());
    int LOGO_COL = 1;
    int LABEL_COL = 2;
    int TEXT_COL = 3;
    int BUTTON_COL = 1;
    GridBagConstraints gbc = new GridBagConstraints();
    gbc.weightx = 100.0;
    gbc.weighty = 100.0;

    gbc.gridx = LABEL_COL;
    gbc.gridy = 0;
    gbc.anchor = GridBagConstraints.EAST;
    add(aLabel = new Label("Name:", Label.CENTER), gbc);
    gbc.anchor = GridBagConstraints.CENTER;
    gbc.gridx = TEXT_COL;
    gbc.gridy = 0;
    add(nameTF = new TextField(10), gbc);

    gbc.gridx = LABEL_COL;
    gbc.gridy = 1;
    gbc.anchor = GridBagConstraints.EAST;
    add(aLabel = new Label("Password:", Label.CENTER), gbc);
    gbc.anchor = GridBagConstraints.CENTER;
    gbc.gridx = TEXT_COL;
    gbc.gridy = 1;
    add(passTF = new TextField(10), gbc);
    passTF.setEchoChar('*');

    gbc.gridx = LABEL_COL;
    gbc.gridy = 2;
    gbc.anchor = GridBagConstraints.EAST;
    add(aLabel = new Label("Domain:", Label.CENTER), gbc);
    gbc.anchor = GridBagConstraints.CENTER;
    gbc.gridx = TEXT_COL;
    gbc.gridy = 2;
    add(domainTF = new TextField(10), gbc);
    sendButton = new Button("Send data");
    gbc.gridx = BUTTON_COL;
    gbc.gridy = 3;
    gbc.gridwidth = 3;
    add(sendButton, gbc);

    whence = getCodeBase();

    // Now the action begins...
    sendButton.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent evt) {
            String name = nameTF.getText();
            if (name.length() == 0) {
                showStatus("Name required");
                return;
            }
            String domain = domainTF.getText();
            if (domain.length() == 0) {
                showStatus("Domain required");
                return;
            }
            showStatus("Connecting to host " + whence.getHost() + " as " + nameTF.getText());

            try {
                Socket s = new Socket(getCodeBase().getHost(), 3333);
                PrintWriter pf = new PrintWriter(s.getOutputStream(), true);
                // send login name
                pf.println(nameTF.getText());
                // passwd
                pf.println(passTF.getText());
                // and domain
                pf.println(domainTF.getText());

                BufferedReader is = new BufferedReader(new InputStreamReader(s.getInputStream()));
                String response = is.readLine();
                showStatus(response);
            } catch (IOException e) {
                showStatus("ERROR: " + e.getMessage());
            }
        }
    });
}

From source file:SumUp.java

/** init() is an Applet method called by the browser to initialize */
public void init() {
    setBackground(Color.magenta);
    // The layout of the Applet is a Grid; always add things in pairs!
    setLayout(new GridLayout(0, 2));
    Choice c;//from  w w w.  java  2  s  . c  om
    add(new Label("Option 1"));
    add(c = new Choice());
    c.addItem("0");
    c.addItem("100");
    c.addItem("200");
    c.addItem("400");
    cs[numChoices++] = c;

    add(new Label("Option 2"));
    add(c = new Choice());
    c.addItem("0");
    c.addItem("100");
    c.addItem("200");
    c.addItem("400");
    cs[numChoices++] = c;

    Panel p = new Panel();
    p.setBackground(Color.pink);
    p.add(new Label("Total:"));
    p.add(resultField = new Label("000000"));
    add(p);

    sendButton = new Button("Send it");
    add(sendButton); // connect Button into Applet
    sendButton.addActionListener(this); // connect it back to Applet
}

From source file:TexCoordTest.java

protected void addCanvas3D(Canvas3D c3d) {
    setLayout(new BorderLayout());
    add(c3d, BorderLayout.CENTER);

    Panel controlPanel = new Panel();

    // creates some GUI components so we can modify the
    // scene and texure coordinate generation at runtime
    Button eyeButton = new Button("EYE_LINEAR");
    eyeButton.addActionListener(this);
    controlPanel.add(eyeButton);/*from  w w  w .  j av a  2 s  .  c  o  m*/

    Button objectButton = new Button("OBJECT_LINEAR");
    objectButton.addActionListener(this);
    controlPanel.add(objectButton);

    Button sphereButton = new Button("SPHERE_MAP");
    sphereButton.addActionListener(this);
    controlPanel.add(sphereButton);

    Button rotateButton = new Button("Rotate");
    rotateButton.addActionListener(this);
    controlPanel.add(rotateButton);

    Button translateButton = new Button("Translate");
    translateButton.addActionListener(this);
    controlPanel.add(translateButton);

    add(controlPanel, BorderLayout.SOUTH);

    doLayout();
}

From source file:Seek.java

/**
 * Given a DataSource, create a player and use that player
 * as a player to playback the media.//from   w w  w  .  ja  v  a 2  s. co  m
 */
public boolean open(DataSource ds) {

    System.err.println("create player for: " + ds.getContentType());

    try {
        p = Manager.createPlayer(ds);
    } catch (Exception e) {
        System.err.println("Failed to create a player from the given DataSource: " + e);
        return false;
    }

    p.addControllerListener(this);

    p.realize();
    if (!waitForState(p.Realized)) {
        System.err.println("Failed to realize the player.");
        return false;
    }

    // Try to retrieve a FramePositioningControl from the player.
    fpc = (FramePositioningControl) p.getControl("javax.media.control.FramePositioningControl");

    if (fpc == null) {
        System.err.println("The player does not support FramePositioningControl.");
        System.err.println("There's no reason to go on for the purpose of this demo.");
        return false;
    }

    Time duration = p.getDuration();

    if (duration != Duration.DURATION_UNKNOWN) {
        System.err.println("Movie duration: " + duration.getSeconds());

        totalFrames = fpc.mapTimeToFrame(duration);
        if (totalFrames != FramePositioningControl.FRAME_UNKNOWN)
            System.err.println("Total # of video frames in the movies: " + totalFrames);
        else
            System.err.println("The FramePositiongControl does not support mapTimeToFrame.");

    } else {
        System.err.println("Movie duration: unknown");
    }

    // Prefetch the player.
    p.prefetch();
    if (!waitForState(p.Prefetched)) {
        System.err.println("Failed to prefetch the player.");
        return false;
    }

    // Display the visual & control component if there's one.

    setLayout(new BorderLayout());

    cntlPanel = new Panel();

    fwdButton = new Button("Forward");
    bwdButton = new Button("Backward");
    rndButton = new Button("Random");

    fwdButton.addActionListener(this);
    bwdButton.addActionListener(this);
    rndButton.addActionListener(this);

    cntlPanel.add(fwdButton);
    cntlPanel.add(bwdButton);
    cntlPanel.add(rndButton);

    Component vc;
    if ((vc = p.getVisualComponent()) != null) {
        add("Center", vc);
    }

    add("South", cntlPanel);

    setVisible(true);

    return true;
}

From source file:PlayerOfMedia.java

/***************************************************************************
 * Construct a PlayerOfMedia. The Frame will have the title supplied by the
 * user. All initial actions on the PlayerOfMedia object are initiated
 * through its menu (or shotcut key)./*from   w  w  w  . j  a va 2  s  .c  om*/
 **************************************************************************/
PlayerOfMedia(String name) {

    super(name);
    ///////////////////////////////////////////////////////////
    // Setup the menu system: a "File" menu with Open and Quit.
    ///////////////////////////////////////////////////////////
    bar = new MenuBar();
    fileMenu = new Menu("File");
    MenuItem openMI = new MenuItem("Open...", new MenuShortcut(KeyEvent.VK_O));
    openMI.setActionCommand("OPEN");
    openMI.addActionListener(this);
    fileMenu.add(openMI);
    MenuItem quitMI = new MenuItem("Quit", new MenuShortcut(KeyEvent.VK_Q));
    quitMI.addActionListener(this);
    quitMI.setActionCommand("QUIT");
    fileMenu.add(quitMI);
    bar.add(fileMenu);
    setMenuBar(bar);

    ///////////////////////////////////////////////////////
    // Layout the frame, its position on screen, and ensure
    // window closes are dealt with properly, including
    // relinquishing the resources of any Player.
    ///////////////////////////////////////////////////////
    setLayout(new BorderLayout());
    setLocation(100, 100);
    addWindowListener(new WindowAdapter() {
        public void windowClosing(WindowEvent e) {
            if (player != null) {
                player.stop();
                player.close();
            }
            System.exit(0);
        }
    });

    /////////////////////////////////////////////////////
    // Build the Dialog box by which the user can select
    // the media to play.
    /////////////////////////////////////////////////////
    selectionDialog = new Dialog(this, "Media Selection");
    Panel pan = new Panel();
    pan.setLayout(new GridBagLayout());
    GridBagConstraints gbc = new GridBagConstraints();
    mediaName = new TextField(40);
    gbc.gridx = 0;
    gbc.gridy = 0;
    gbc.gridwidth = 2;
    pan.add(mediaName, gbc);
    choose = new Button("Choose File...");
    gbc.ipadx = 10;
    gbc.ipady = 10;
    gbc.gridx = 2;
    gbc.gridwidth = 1;
    pan.add(choose, gbc);
    choose.addActionListener(this);
    open = new Button("Open");
    gbc.gridy = 1;
    gbc.gridx = 1;
    pan.add(open, gbc);
    open.addActionListener(this);
    cancel = new Button("Cancel");
    gbc.gridx = 2;
    pan.add(cancel, gbc);
    cancel.addActionListener(this);
    selectionDialog.add(pan);
    selectionDialog.pack();
    selectionDialog.setLocation(200, 200);

    ////////////////////////////////////////////////////
    // Build the error Dialog box by which the user can
    // be informed of any errors or problems.
    ////////////////////////////////////////////////////
    errorDialog = new Dialog(this, "Error", true);
    errorLabel = new Label("");
    errorDialog.add(errorLabel, "North");
    ok = new Button("OK");
    ok.addActionListener(this);
    errorDialog.add(ok, "South");
    errorDialog.pack();
    errorDialog.setLocation(150, 300);

    Manager.setHint(Manager.PLUGIN_PLAYER, new Boolean(true));
}