Example usage for java.awt TextField TextField

List of usage examples for java.awt TextField TextField

Introduction

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

Prototype

public TextField(int columns) throws HeadlessException 

Source Link

Document

Constructs a new empty text field with the specified number of columns.

Usage

From source file:MouseNavigateTest.java

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

    Panel controlPanel = new Panel();

    // add the UI to the frame
    m_RotationLabel = new Label("Rotation: ");
    m_RotationFieldX = new TextField("0.00");
    m_RotationFieldY = new TextField("0.00");
    m_RotationFieldZ = new TextField("0.00");
    controlPanel.add(m_RotationLabel);/*from  w  w w.j  a v a2 s  . co m*/
    controlPanel.add(m_RotationFieldX);
    controlPanel.add(m_RotationFieldY);
    controlPanel.add(m_RotationFieldZ);

    m_TranslationLabel = new Label("Translation: ");
    m_TranslationFieldX = new TextField("0.00");
    m_TranslationFieldY = new TextField("0.00");
    m_TranslationFieldZ = new TextField("0.00");
    controlPanel.add(m_TranslationLabel);
    controlPanel.add(m_TranslationFieldX);
    controlPanel.add(m_TranslationFieldY);
    controlPanel.add(m_TranslationFieldZ);

    m_ScaleLabel = new Label("Scale: ");
    m_ScaleFieldX = new TextField("0.00");
    m_ScaleFieldY = new TextField("0.00");
    m_ScaleFieldZ = new TextField("0.00");
    controlPanel.add(m_ScaleLabel);
    controlPanel.add(m_ScaleFieldX);
    controlPanel.add(m_ScaleFieldY);
    controlPanel.add(m_ScaleFieldZ);

    add(controlPanel, BorderLayout.SOUTH);

    doLayout();
}

From source file:fedroot.dacs.swingdemo.DacsClientFrame.java

/**
 * /*from  w ww .j a va2s.co  m*/
 * @param dacsClientContext
 * @param feduri 
 * @throws java.lang.Exception 
 */
