Example usage for java.awt Panel add

List of usage examples for java.awt Panel add

Introduction

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

Prototype

public Component add(String name, Component comp) 

Source Link

Document

Adds the specified component to this container.

Usage

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  v a  2s .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));
}

From source file:SplineAnim.java

private void createCanvasPanel(Panel p) {

    GridBagLayout gl = new GridBagLayout();
    GridBagConstraints gbc = new GridBagConstraints();

    p.setLayout(gl);//from   w ww  . j  av a  2s  .com
    gbc.gridx = 0;
    gbc.gridy = 0;
    gbc.gridwidth = 5;
    gbc.gridheight = 5;
    GraphicsConfiguration config = SimpleUniverse.getPreferredConfiguration();

    canvas = new Canvas3D(config);
    canvas.setSize(490, 490);
    p.add(canvas, gbc);

}

From source file:HelloUniverse.java

public ButtonPositionControls(float x, float y, float z) {

    // up, down, right, and left movement buttons
    Panel panPanel = new Panel();
    panPanel.setLayout(new BorderLayout());
    panPanel.add("North", upB);
    panPanel.add("East", rightB);
    panPanel.add("South", downB);
    panPanel.add("West", leftB);

    // forward, backward, and reset buttons
    Panel p = new Panel();
    p.setLayout(new GridLayout(0, 1, 0, 0));
    p.add(forwardB);//from  w  w  w.ja  va2 s. c om
    p.add(backwardB);
    p.add(reset);

    // set the initial position
    position.x = x;
    position.y = y;
    position.z = z;
    orig_position.set(position);

    // add a mouse listener to each button
    upB.addMouseListener(this);
    downB.addMouseListener(this);
    leftB.addMouseListener(this);
    rightB.addMouseListener(this);
    forwardB.addMouseListener(this);
    backwardB.addMouseListener(this);
    reset.addMouseListener(this);

    this.setLayout(new BorderLayout());
    add("East", p);
    add("West", panPanel);
}

From source file:CustomAlphaTest.java

protected void addCanvas3D(Canvas3D c3d) {
    Frame frame = new Frame("Custom Alpha Test");

    Panel aPanel = new Panel();
    aPanel.setLayout(new BorderLayout());
    aPanel.add(c3d, BorderLayout.CENTER);

    frame.add(aPanel);/*  w  ww  .  j  a v a  2s  .  c o m*/

    frame.pack();
    frame.setSize(new Dimension(320, 320));
    frame.validate();
    frame.setVisible(true);

    doLayout();
}

From source file:SplineAnim.java

private void createControlPanel(Panel p) {

    GridBagLayout gl = new GridBagLayout();
    GridBagConstraints gbc = new GridBagConstraints();

    p.setLayout(gl);/*from  w  w  w. j  a  va 2  s. c o  m*/
    gbc.weightx = 100;
    gbc.weighty = 100;
    gbc.fill = GridBagConstraints.BOTH;

    gbc.gridx = 0;
    gbc.gridy = 0;
    gbc.gridwidth = 1;
    gbc.gridheight = 1;
    interpLabel = new Label("Interpolation Type", Label.LEFT);
    p.add(interpLabel, gbc);

    gbc.gridx = 1;
    gbc.gridy = 0;
    gbc.gridwidth = 1;
    gbc.gridheight = 1;
    interpChoice = new Choice();
    interpChoice.add("Spline");
    interpChoice.add("Linear");
    p.add(interpChoice, gbc);
    interpChoice.addItemListener(this);

    gbc.gridx = 0;
    gbc.gridy = 2;
    gbc.gridwidth = 2;
    gbc.gridheight = 1;
    speedSlider = new Scrollbar(Scrollbar.HORIZONTAL, 2, 1, 0, 11);
    speedSlider.setUnitIncrement(1);
    p.add(speedSlider, gbc);
    speedSlider.addAdjustmentListener(this);

    gbc.gridx = 0;
    gbc.gridy = 3;
    gbc.gridwidth = 2;
    gbc.gridheight = 1;
    speedLabel = new Label(" - Animation Speed +", Label.CENTER);
    p.add(speedLabel, gbc);

    gbc.gridx = 0;
    gbc.gridy = 5;
    gbc.gridwidth = 2;
    gbc.gridheight = 1;
    animateButton = new Button("Stop Animation");
    p.add(animateButton, gbc);
    animateButton.addActionListener(this);

}

