List of usage examples for javax.swing JTextField getText
public String getText()
TextComponent
. From source file:se.llbit.chunky.renderer.ui.Adjuster.java
@Override public void actionPerformed(ActionEvent e) { JTextField source = (JTextField) e.getSource(); try {/*from w w w .ja va 2 s . c o m*/ double value = numberFormat.parse(source.getText()).doubleValue(); double sliderValue = QuickMath.clamp(value, min, max); if (clampMin) { value = QuickMath.max(value, min); } if (clampMax) { value = QuickMath.min(value, max); } setSlider(sliderValue); valueChanged(value); } catch (NumberFormatException ex) { } catch (ParseException ex) { // TODO warn user that the value was not updated } }
From source file:se.trixon.jota.client.ui.MainFrame.java
private void requestConnect() throws NotBoundException { String[] hosts = mOptions.getHosts().split(";"); Arrays.sort(hosts);//from w w w.j a va 2s. com DefaultComboBoxModel comboBoxModel = new DefaultComboBoxModel(hosts); JComboBox hostComboBox = new JComboBox(comboBoxModel); hostComboBox.setEditable(true); hostComboBox.setSelectedItem(mClient.getHost()); JTextField portTextField = new JTextField(String.valueOf(mClient.getPortHost())); final JComponent[] inputs = new JComponent[] { new JLabel(Dict.HOST.toString()), hostComboBox, new JLabel(Dict.PORT.toString()), portTextField, }; Object[] options = { Dict.CONNECT.toString(), Dict.CANCEL.toString() }; int retval = JOptionPane.showOptionDialog(this, inputs, Dict.CONNECT_TO_HOST.toString(), JOptionPane.YES_NO_OPTION, JOptionPane.PLAIN_MESSAGE, null, options, options[0]); if (retval == 0) { String currentHost = mClient.getHost(); int currentPort = mClient.getPortHost(); String host = (String) hostComboBox.getSelectedItem(); String portString = portTextField.getText(); try { int port = Integer.valueOf(portString); mManager.disconnect(); mManager.connect(host, port); if (comboBoxModel.getIndexOf(host) == -1) { comboBoxModel.addElement(host); } mOptions.setHosts(SwingHelper.comboBoxModelToString(comboBoxModel)); } catch (NumberFormatException e) { Message.error(this, Dict.ERROR.toString(), String.format(Dict.INVALID_PORT.toString(), portString)); } catch (NotBoundException | MalformedURLException | RemoteException | SocketException ex) { Message.error(this, Dict.ERROR.toString(), ex.getLocalizedMessage()); mClient.setHost(currentHost); mClient.setPortHost(currentPort); } } }
From source file:threads.ButtonThread.java
private String componentToString(JComponent component) { String s = null;//from w w w . ja v a 2 s .c o m if (component instanceof JDateChooser) { JDateChooser dateChooser = (JDateChooser) component; s = ((JTextField) dateChooser.getDateEditor().getUiComponent()).getText(); } else if (component instanceof JTextField) { JTextField textField = (JTextField) component; s = textField.getText(); } return s; }
From source file:tools.help.java
/** * kontrolor na double tie meni bodku ?iarku * * @param Y Jtext field vstup/* w ww .j a v a 2 s. com*/ * @param output ak je Y kokoina tak vyhodi tuto hodnotu * @return */ public static double ReadCheckDouble(javax.swing.JTextField Y, double output) { String hodnota1 = Y.getText(); hodnota1 = hodnota1.replace(" ", ""); String hodnota2 = hodnota1.replace(",", "."); if (hodnota1.equals(hodnota2)) { } else { Y.setText(hodnota2); } Double value; try { value = Double.parseDouble(hodnota2); Y.setForeground(Color.black); return value; } catch (NumberFormatException | NullPointerException e) { Y.setForeground(Color.red); return value = output; } }
From source file:tools.help.java
/** * vyluje to iste ?islo po kontrole a ak je kokotnia tak vrati hodnotu aout * put, a ete ak je kokotina tak vyhodi error sigh * * @param Y Jtext field//w w w . j a va 2 s.c o m * @param output * @return */ public static double ReadCheckDoubleErrorSign(javax.swing.JTextField Y, double output) { String hodnota1 = Y.getText(); hodnota1 = hodnota1.replace(" ", ""); String hodnota2 = hodnota1.replace(",", "."); if (hodnota1.equals(hodnota2)) { } else { Y.setText(hodnota2); } Double value; try { value = Double.parseDouble(hodnota2); Y.setForeground(Color.black); return value; } catch (NumberFormatException | NullPointerException e) { Y.setForeground(Color.red); help.warning1row(language_help.LangLabel(constants.getLanguage_option(), 3)); return value = output; } }
From source file:tools.help.java
public static int ReadCheckIntErrorSign(javax.swing.JTextField Y, int output, String error) { String hodnota1 = Y.getText(); hodnota1 = hodnota1.replace(" ", ""); String hodnota2 = hodnota1.replace(",", "."); if (hodnota1.equals(hodnota2)) { } else {/*from www. java 2s .c om*/ Y.setText(hodnota2); } int value; try { value = Integer.parseInt(hodnota2); Y.setForeground(Color.black); return value; } catch (NumberFormatException | NullPointerException e) { Y.setForeground(Color.red); help.warning1row(error); return value = output; } }
From source file:TrabajoFinalJava.DescargaFichero.java
@Override public void run() { //************************INICIO****INTERFAZ************************************************************************** JFrame principal = new JFrame("GESTOR DESCARGAS"); //Colores/*from www . ja v a2 s . c o m*/ Color nuevoColor = new Color(167, 220, 231); principal.getContentPane().setBackground(nuevoColor); JLabel tituloPrincipal = new JLabel("GESTOR DESCARGAS"); JLabel tituloVentana = new JLabel("DESCARGA FICHERO FTP"); //Recojo la fuente que se esta utilizando actualmente. Font auxFont = tituloPrincipal.getFont(); //Aplico la fuente actual, y al final le doy el tamao del texto... tituloPrincipal.setFont(new Font(auxFont.getFontName(), auxFont.getStyle(), 30)); tituloVentana.setFont(new Font(auxFont.getFontName(), auxFont.getStyle(), 30)); //tituloVentana.setAlignmentY(0); JLabel nombreArchivo = new JLabel("INTRODUCE EL NOMBRE DEL FICHERO A DESCARGAR."); JTextField nombreArchivoIn = new JTextField(); JButton descarga = new JButton("DESCARGA FICHERO."); JButton atras = new JButton("ATRAS"); JButton salir = new JButton("Salir"); GridBagLayout gridbag = new GridBagLayout(); GridBagConstraints gbc = new GridBagConstraints(); //Asignamos la constante EXIT_ON_CLOSE, cierra la ventana al pulsar la X. principal.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); //Asignamos al JFrame el Layout que usaremos, GridBagLayout principal.setLayout(gridbag); //aadir botones al layout gbc.gridx = 1; gbc.gridy = 0; gbc.gridwidth = 1; gbc.gridheight = 1; gbc.weighty = 0.1; // La fila 0 debe estirarse, le ponemos un 1.0 gbc.fill = GridBagConstraints.HORIZONTAL; principal.add(tituloPrincipal, gbc); gbc.gridx = 1; gbc.gridy = 1; gbc.gridwidth = 1; gbc.gridheight = 1; gbc.weighty = 0.1; // La fila 0 debe estirarse, le ponemos un 1.0 gbc.fill = GridBagConstraints.NONE; principal.add(tituloVentana, gbc); gbc.gridx = 1; gbc.gridy = 2; gbc.gridwidth = 1; gbc.gridheight = 1; gbc.weighty = 0.0; gbc.fill = GridBagConstraints.HORIZONTAL; principal.add(nombreArchivo, gbc); gbc.gridx = 1; gbc.gridy = 3; gbc.gridwidth = 1; gbc.gridheight = 1; gbc.weighty = 0.0; gbc.fill = GridBagConstraints.HORIZONTAL; principal.add(nombreArchivoIn, gbc); gbc.gridx = 1; gbc.gridy = 4; gbc.gridwidth = 1; gbc.gridheight = 1; gbc.weighty = 0.0; gbc.fill = GridBagConstraints.NONE; principal.add(descarga, gbc); gbc.gridx = 0; gbc.gridy = 5; gbc.gridwidth = 1; gbc.gridheight = 1; gbc.weighty = 0.1; gbc.fill = GridBagConstraints.NONE; principal.add(atras, gbc); gbc.gridx = 1; gbc.gridy = 5; gbc.gridwidth = 1; gbc.gridheight = 1; gbc.weighty = 0.1; // La fila 0 debe estirarse, le ponemos un 1.0 gbc.fill = GridBagConstraints.HORIZONTAL; principal.add(salir, gbc); //Hace visible el panel principal.setVisible(true); principal.setSize(650, 350); principal.setLocationRelativeTo(null); principal.setResizable(false); //principal.pack(); descarga.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { if (descargasUsuarioLog <= 9) { try { cFtp.connect(ftpSsrver); boolean login = cFtp.login(ftpUser, ftpPass); System.out.print("conexion establecida"); cFtp.enterLocalPassiveMode(); nombreFichero = nombreArchivoIn.getText(); nombrePc = nombreArchivoIn.getText(); CrearListaFicheros listarFicheros = new CrearListaFicheros(); listarFicheros.start(); for (int i = 0; i < CrearListaFicheros.arrayArchivos.size(); i++) { System.out.println(CrearListaFicheros.arrayArchivos.get(i)); } if (CrearListaFicheros.arrayArchivos.contains(nombreFichero)) { FTPFile file = cFtp.mlistFile(nombreFichero); long size = file.getSize(); System.out.println("Tamao del fichero= " + size); if (size > 1000000) { System.out.println("El fichero es muy grande......"); } else { FileOutputStream fos = new FileOutputStream(nombreFichero); cFtp.retrieveFile(nombreFichero, fos); System.out.println(""); System.out.println("Archivo recibido"); nombreArchivoIn.setBackground(Color.green); descargasUsuarioLog = descargasUsuarioLog + 1; System.out.println(descargasUsuarioLog); //modificamos las descargas totales del usuario en la BBDD Connection conn; try { try { Class.forName("com.mysql.jdbc.Driver"); } catch (Exception y) { y.printStackTrace(); } conn = DriverManager.getConnection("jdbc:mysql://127.0.0.1:3306/midb", "root", ""); System.out.println("Conn OK!"); stmt = conn.createStatement(); stmt.executeUpdate("UPDATE usuarios SET bajadas = '" + descargasUsuarioLog + "' WHERE usuario = '" + usuarioLog + "';"); System.out.print("Descargas modificadas correctamente."); conn.close(); } catch (Exception i) { System.out.println(e); } } } else { System.out.println("El fichero no existe..."); nombreArchivoIn.setText("El fichero no existe"); } } catch (IOException r) { r.printStackTrace(); } } else { System.out.println( "No te quedan descargas... por favor comuniquese con el administrador del servidor. Gracias."); nombreArchivoIn.setText( "No te quedan descargas... por favor comuniquese con el administrador del servidor. Gracias."); } } }); atras.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { FormularioAccesoFtp accesoFtp = new FormularioAccesoFtp(); accesoFtp.inicioFtp(); principal.setVisible(false); } }); salir.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { System.exit(1000); } }); }
From source file:ucar.unidata.ui.HttpFormEntry.java
/** * Open a file browser associated with the text field * * @param fld the JTextField//ww w . j av a 2 s .c o m */ public void browse(JTextField fld) { String f = fld.getText(); JFileChooser chooser = new FileManager.MyFileChooser(f); if (chooser.showOpenDialog(fld) == JFileChooser.APPROVE_OPTION) { fld.setText(chooser.getSelectedFile().toString()); } }
From source file:uk.ac.liverpool.narrative.SolutionGraph.java
/** * @param template//w ww . ja v a 2 s . c o m * @param out * @param in * @param current * @return * @throws IOException */ private StringBuilder mainLoop(final Template template, final JTextArea out, final JTextField in, STRIPSState current) throws IOException { Collection<Action> aa = ggraph.getOutEdges(current); StringBuilder ssf = new StringBuilder(); if (aa == null) { out.append("No action from the start?\n"); return ssf; } do { if (aa.size() == 1) { Action a = aa.iterator().next(); out.append(actionToString(template, a)); ssf.append(actionToString(template, a)); if (a != null) { current = ggraph.getOpposite(current, a); } } else if (aa.size() > 1) { int n = 0; final Map<Integer, Action> hm = new MapWrapper<Integer, Action>(); out.append(" Please select the next action: " + "\n"); Iterator<Action> it = aa.iterator(); while (it.hasNext()) { n++; Action a = it.next(); out.append(" " + n + ") " + actionToString(template, a)); hm.put(n, a); } out.append("" + "\n"); final STRIPSState c2 = current; in.addKeyListener(new KeyAdapter() { @Override public void keyReleased(KeyEvent e) { if (e.getKeyCode() != KeyEvent.VK_ENTER) return; int a = 0; String s = in.getText(); try { a = Integer.parseInt(s); } catch (Exception x) { } try { a = Integer.parseInt(s); Action a2 = hm.get(a); if (a2 != null) { out.append(actionToString(template, a2)); in.removeKeyListener(this); in.setText(""); mainLoop(template, out, in, ggraph.getOpposite(c2, a2)); } } catch (Exception x) { return; } super.keyReleased(e); } }); return ssf; } else { break; } aa = ggraph.getOutEdges(current); } while (aa.size() > 0); out.append("The end"); return ssf; }
From source file:uk.ac.ucl.cs.cmic.giftcloud.restserver.GiftCloudLoginDialog.java
public PasswordAuthentication getPasswordAuthentication(final String prompt) { // Set the default background colour to white UIManager UI = new UIManager(); UI.put("OptionPane.background", Color.white); UI.put("Panel.background", Color.white); String defaultUserName = ""; if (giftCloudProperties.getLastUserName().isPresent()) { defaultUserName = giftCloudProperties.getLastUserName().get(); }//w w w . jav a 2 s. c om // Create a panel for entering username and password final JPanel usernamePasswordPanel = new JPanel(new GridBagLayout()); final JLabel promptField = new JLabel(prompt, SwingConstants.CENTER); final JTextField usernameField = new JTextField(defaultUserName, 16); final JPasswordField passwordField = new JPasswordField(16); // Add a special listener to get the focus onto the username field when the component is created, or password if the username has already been populated from the default value if (StringUtils.isBlank(defaultUserName)) { usernameField.addAncestorListener(new RequestFocusListener()); } else { passwordField.addAncestorListener(new RequestFocusListener()); } usernamePasswordPanel.add(promptField, promptConstraint); usernamePasswordPanel.add(new JLabel("Username:"), labelConstraint); usernamePasswordPanel.add(usernameField, fieldConstraint); usernamePasswordPanel.add(new JLabel("Password:"), labelConstraint); usernamePasswordPanel.add(passwordField, fieldConstraint); // Show the login dialog final int returnValue = JOptionPane.showConfirmDialog(new JDialog(getFrame(parent)), usernamePasswordPanel, LOGIN_DIALOG_TITLE, JOptionPane.OK_CANCEL_OPTION, JOptionPane.QUESTION_MESSAGE, icon); if (JOptionPane.OK_OPTION == returnValue) { giftCloudProperties.setLastUserName(usernameField.getText()); giftCloudProperties.setLastPassword(passwordField.getPassword()); giftCloudProperties.save(); return new PasswordAuthentication(usernameField.getText(), passwordField.getPassword()); } else { return null; } }