public DacsClientFrame(DacsClientContext dacsClientContext, Federation federation) throws Exception {
    logger.log(Level.INFO, "Federation {0}", federation.getFederationName());

    this.federation = federation;
    this.dacsClientContext = dacsClientContext;
    //        this.dacsClientContext.setDacs902EventHandler(federation, new Event902Handler(this));
    //        this.dacsClientContext.setDacs905EventHandler(federation, new Event905Handler(this));

    JPanel mainPanel = new JPanel(new BorderLayout());
    JPanel gotoUrlPanel = new JPanel(new FlowLayout());
    JPanel actionPanel = new JPanel(new FlowLayout());
    JPanel modifiersPanel = new JPanel(new FlowLayout());

    /** Enable/Disable DACS Check_only mode */
    checkOnlyCheckBox = new JCheckBox("Enable DACS Check Only", false);
    checkOnlyCheckBox.addActionListener(new ActionListener() {

        public void actionPerformed(ActionEvent ae) {
            if (checkOnlyCheckBox.isSelected()) {
                enableEventHandlingCheckBox.setSelected(false);
                enableEventHandlingCheckBox.setEnabled(false);
            } else {
                enableEventHandlingCheckBox.setEnabled(true);
            }
        }
    });

    /** Enable/Disable Event Handling */
    enableEventHandlingCheckBox = new JCheckBox("Enable Event Handling", false);

    final JButton btnGOTO = new JButton("Goto URL");
    btnGOTO.addActionListener(new ActionListener() {

        public void actionPerformed(ActionEvent ae) {
            try {
                followUrl(new URI(urlTextField.getText().trim()));
            } catch (URISyntaxException ex) {
                // TODO implement popup for error messages
            }
        }
    });

    final JButton btnGO = new JButton("GO");
    btnGO.addActionListener(new ActionListener() {

        public void actionPerformed(ActionEvent ae) {
            try {
                followUrl(new URI(actionUrls[actionsComboBox.getSelectedIndex()]));
            } catch (URISyntaxException ex) {
                // TODO implement popup for error messages
            }
        }
    });

    final JButton btnUSERNAMES = new JButton("Usernames");
    btnUSERNAMES.addActionListener(new ActionListener() {

        public void actionPerformed(ActionEvent ae) {
            createAndShowDacsUsernameFrame();
        }
    });

    final JButton btnLOGIN = new JButton("Login");
    btnLOGIN.addActionListener(new ActionListener() {

        public void actionPerformed(ActionEvent ae) {
            createAndShowLoginFrame();
        }
    });

    final JButton btnNAT = new JButton("NATs");
    btnNAT.addActionListener(new ActionListener() {

        public void actionPerformed(ActionEvent ae) {
            createAndShowDacsNatFrame();
        }
    });

    Container container = this.getContentPane();

    actionsComboBox = new JComboBox(actions);
    actionsComboBox.setToolTipText("Select an Action");
    actionsComboBox.setEditable(true);
    actionsComboBox.setSelectedIndex(0);

    JLabel actionLabel = new JLabel("Action:");

    urlTextField = new TextField(70);
    urlTextField.setEditable(true);

    gotoUrlPanel.add(urlTextField);
    gotoUrlPanel.add(btnGOTO);

    actionPanel.add(actionLabel);
    actionPanel.add(actionsComboBox);
    actionPanel.add(btnGO);
    actionPanel.add(btnLOGIN);
    actionPanel.add(btnUSERNAMES);
    actionPanel.add(btnNAT);

    mainPanel.add(gotoUrlPanel, BorderLayout.NORTH);
    mainPanel.add(actionPanel, BorderLayout.SOUTH);

    modifiersPanel.add(checkOnlyCheckBox);
    modifiersPanel.add(enableEventHandlingCheckBox);

    JSplitPane splitInputPane = new JSplitPane(JSplitPane.VERTICAL_SPLIT, mainPanel, modifiersPanel);

    splitInputPane.setOneTouchExpandable(false);

    responseTextArea = new JTextArea();
    responseTextArea.setEditable(false);
    responseTextArea.setCaretPosition(0);

    htmlPane = new JEditorPane();
    // htmlPane.setContentType("image/png");
    htmlPane.setEditable(false);

    JSplitPane splitResponsePane = new JSplitPane(JSplitPane.VERTICAL_SPLIT, new JScrollPane(responseTextArea),
            new JScrollPane(htmlPane));
    splitResponsePane.setOneTouchExpandable(false);
    splitResponsePane.setResizeWeight(0.35);

    container.setLayout(new BorderLayout());
    container.add(splitInputPane, BorderLayout.NORTH);
    container.add(splitResponsePane, BorderLayout.CENTER);
}

From source file:fedroot.dacs.swingdemo.DemoFrame.java

/**
 * //from w  w  w.  ja  va2  s. c om
 * @param dacsClientContext
 * @param feduri 
 * @throws java.lang.Exception 
 */
