Example usage for javax.swing JTextField getText

List of usage examples for javax.swing JTextField getText

Introduction

In this page you can find the example usage for javax.swing JTextField getText.

Prototype

public String getText() 

Source Link

Document

Returns the text contained in this TextComponent.

Usage

From source file:main.UIController.java

public void convertToGregorian() {
    UI window = this.getUi();

    String errorNoLoa = "Please insert a loa.";
    String errorLoaNotNumeric = "Please insert the loa as a numeric value.";
    String errorYearNotValid = "Please insert a valid loa (from 1 to 144).";
    String errorDayNotRead = "Sorry, the day could not be read.";

    JComboBox yen = window.getYen();
    JTextField loa = window.getLoa();
    JComboBox period = window.getPeriod();
    JComboBox day = window.getDayOfLoa();
    JCheckBox beforeMidnight = window.getBeforeMidnight();
    JTextPane result = window.getResGregorian();
    int yenNum = yen.getSelectedIndex() + 1;
    String value = loa.getText();
    if (!value.isEmpty()) {
        try {//from  w w  w. j a v a  2  s.co m
            int loaNum = Integer.parseInt(value);
            if (loaNum > 0 && loaNum <= 144) {
                int periodNum = period.getSelectedIndex() + 1;
                ImladrisCalendar cal = new ImladrisCalendar();
                boolean success = false;
                if (periodNum == ImladrisCalendar.YESTARE || periodNum == ImladrisCalendar.METTARE) {
                    success = true;
                    cal = new ImladrisCalendar(cal.intToRoman(yenNum), loaNum, periodNum);
                } else {
                    int dayNum = 0;
                    if (day.isEnabled()) {
                        success = true;
                        dayNum = day.getSelectedIndex() + 1;
                        cal = new ImladrisCalendar(cal.intToRoman(yenNum), loaNum, periodNum, dayNum);
                    } else {
                        result.setText(errorDayNotRead);
                    }
                }
                if (success) {
                    GregorianCalendar gcal = cal.getGregorian();
                    if (beforeMidnight.isSelected()) {
                        gcal.add(GregorianCalendar.DAY_OF_YEAR, -1);
                    }
                    String gstr = this.gregorianToString(gcal);
                    result.setText(gstr);
                }
            } else {
                result.setText(errorYearNotValid);
            }
        } catch (NumberFormatException e) {
            result.setText(errorLoaNotNumeric);
        }
    } else {
        result.setText(errorNoLoa);
    }
}

From source file:com.gs.obevo.util.inputreader.DialogInputReader.java

@Override
public String readLine(String promptMessage) {
    final JTextField juf = new JTextField();
    JOptionPane juop = new JOptionPane(juf, JOptionPane.QUESTION_MESSAGE, JOptionPane.OK_CANCEL_OPTION);
    JDialog userDialog = juop.createDialog(promptMessage);
    userDialog.addComponentListener(new ComponentAdapter() {
        @Override/*w  w  w.  j  a  va  2s.c om*/
        public void componentShown(ComponentEvent e) {
            SwingUtilities.invokeLater(new Runnable() {
                @Override
                public void run() {
                    juf.requestFocusInWindow();
                }
            });
        }
    });
    userDialog.setVisible(true);
    int uresult = (Integer) juop.getValue();
    userDialog.dispose();
    String userName = null;
    if (uresult == JOptionPane.OK_OPTION) {
        userName = new String(juf.getText());
    }

    if (StringUtils.isEmpty(userName)) {
        return null;
    } else {
        return userName;
    }
}

From source file:com.sun.jersey.client.apache.config.DefaultCredentialsProvider.java