From source file:HelloUniverse.java

public VirtualInputDevice(String[] args) {

    // default user-definable values
    printvalues = false;// www .j av a2s. co m
    xscreeninitloc = 400;
    yscreeninitloc = 0;
    xscreensize = 400;
    yscreensize = 200;
    xobjinitloc = 0.0f;
    yobjinitloc = 0.0f;
    zobjinitloc = 2.2f;
    xaxisrotinit = 0.0f;
    yaxisrotinit = 0.0f;
    zaxisrotinit = 0.0f;

    for (int i = 0; i < args.length; i += 2) {
        if (args[i] == null)
            break;
        else if (args[i] == "printvalues")
            printvalues = (Boolean.valueOf(args[i + 1])).booleanValue();
        else if (args[i] == "xscreeninitloc")
            xscreeninitloc = (Integer.valueOf(args[i + 1])).intValue();
        else if (args[i] == "yscreeninitloc")
            yscreeninitloc = (Integer.valueOf(args[i + 1])).intValue();
        else if (args[i] == "xscreensize")
            xscreensize = (Integer.valueOf(args[i + 1])).intValue();
        else if (args[i] == "yscreensize")
            yscreensize = (Integer.valueOf(args[i + 1])).intValue();
        else if (args[i] == "xobjinitloc")
            xobjinitloc = (Float.valueOf(args[i + 1])).floatValue();
        else if (args[i] == "yobjinitloc")
            yobjinitloc = (Float.valueOf(args[i + 1])).floatValue();
        else if (args[i] == "zobjinitloc")
            zobjinitloc = (Integer.valueOf(args[i + 1])).floatValue();
    }

    if (printvalues == true) {
        System.out.println("Initial values for VirtualInputDevice:");
        System.out.println("xscreeninitloc = " + xscreeninitloc);
        System.out.println("yscreeninitloc = " + yscreeninitloc);
        System.out.println("xscreeninitsize = " + xscreensize);
        System.out.println("yscreeninitsize = " + yscreensize);
        System.out.println("xobjinitloc = " + xobjinitloc);
        System.out.println("yobjinitloc = " + yobjinitloc);
        System.out.println("zobjinitloc = " + zobjinitloc);
        System.out.println("xaxisrotinit = " + xaxisrotinit);
        System.out.println("yaxisrotinit = " + yaxisrotinit);
        System.out.println("zaxisrotinit = " + zaxisrotinit);
    }

    // initialize the InputDevice GUI
    Frame deviceFrame = new Frame();
    deviceFrame.setSize(xscreensize, yscreensize);
    deviceFrame.setLocation(xscreeninitloc, yscreeninitloc);
    deviceFrame.setTitle("Virtual Input Device");
    ButtonPositionControls positionControls;
    // initialize position with initial x, y, and z position
    positionControls = new ButtonPositionControls(xobjinitloc, yobjinitloc, zobjinitloc);
    WheelControls rotControls;
    // initialize rotations with initial angles in radians)
    rotControls = new WheelControls(xaxisrotinit, yaxisrotinit, zaxisrotinit);
    positionControls.setDevice(this);
    Panel devicePanel = new Panel();
    devicePanel.setLayout(new BorderLayout());
    devicePanel.add("East", positionControls);
    devicePanel.add("West", rotControls);
    deviceFrame.add(devicePanel);
    deviceFrame.pack();
    deviceFrame.setVisible(true);

    initPos.set(xobjinitloc, yobjinitloc, zobjinitloc);

    this.positionControls = positionControls;
    this.rotControls = rotControls;

    // default processing mode
    processingMode = InputDevice.DEMAND_DRIVEN;

    sensors[0] = new Sensor(this);
}