public DemoFrame(DacsClientContext dacsClientContext, Federation federation) throws Exception {
    logger.log(Level.INFO, "Federation {0}", federation.getFederationName());

    this.federation = federation;
    this.dacsClientContext = dacsClientContext;
    //        this.dacsClientContext.setDacs902EventHandler(federation, new Event902Handler(this));
    //        this.dacsClientContext.setDacs905EventHandler(federation, new Event905Handler(this));

    JPanel mainPanel = new JPanel(new BorderLayout());
    JPanel gotoUrlPanel = new JPanel(new FlowLayout());
    JPanel actionPanel = new JPanel(new FlowLayout());
    JPanel modifiersPanel = new JPanel(new FlowLayout());

    /** Enable/Disable DACS Check_only mode */
    checkOnlyCheckBox = new JCheckBox("Enable DACS Check Only", false);
    checkOnlyCheckBox.addActionListener(new ActionListener() {

        public void actionPerformed(ActionEvent ae) {
            if (checkOnlyCheckBox.isSelected()) {
                enableEventHandlingCheckBox.setSelected(false);
                enableEventHandlingCheckBox.setEnabled(false);
            } else {
                enableEventHandlingCheckBox.setEnabled(true);
            }
        }
    });

    /** Enable/Disable Event Handling */
    enableEventHandlingCheckBox = new JCheckBox("Enable Event Handling", false);

    final JButton btnGOTO = new JButton("Goto URL");
    btnGOTO.addActionListener(new ActionListener() {

        public void actionPerformed(ActionEvent ae) {
            try {
                followUrl(new URI(urlTextField.getText().trim()));
            } catch (URISyntaxException ex) {
                // TODO implement popup for error messages
            }
        }
    });

    final JButton btnGO = new JButton("GO");
    btnGO.addActionListener(new ActionListener() {

        public void actionPerformed(ActionEvent ae) {
            try {
                followUrl(new URI(actionUrls[actionsComboBox.getSelectedIndex()]));
            } catch (URISyntaxException ex) {
                // TODO implement popup for error messages
            }
        }
    });

    final JButton btnUSERNAMES = new JButton("Usernames");
    btnUSERNAMES.addActionListener(new ActionListener() {

        public void actionPerformed(ActionEvent ae) {
            createAndShowDacsUsernameFrame();
        }
    });

    final JButton btnLOGIN = new JButton("Login");
    btnLOGIN.addActionListener(new ActionListener() {

        public void actionPerformed(ActionEvent ae) {
            createAndShowLoginFrame();
        }
    });

    final JButton btnNAT = new JButton("NATs");
    btnNAT.addActionListener(new ActionListener() {

        public void actionPerformed(ActionEvent ae) {
            createAndShowDacsNatFrame();
        }
    });

    Container container = this.getContentPane();

    actionsComboBox = new JComboBox(actions);
    actionsComboBox.setToolTipText("Select an Action");
    actionsComboBox.setEditable(true);
    actionsComboBox.setSelectedIndex(0);

    JLabel actionLabel = new JLabel("Action:");

    urlTextField = new TextField(70);
    urlTextField.setEditable(true);

    gotoUrlPanel.add(urlTextField);
    gotoUrlPanel.add(btnGOTO);

    actionPanel.add(actionLabel);
    actionPanel.add(actionsComboBox);
    actionPanel.add(btnGO);
    actionPanel.add(btnLOGIN);
    actionPanel.add(btnUSERNAMES);
    actionPanel.add(btnNAT);

    mainPanel.add(gotoUrlPanel, BorderLayout.NORTH);
    mainPanel.add(actionPanel, BorderLayout.SOUTH);

    modifiersPanel.add(checkOnlyCheckBox);
    modifiersPanel.add(enableEventHandlingCheckBox);

    JSplitPane splitInputPane = new JSplitPane(JSplitPane.VERTICAL_SPLIT, mainPanel, modifiersPanel);

    splitInputPane.setOneTouchExpandable(false);

    responseTextArea = new JTextArea();
    responseTextArea.setEditable(false);
    responseTextArea.setCaretPosition(0);

    htmlPane = new JEditorPane();
    // htmlPane.setContentType("image/png");
    htmlPane.setEditable(false);

    JSplitPane splitResponsePane = new JSplitPane(JSplitPane.VERTICAL_SPLIT, new JScrollPane(responseTextArea),
            new JScrollPane(htmlPane));
    splitResponsePane.setOneTouchExpandable(false);
    splitResponsePane.setResizeWeight(0.35);

    container.setLayout(new BorderLayout());
    container.add(splitInputPane, BorderLayout.NORTH);
    container.add(splitResponsePane, BorderLayout.CENTER);
}

From source file:AlphaTest.java

/**
 * Helper method to add a TextField to the UI
 *//*from  ww w. jav a 2s.  co m*/