public Credentials getCredentials(AuthScheme scheme, String host, int port, boolean proxy)
        throws CredentialsNotAvailableException {
    if (scheme == null) {
        return null;
    }/* w  ww.j  a  v  a  2s.com*/

    try {
        JTextField userField = new JTextField();
        JPasswordField passwordField = new JPasswordField();
        int response;

        if (scheme instanceof NTLMScheme) {
            JTextField domainField = new JTextField();
            Object[] msg = { host + ":" + port + " requires Windows authentication", "Domain", domainField,
                    "User Name", userField, "Password", passwordField };
            response = JOptionPane.showConfirmDialog(null, msg, "Authenticate", JOptionPane.OK_CANCEL_OPTION);

            if ((response == JOptionPane.CANCEL_OPTION) || (response == JOptionPane.CLOSED_OPTION)) {
                throw new CredentialsNotAvailableException("User cancled windows authentication.");
            }

            return new NTCredentials(userField.getText(), new String(passwordField.getPassword()), host,
                    domainField.getText());

        } else if (scheme instanceof RFC2617Scheme) {
            Object[] msg = {
                    host + ":" + port + " requires authentication with the realm '" + scheme.getRealm() + "'",
                    "User Name", userField, "Password", passwordField };

            response = JOptionPane.showConfirmDialog(null, msg, "Authenticate", JOptionPane.OK_CANCEL_OPTION);

            if ((response == JOptionPane.CANCEL_OPTION) || (response == JOptionPane.CLOSED_OPTION)) {
                throw new CredentialsNotAvailableException("User cancled windows authentication.");
            }

            return new UsernamePasswordCredentials(userField.getText(),
                    new String(passwordField.getPassword()));

        } else {

            throw new CredentialsNotAvailableException(
                    "Unsupported authentication scheme: " + scheme.getSchemeName());

        }
    } catch (IOException ioe) {

        throw new CredentialsNotAvailableException(ioe.getMessage(), ioe);

    }
}

From source file:com.smanempat.controller.ControllerEvaluation.java

public void validasiNumberofNearest(KeyEvent evt, JTextField txtNumberOfK, JLabel labelPesanError,
        JTable tableDataSetModel) {
    String numberValidate = txtNumberOfK.getText();
    int modelRow = tableDataSetModel.getRowCount();
    if (Pattern.matches("[0-9]+", numberValidate) == false && numberValidate.length() > 0) {
        evt.consume();/*from  w w w  .  j ava 2 s . co m*/
        labelPesanError.setText("Number of Nearest Neighbor tidak valid");
    } else if (numberValidate.length() == 9) {
        evt.consume();
        labelPesanError.setText("Number of Nearest Neighbor terlalu panjang");
    } else {
        labelPesanError.setText("");
    }
}

From source file:Applet.EmbeddedChart.java