From source file:gdsc.smlm.ij.plugins.SpotAnalysis.java

private Panel createChoicePanel(Choice list, String label) {
    Panel panel = new Panel();
    panel.setLayout(new BorderLayout());
    Label listLabel = new Label(label, 0);
    //listLabel.setFont(monoFont);
    //list.setSize(fontWidth * 3, fontWidth);
    panel.add(listLabel, BorderLayout.WEST);
    panel.add(list, BorderLayout.CENTER);
    return panel;
}

From source file:gdsc.smlm.ij.plugins.SpotAnalysis.java

private Panel createLabelPanel(Label field, String label, String value) {
    Panel panel = new Panel();
    panel.setLayout(new BorderLayout());
    Label listLabel = new Label(label, 0);
    //listLabel.setFont(monoFont);
    //textField.setSize(fontWidth * 3, fontWidth);
    field.setText(value);//from   ww  w . j av  a  2s  .c o m
    panel.add(listLabel, BorderLayout.WEST);
    panel.add(field, BorderLayout.CENTER);
    return panel;
}

From source file:gdsc.smlm.ij.plugins.SpotAnalysis.java

private Panel createTextPanel(TextField textField, String label, String value) {
    Panel panel = new Panel();
    panel.setLayout(new BorderLayout());
    Label listLabel = new Label(label, 0);
    //listLabel.setFont(monoFont);
    //textField.setSize(fontWidth * 3, fontWidth);
    textField.setText(value);//from www .ja v a 2 s .  co m
    panel.add(listLabel, BorderLayout.WEST);
    panel.add(textField, BorderLayout.CENTER);
    return panel;
}

From source file:Tcpbw100.java

public void showOptions() {
    showStatus(messages.getString("showOptions"));

    if (optionsFrame == null) {
        optionsFrame = new clsFrame();
        optionsFrame.setTitle(messages.getString("options"));

        JPanel optionsPanel = new JPanel();
        optionsPanel.setLayout(new BoxLayout(optionsPanel, BoxLayout.Y_AXIS));

        JPanel testsPanel = new JPanel();
        testsPanel.setBorder(BorderFactory.createTitledBorder(messages.getString("performedTests")));
        testsPanel.add(defaultTest);/*from   w  w  w  .j av  a  2s. c  om*/
        optionsPanel.add(testsPanel);

        JPanel protocolPanel = new JPanel();
        protocolPanel.setBorder(BorderFactory.createTitledBorder(messages.getString("ipProtocol")));
        protocolPanel.add(preferIPv6);
        optionsPanel.add(protocolPanel);

        if (getParameter("enableMultipleTests") != null) {
            JPanel generalPanel = new JPanel();
            generalPanel.setLayout(new BoxLayout(generalPanel, BoxLayout.Y_AXIS));
            generalPanel.setBorder(BorderFactory.createTitledBorder(messages.getString("general")));
            JPanel tmpPanel = new JPanel();
            tmpPanel.add(new JLabel(messages.getString("numberOfTests") + ":"));
            tmpPanel.add(numOfTests);
            generalPanel.add(tmpPanel);
            tmpPanel = new JPanel();
            tmpPanel.add(new JLabel(messages.getString("delayBetweenTests") + ":"));
            tmpPanel.add(delay);
            generalPanel.add(tmpPanel);

            optionsPanel.add(generalPanel);
        }

        optionsFrame.getContentPane().add(optionsPanel);
        Panel buttons = new Panel();
        optionsFrame.getContentPane().add("South", buttons);

        JButton okButton = new JButton(messages.getString("ok"));
        okButton.addActionListener(new ActionListener() {

            public void actionPerformed(ActionEvent e) {
                optionsFrame.toBack();
                optionsFrame.dispose();
            }

        });

        buttons.add("West", okButton);

        optionsFrame.pack();
    }
    optionsFrame.setResizable(false);
    optionsFrame.setVisible(true);
}