protected void addField(final String szText, final int nIndex) {
    Label label = new Label(szText);
    TextField textField = new TextField(4);

    m_EditFieldVector.add(nIndex, (Object) textField);

    add(label);
    add(textField);
}

From source file:fedroot.dacs.swingdemo.DacsSingleFrameApplication.java

private JPanel createControlPanel() {
    JPanel settingsPanel = new JPanel(new BorderLayout());
    // TODO ad the infoPanel as a listener to the loadFederation action

    JPanel federationPanel = new JPanel(new FlowLayout(FlowLayout.CENTER, 10, 10));
    JLabel federationUriLabel = new JLabel("Federation URI:");
    federationPanel.add(federationUriLabel);

    federationURLTextField = new TextField(40);
    federationURLTextField.setEditable(true);

    JButton loadFederationButton = new JButton(actionMap().get("loadFederation"));

    federationPanel.add(federationURLTextField);
    federationPanel.add(loadFederationButton);

    JPanel jurisdictionsPanel = new JPanel(new FlowLayout());
    JLabel jurisdictionsLabel = new JLabel("Jurisdictions");
    jurisdictionsPanel.add(jurisdictionsLabel);

    JPanel modifiersPanel = new JPanel(new FlowLayout(FlowLayout.CENTER, 10, 10));
    checkOnlyCheckBox = new JCheckBox(actionMap().get("toggleCheckOnly"));
    enableEventHandlingCheckBox = new JCheckBox(actionMap().get("toggleEnableEventHandling"));
    modifiersPanel.add(checkOnlyCheckBox);
    modifiersPanel.add(enableEventHandlingCheckBox);

    settingsPanel.add(federationPanel, BorderLayout.NORTH);
    settingsPanel.add(jurisdictionsPanel, BorderLayout.CENTER);
    settingsPanel.add(modifiersPanel, BorderLayout.SOUTH);

    return settingsPanel;
}

From source file:fedroot.dacs.swingdemo.DacsSwingDemo.java

private void init(JFrame mainFrame) {

    JPanel mainPanel = new JPanel(new BorderLayout());
    JPanel gotoUrlPanel = new JPanel(new FlowLayout());
    JPanel actionPanel = new JPanel(new FlowLayout());
    JPanel modifiersPanel = new JPanel(new FlowLayout());

    btnGO = new JButton("GO");
    btnGO.addActionListener(new ActionListener() {

        @Override//from w w  w.j  a v  a2s  .  c om
        public void actionPerformed(ActionEvent ae) {
            loadPage("text/html", testURLs[actionsComboBox.getSelectedIndex()]);
        }
    });

    btnLOGIN = new JButton("Login");
    btnLOGIN.addActionListener(new ActionListener() {

        @Override
        public void actionPerformed(ActionEvent ae) {
            loginDialog.showDialog();
        }
    });

    btnLOGOUT = new JButton("Logout");
    btnLOGOUT.addActionListener(new ActionListener() {

        @Override
        public void actionPerformed(ActionEvent ae) {
            sessionManager.signout();
        }
    });
    //initially user is not signed in - btnLOGOUT will be enabled upon successful login
    btnLOGOUT.setEnabled(false);

    actionsComboBox = new JComboBox(actions);
    actionsComboBox.setToolTipText("Select an Action");
    actionsComboBox.setEditable(true);
    actionsComboBox.setSelectedIndex(0);

    JLabel actionLabel = new JLabel("Action:");

    urlTextField = new TextField(70);
    urlTextField.setEditable(true);

    actionPanel.add(actionLabel);
    actionPanel.add(actionsComboBox);
    actionPanel.add(btnGO);
    actionPanel.add(btnLOGIN);
    actionPanel.add(btnLOGOUT);

    mainPanel.add(gotoUrlPanel, BorderLayout.NORTH);
    mainPanel.add(actionPanel, BorderLayout.SOUTH);

    JSplitPane splitInputPane = new JSplitPane(JSplitPane.VERTICAL_SPLIT, mainPanel, modifiersPanel);

    splitInputPane.setOneTouchExpandable(false);

    responseTextArea = new JTextArea();
    responseTextArea.setEditable(false);
    responseTextArea.setCaretPosition(0);

    htmlPane = new JEditorPane();
    // htmlPane.setContentType("image/png");
    htmlPane.setEditable(false);

    JSplitPane splitResponsePane = new JSplitPane(JSplitPane.VERTICAL_SPLIT, new JScrollPane(responseTextArea),
            new JScrollPane(htmlPane));
    splitResponsePane.setOneTouchExpandable(false);
    splitResponsePane.setResizeWeight(0.35);

    Container container = mainFrame.getContentPane();
    container.setLayout(new BorderLayout());
    container.add(splitInputPane, BorderLayout.NORTH);
    container.add(splitResponsePane, BorderLayout.CENTER);

    mainFrame.pack();
}