public synchronized void updateInfo(String[] legends, List<double[][]> yVals, boolean gofr) {
    removeAll();//from   w w  w .j a  va2 s.  com
    GridBagLayout gbl = new GridBagLayout();
    gbl.columnWidths = new int[] { 10, 0, 0 };
    gbl.rowHeights = new int[] { 0, 0, 0 };
    gbl.columnWeights = new double[] { 0.0, 1.0, 1.0 };
    gbl.rowWeights = new double[] { 1.0, 1.0, 0.0 };
    setLayout(gbl);

    this.legends = legends;
    this.yvals = yVals;
    this.gofr = gofr;

    XYDataset dataset = createDataset(gofr, legends, yVals);
    JFreeChart chart = createChart(dataset, title, gofr);
    chartPanel = new ChartPanel(chart);
    chartPanel.setMinimumDrawWidth(0);
    chartPanel.setMinimumDrawHeight(0);
    chartPanel.setMaximumDrawWidth(2000);
    chartPanel.setMaximumDrawHeight(2000);
    XYPlot plot = (XYPlot) chart.getPlot();
    plot.setBackgroundPaint(Color.white);
    chartPanel.getChart().setBackgroundPaint(null);
    GridBagConstraints gbc = new GridBagConstraints();
    gbc.gridx = 1;
    gbc.gridy = 0;
    gbc.gridwidth = 2;
    gbc.gridheight = 2;
    gbc.fill = GridBagConstraints.BOTH;
    add(chartPanel, gbc);

    GridBagConstraints gbcX1 = new GridBagConstraints();
    GridBagConstraints gbcX2 = new GridBagConstraints();
    GridBagConstraints gbcY1 = new GridBagConstraints();
    GridBagConstraints gbcY2 = new GridBagConstraints();
    GridBagConstraints gbcButton = new GridBagConstraints();
    final NumberAxis domain = (NumberAxis) ((XYPlot) chartPanel.getChart().getPlot()).getDomainAxis();
    final NumberAxis range = (NumberAxis) ((XYPlot) chartPanel.getChart().getPlot()).getRangeAxis();

    if (gofr) {
        domain.setLowerBound(over.gr_xMin);
        domain.setUpperBound(over.gr_xMax);
        range.setLowerBound(over.gr_yMin);
        range.setUpperBound(over.gr_yMax);
    } else {
        domain.setLowerBound(over.pot_xMin);
        domain.setUpperBound(over.pot_xMax);
        range.setLowerBound(over.pot_yMin);
        range.setUpperBound(over.pot_yMax);
    }

    gbcX2.gridx = 2;
    gbcX2.gridy = 2;
    gbcX2.anchor = GridBagConstraints.EAST;
    gbcX2.insets = new Insets(0, 0, 0, 12);
    final JTextField xMax = new JTextField(5);
    xMax.setMinimumSize(new Dimension(50, 20));
    xMax.setText("" + domain.getUpperBound());
    // gbcX2.fill = GridBagConstraints.VERTICAL;
    add(xMax, gbcX2);
    final boolean gr = gofr;
    xMax.addFocusListener(new FocusListener() {

        @Override
        public void focusLost(FocusEvent e) {
            if (gr) {
                over.gr_xMax = Double.parseDouble(xMax.getText());
                domain.setRange(over.gr_xMin, over.gr_xMax);
            } else {
                over.pot_xMax = Double.parseDouble(xMax.getText());
                domain.setRange(over.pot_xMin, over.pot_xMax);
            }
        }

        @Override
        public void focusGained(FocusEvent e) {
        }
    });

    gbcX1.gridx = 1;
    gbcX1.gridy = 2;
    gbcX1.anchor = GridBagConstraints.WEST;
    gbcX1.insets = new Insets(0, 70, 0, 0);
    final JTextField xMin = new JTextField(5);
    xMin.setMinimumSize(new Dimension(50, 20));
    xMin.setText("" + domain.getLowerBound());
    // gbcX1.fill = GridBagConstraints.VERTICAL;
    add(xMin, gbcX1);
    xMin.addFocusListener(new FocusListener() {

        @Override
        public void focusLost(FocusEvent e) {
            x1 = Double.parseDouble(xMin.getText());
            domain.setRange(x1, x2);
            if (gr) {
                over.gr_xMin = Double.parseDouble(xMin.getText());
                domain.setRange(over.gr_xMin, over.gr_xMax);
            } else {
                over.pot_xMin = Double.parseDouble(xMin.getText());
                domain.setRange(over.pot_xMin, over.pot_xMax);
            }
        }

        @Override
        public void focusGained(FocusEvent e) {
        }
    });

    gbcY1.gridx = 0;
    gbcY1.gridy = 1;
    gbcY1.anchor = GridBagConstraints.SOUTH;
    gbcY1.insets = new Insets(0, 0, 45, 0);
    final JTextField yMin = new JTextField(5);
    yMin.setMinimumSize(new Dimension(50, 20));
    yMin.setText("" + range.getLowerBound());
    // gbcY1.fill = GridBagConstraints.BOTH;
    add(yMin, gbcY1);
    yMin.addFocusListener(new FocusListener() {

        @Override
        public void focusLost(FocusEvent e) {
            if (gr) {
                over.gr_yMin = Double.parseDouble(yMin.getText());
                range.setRange(over.gr_yMin, over.gr_yMax);
            } else {
                over.pot_yMin = Double.parseDouble(yMin.getText());
                range.setRange(over.pot_yMin, over.pot_yMax);
            }

        }

        @Override
        public void focusGained(FocusEvent e) {
        }
    });

    gbcY2.gridx = 0;
    gbcY2.gridy = 0;
    gbcY2.anchor = GridBagConstraints.NORTH;
    gbcY2.insets = new Insets(10, 0, 0, 0);
    final JTextField yMax = new JTextField(5);
    yMax.setMinimumSize(new Dimension(50, 20));
    yMax.setText("" + range.getUpperBound());
    // gbcY2.fill = GridBagConstraints.BOTH;
    add(yMax, gbcY2);
    yMax.addFocusListener(new FocusListener() {

        @Override
        public void focusLost(FocusEvent e) {
            if (gr) {
                over.gr_yMax = Double.parseDouble(yMax.getText());
                range.setRange(over.gr_yMin, over.gr_yMax);
            } else {
                over.pot_yMax = Double.parseDouble(yMax.getText());
                range.setRange(over.pot_yMin, over.pot_yMax);
            }
        }

        @Override
        public void focusGained(FocusEvent e) {
        }
    });

}

From source file:com.rapidminer.gui.new_plotter.gui.dialog.ManageZoomDialog.java

/**
 * Verify that the x-value is correct./*from  www.j a  v  a 2  s. c o m*/
 * 
 * @param input
 * @return true if the value is valid; false otherwise
 */
private boolean verifyDomainRangeUpperBoundInput(JComponent input) {
    JTextField textField = (JTextField) input;
    String inputString = textField.getText();
    try {
        double domainUpperBound;
        if (inputString.startsWith("-")) {
            domainUpperBound = Double.parseDouble(inputString.substring(1));
            domainUpperBound = -domainUpperBound;
        } else {
            domainUpperBound = Double.parseDouble(inputString);
        }
        // TODO: fix check for actual ranges
    } catch (NumberFormatException e) {
        textField.setForeground(Color.RED);
        return false;
    }

    textField.setForeground(Color.BLACK);
    return true;
}

From source file:com.rapidminer.gui.new_plotter.gui.dialog.ManageZoomDialog.java

/**
 * Verify that the y-value is correct.//  ww w .  j  ava 2  s . co m
 * 
 * @param input
 * @return true if the value is valid; false otherwise
 */
private boolean verifyDomainRangeLowerBoundInput(JComponent input) {
    JTextField textField = (JTextField) input;
    String inputString = textField.getText();
    try {
        double domainLowerBound;
        if (inputString.startsWith("-")) {
            domainLowerBound = Double.parseDouble(inputString.substring(1));
            domainLowerBound = -domainLowerBound;
        } else {
            domainLowerBound = Double.parseDouble(inputString);
        }
        // TODO: fix check for actual ranges
    } catch (NumberFormatException e) {
        textField.setForeground(Color.RED);
        return false;
    }

    textField.setForeground(Color.BLACK);
    return true;
}

From source file:com.rapidminer.gui.new_plotter.gui.dialog.ManageZoomDialog.java

/**
 * Verify that the width value is correct.
 * /*from w w  w .  jav a2s . c  o  m*/
 * @param input
 * @return true if the value is valid; false otherwise
 */
private boolean verifyValueRangeLowerBoundInput(JComponent input) {
    JTextField textField = (JTextField) input;
    String inputString = textField.getText();
    try {
        double valueLowerBound;
        if (inputString.startsWith("-")) {
            valueLowerBound = Double.parseDouble(inputString.substring(1));
            valueLowerBound = -valueLowerBound;
        } else {
            valueLowerBound = Double.parseDouble(inputString);
        }
        // TODO: fix check for actual ranges
    } catch (NumberFormatException e) {
        textField.setForeground(Color.RED);
        return false;
    }

    textField.setForeground(Color.BLACK);
    return true;
}

From source file:com.rapidminer.gui.new_plotter.gui.dialog.ManageZoomDialog.java

/**
 * Verify that the height value is correct.
 * /* w w  w  .j a  va2 s . co m*/
 * @param input
 * @return true if the value is valid; false otherwise
 */
private boolean verifyValueRangeUpperBoundInput(JComponent input) {
    JTextField textField = (JTextField) input;
    String inputString = textField.getText();
    try {
        double valueUpperBound;
        if (inputString.startsWith("-")) {
            valueUpperBound = Double.parseDouble(inputString.substring(1));
            valueUpperBound = -valueUpperBound;
        } else {
            valueUpperBound = Double.parseDouble(inputString);
        }
        // TODO: fix check for actual ranges
    } catch (NumberFormatException e) {
        textField.setForeground(Color.RED);
        return false;
    }

    textField.setForeground(Color.BLACK);
    return true;
}

From source file:com.rapidminer.gui.new_plotter.gui.dialog.ManageZoomDialog.java

/**
 * Verify that the color value is correct.
 * /*ww w .  j  a  v a  2s  .co  m*/
 * @param input
 * @return true if the value is valid; false otherwise
 */
private boolean verifyColorInput(JComponent input) {
    JTextField textField = (JTextField) input;
    String inputString = textField.getText();
    try {
        double color;
        if (inputString.startsWith("-")) {
            color = Double.parseDouble(inputString.substring(1));
            color = -color;
        } else {
            color = Double.parseDouble(inputString);
        }
        // TODO: fix check for actual ranges
    } catch (NumberFormatException e) {
        textField.setForeground(Color.RED);
        return false;
    }

    textField.setForeground(Color.BLACK);
    return true;
}