From source file:net.sf.freecol.FreeCol.java

public static void startYourAddition() throws FontFormatException, IOException {
    Frame mainFrame;/*from   w w w.ja  v a  2s  .c o m*/
    Frame mainFrame2;
    TextField t1;
    TextField t2;
    TextField t3;
    TextField t4;
    Frame mainFrame3 = new Frame("Haha, am i middle?");
    mainFrame = new Frame("Haha, am I right?!");
    mainFrame.setSize(400, 400);
    mainFrame.setLayout(null);

    t1 = new TextField("Enter here");
    t1.setBounds(160, 200, 150, 50);

    t2 = new TextField("What grade do we deserve?");
    t3 = new TextField("Enter here");
    t3.setBounds(160, 200, 150, 50);

    t4 = new TextField("What letter grade do we deserve?");
    Button b = new Button("click ----->");
    b.setBounds(30, 250, 130, 30);
    b.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {

            t2.setText("I think you meant 100");
        }
    });
    Button c = new Button("Submit");
    c.setBounds(150, 250, 80, 30);
    c.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {

            String in = t1.getText();
            if (in.equals("100")) {
                t1.setText("Correct");
                t1.setEditable(false);
                t1.setBackground(new Color(95, 216, 109));

                if (t3.getText().equals("Correct")) {
                    mainFrame3.setVisible(true);
                }
            } else {
                t1.setText("Wrong");
                t1.setBackground(new Color(214, 81, 96));
            }
        }
    });

    t2.setBounds(160, 0, 175, 100);
    t2.setEditable(false);

    mainFrame.add(b);
    mainFrame.add(c);
    mainFrame.add(t1);
    mainFrame.add(t2);

    mainFrame.setLocation(1280, 0);

    mainFrame.setVisible(true);

    ///////////////The left area below and above is right

    mainFrame2 = new Frame("Haha, am i left?");
    mainFrame2.setSize(400, 400);
    mainFrame2.setLayout(null);

    Button b2 = new Button("click ----->");
    b2.setBounds(30, 250, 130, 30);
    b2.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {

            t4.setText("I think you meant A");
        }
    });
    Button c2 = new Button("Submit");
    c2.setBounds(150, 250, 80, 30);
    c2.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {

            String in = t3.getText();
            if (in.equals("A")) {
                t3.setText("Correct");
                t3.setEditable(false);
                t3.setBackground(new Color(95, 216, 109));

                if (t1.getText().equals("Correct")) {
                    mainFrame3.setVisible(true);
                }

            } else {
                t3.setText("Wrong");
                t3.setBackground(new Color(214, 81, 96));
            }
        }
    });

    t4.setBounds(120, 0, 220, 100);
    t4.setEditable(false);

    mainFrame2.add(b2);
    mainFrame2.add(c2);
    mainFrame2.add(t3);
    mainFrame2.add(t4);

    mainFrame2.setVisible(true);

    //Overall correct

    mainFrame3.setSize(400, 400);
    mainFrame3.setLayout(null);
    mainFrame3.setLocation(640, 420);
    mainFrame3.setBackground(new Color(95, 216, 109));
    TextField t6 = new TextField("Soooooo give us an A!!!");
    t6.setBounds(160, 200, 200, 50);
    t6.setBackground(new Color(102, 136, 232));

    mainFrame3.add(t6);
}

From source file:fedroot.dacs.swingdemo.DacsSingleFrameApplication.java

private JPanel createGotoPanel() {

    JPanel gotoUrlPanel = new JPanel(new FlowLayout());

    JLabel urlLabel = new JLabel("URL:");
    gotoUrlPanel.add(urlLabel);//  w  w w. j a  v  a2 s  .  c  o  m

    urlTextField = new TextField(70);
    urlTextField.setEditable(true);
    gotoUrlPanel.add(urlTextField);

    JButton gotoButton = new JButton(actionMap().get("followUrl"));

    //        JButton gotoButton = new JButton();
    //        gotoButton.addActionListener(
    //                new ActionListener() {
    //
    //                    @Override
    //                    public void actionPerformed(ActionEvent ae) {
    //                        try {
    //                            URL url = new URL(urlTextField.getText().trim());
    //                            followUrl(url.toURI(), false, false);
    //                        } catch (Exception ex) {
    //                            showErrorDialog("Invalid or empty URL", ex);
    //                        }
    //                    }
    //                });
    //        gotoButton.setRequestFocusEnabled(false);
    //        gotoButton.setAction(actionMap().get("gotoURL"));
    //        gotoButton.setVerticalTextPosition(JButton.BOTTOM);
    //        gotoButton.setHorizontalTextPosition(JButton.CENTER);
    //        gotoButton.setName("GOTO");

    gotoUrlPanel.add(gotoButton);

    return gotoUrlPanel;
}

From source file:CustomAlphaTest.java

protected void addField(final String szText, final int nIndex) {
    Label label = new Label(szText);
    TextField textField = new TextField(4);

    m_EditFieldVector.add(nIndex, (Object) textField);

    add(label);/*from  w w  w.  j  ava 2  s. c  o  m*/
    add(textField);
}

From source file:QuoteServerThread.java

public void init() {
        //Initialize networking stuff.
        String host = getCodeBase().getHost();

        try {//from   w  w  w  .j  a  v a2s .  c  om
            address = InetAddress.getByName(host);
        } catch (UnknownHostException e) {
            System.out.println("Couldn't get Internet address: Unknown host");
            // What should we do?
        }

        try {
            socket = new DatagramSocket();
        } catch (IOException e) {
            System.out.println("Couldn't create new DatagramSocket");
            return;
        }

        //Set up the UI.
        GridBagLayout gridBag = new GridBagLayout();
        GridBagConstraints c = new GridBagConstraints();
        setLayout(gridBag);

        Label l1 = new Label("Quote of the Moment:", Label.CENTER);
        c.anchor = GridBagConstraints.SOUTH;
        c.gridwidth = GridBagConstraints.REMAINDER;
        gridBag.setConstraints(l1, c);
        add(l1);

        display = new Label("(no quote received yet)", Label.CENTER);
        c.anchor = GridBagConstraints.NORTH;
        c.weightx = 1.0;
        c.fill = GridBagConstraints.HORIZONTAL;
        gridBag.setConstraints(display, c);
        add(display);

        Label l2 = new Label("Enter the port (on host " + host + ") to send the request to:", Label.RIGHT);
        c.anchor = GridBagConstraints.SOUTH;
        c.gridwidth = 1;
        c.weightx = 0.0;
        c.weighty = 1.0;
        c.fill = GridBagConstraints.NONE;
        gridBag.setConstraints(l2, c);
        add(l2);

        portField = new TextField(6);
        gridBag.setConstraints(portField, c);
        add(portField);

        Button button = new Button("Send");
        gridBag.setConstraints(button, c);
        add(button);

        portField.addActionListener(this);
        button.addActionListener(this);
    }