List of usage examples for javax.swing JTextField getText
public String getText()
TextComponent
. From source file:com.smanempat.controller.ControllerClassification.java
public void validasiNumberofNearest(java.awt.event.KeyEvent evt, JTextField textNumberOfK, JLabel labelPesanError) { ModelClassification modelClassification = new ModelClassification(); String numberValidate = textNumberOfK.getText(); int modelRow = modelClassification.getRowCount(); if (Pattern.matches("[0-9]+", numberValidate) == false && numberValidate.length() > 0) { evt.consume();// w w w . j a v a 2 s .c om 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:edu.ku.brc.helpers.EMailHelper.java
/** * Asks for a username and password.//from w w w . j a v a 2 s.c om * @param topframe the parent frame * @return the list of user[index 1] and password[index 2], or 'null' if cancel was pressed */ public static ArrayList<String> askForUserAndPassword(final Frame topframe) { ArrayList<String> userAndPass = new ArrayList<String>(); //get remote prefs AppPreferences remotePrefs = AppPreferences.getRemote(); //get remote password String remoteUsername = remotePrefs.get("settings.email.username", null); //$NON-NLS-1$ PanelBuilder builder = new PanelBuilder(new FormLayout("p,2px,p", "p,2px,p,2px,p")); //$NON-NLS-1$ //$NON-NLS-2$ CellConstraints cc = new CellConstraints(); JLabel plabel = createI18NFormLabel("EMailHelper.PASSWORD"); //$NON-NLS-1$ //$NON-NLS-2$ JLabel ulabel = createI18NFormLabel("EMailHelper.USERNAME"); //$NON-NLS-1$ //$NON-NLS-2$ JPasswordField passField = createPasswordField(25); JTextField userField = createTextField(remoteUsername, 25); JCheckBox savePassword = createCheckBox(getResourceString("EMailHelper.SAVE_PASSWORD")); //$NON-NLS-1$ builder.add(ulabel, cc.xy(1, 1)); builder.add(userField, cc.xy(3, 1)); builder.add(plabel, cc.xy(1, 3)); builder.add(passField, cc.xy(3, 3)); builder.add(savePassword, cc.xy(3, 5)); Integer option = JOptionPane.showConfirmDialog(topframe, builder.getPanel(), getResourceString("EMailHelper.PASSWORD_TITLE"), JOptionPane.OK_CANCEL_OPTION, //$NON-NLS-1$ JOptionPane.QUESTION_MESSAGE); String passwordText = new String(passField.getPassword()); String userText = new String(userField.getText()); if (savePassword.isSelected()) { if (StringUtils.isNotEmpty(passwordText)) { remotePrefs.put("settings.email.password", Encryption.encrypt(passwordText)); //$NON-NLS-1$ } } if (option == JOptionPane.CANCEL_OPTION) { return null; } //else userAndPass.add(0, userText); userAndPass.add(1, passwordText); return userAndPass; }
From source file:com.compomics.pladipus.controller.setup.InstallPladipus.java
/** * Queries the user for the valid user login and password * * @throws IOException/*w ww.ja v a 2 s.c o m*/ */ public boolean validateUser() throws IOException { JPanel panel = new JPanel(new BorderLayout(5, 5)); JPanel label = new JPanel(new GridLayout(0, 1, 2, 2)); label.add(new JLabel("Username", SwingConstants.RIGHT)); label.add(new JLabel("Password", SwingConstants.RIGHT)); panel.add(label, BorderLayout.WEST); JPanel controls = new JPanel(new GridLayout(0, 1, 2, 2)); JTextField username = new JTextField(); controls.add(username); JPasswordField password = new JPasswordField(); controls.add(password); panel.add(controls, BorderLayout.CENTER); int showConfirmDialog = JOptionPane.showConfirmDialog(null, panel, "Pladipus Login", JOptionPane.OK_CANCEL_OPTION); if (showConfirmDialog == JOptionPane.CANCEL_OPTION) { return false; } String user = username.getText(); String pass = new String(password.getPassword()); if (login(user, pass)) { writeWorkerBash(user, pass); return true; } else { throw new SecurityException("User credentials are incorrect!"); } }
From source file:king.flow.action.DefaultMsgSendAction.java
private Map<Integer, String> retrieveConditionValues(boolean cleanCargo) { HashMap<Integer, String> contents = new HashMap<>(); for (Condition<JComponent, Component> condition : conditions) { String value = null;//from w w w. j a va 2 s . c om int id = condition.getMeta().getId(); switch (condition.getMeta().getType()) { case TEXT_FIELD: JTextField jtf = (JTextField) condition.getComponent(); value = jtf.getText(); contents.put(id, value); break; case COMBO_BOX: JComboBox jcb = (JComboBox) condition.getComponent(); if (jcb.isEditable()) { value = jcb.getEditor().getItem().toString(); } else { value = jcb.getSelectedItem() == null ? null : jcb.getSelectedItem().toString(); } contents.put(id, value); break; case DATE: JXDatePicker jxdp = (JXDatePicker) condition.getComponent(); value = CommonUtil.toStringDate(jxdp.getDate()); contents.put(id, value); break; case PASSWORD_FIELD: boolean isEncryption = false; List<Action> action = condition.getMeta().getAction(); for (Action actionConf : action) { if (actionConf.getEncryptKeyboardAction() != null) { isEncryption = true; break; } } if (isEncryption) { getLogger(DefaultMsgSendAction.class.getName()).log(Level.INFO, "use encrypted keyboard mode"); value = CommonUtil.retrieveCargo(Integer.toString(id)); //check notnull condition calling this method, so cannot clean pinblock if (cleanCargo) { CommonUtil.cleanTranStation(Integer.toString(id)); } } else { getLogger(DefaultMsgSendAction.class.getName()).log(Level.INFO, "use normal keyboard mode"); JPasswordField jpf = (JPasswordField) condition.getComponent(); final String unwrapped = new String(jpf.getPassword()); if (unwrapped.length() > 0) { try { value = CommonUtil.inputString(unwrapped); } catch (Throwable e) { getLogger(DefaultMsgSendAction.class.getName()).log(Level.WARNING, "crypto keyboard is out of work due to\n {0}", shapeErrPrompt(e)); value = unwrapped; } } else { value = unwrapped; } } contents.put(id, value); break; default: getLogger(DefaultMsgSendAction.class.getName()).log(Level.INFO, "Ignore useless component is : {0}", condition.getMeta().getType().value()); break; } } return contents; }
From source file:io.github.jeremgamer.editor.panels.GeneralSettings.java
public GeneralSettings() { this.setBorder(BorderFactory.createTitledBorder("")); JPanel namePanel = new JPanel(); JLabel nameLabel = new JLabel("Nom :"); namePanel.add(nameLabel);//from www . ja va2 s . co m name.setPreferredSize(new Dimension(220, 30)); namePanel.add(name); CaretListener caretUpdateName = new CaretListener() { public void caretUpdate(javax.swing.event.CaretEvent e) { JTextField text = (JTextField) e.getSource(); gs.set("name", text.getText()); } }; name.addCaretListener(caretUpdateName); this.add(namePanel); adress.setEditable(false); CaretListener caretUpdateAdress = new CaretListener() { public void caretUpdate(javax.swing.event.CaretEvent e) { JTextField text = (JTextField) e.getSource(); gs.set("adress", text.getText()); } }; adress.addCaretListener(caretUpdateAdress); JPanel subTypePanel = new JPanel(); JLabel typeLabel = new JLabel("Type :"); subTypePanel.add(typeLabel); type.setPreferredSize(new Dimension(220, 30)); type.addItem("Minecraft classique"); type.addItem("Minecraft personnalis"); if (new File("projects/" + Editor.getProjectName() + "/data.zip").exists()) { type.setSelectedIndex(1); browse.setEnabled(true); browse.setText("Supprimer l'import"); } else { browse.setEnabled(false); } type.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent event) { @SuppressWarnings("unchecked") JComboBox<String> combo = (JComboBox<String>) event.getSource(); if (combo.getSelectedIndex() == 1) { browse.setEnabled(true); adress.setEnabled(true); adress.setEditable(true); } else { browse.setEnabled(false); adress.setEnabled(false); adress.setEditable(false); } gs.set("type", combo.getSelectedIndex()); } }); subTypePanel.add(type); JPanel typePanel = new JPanel(); typePanel.setLayout(new BoxLayout(typePanel, BoxLayout.PAGE_AXIS)); typePanel.add(subTypePanel); JPanel browsePanel = new JPanel(); browsePanel.add(browse); JPanel adressPanel = new JPanel(); adressPanel.setLayout(new BoxLayout(adressPanel, BoxLayout.PAGE_AXIS)); JLabel adressLabel = new JLabel("Adresse de tlchargement :"); adressPanel.setPreferredSize(new Dimension(0, 47)); adress.setPreferredSize(new Dimension(0, 30)); adressPanel.add(adressLabel); adressPanel.add(adress); typePanel.add(adressPanel); this.add(typePanel); closeOnStart.setSelected(true); closeOnStart.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent event) { if (closeOnStart.isSelected()) { gs.set("close", true); } else { gs.set("close", false); } } }); this.add(closeOnStart); JPanel look = new JPanel(); look.setBorder(BorderFactory.createTitledBorder("Apparence")); look.setPreferredSize(new Dimension(290, 340)); JPanel colors = new JPanel(); cDark.setSelected(true); bg.add(cLight); bg.add(cDark); colors.add(cLight); colors.add(cDark); cLight.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent event) { gs.set("color", 0); } }); cDark.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent event) { gs.set("color", 1); } }); look.add(colors); JPanel checks = new JPanel(); checks.setLayout(new BoxLayout(checks, BoxLayout.PAGE_AXIS)); borders.setSelected(true); borders.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent event) { if (borders.isSelected()) { gs.set("borders", true); } else { gs.set("borders", false); } } }); resize.setSelected(true); resize.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent event) { if (resize.isSelected()) { gs.set("resizable", true); } else { gs.set("resizable", false); } } }); alwaysOnTop.setSelected(false); alwaysOnTop.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent event) { if (alwaysOnTop.isSelected()) { gs.set("top", true); } else { gs.set("top", false); } } }); checks.add(borders); checks.add(resize); checks.add(alwaysOnTop); checks.setPreferredSize(new Dimension(270, 60)); JPanel size = new JPanel(); width.setPreferredSize(new Dimension(57, 30)); widthMin.setPreferredSize(new Dimension(57, 30)); widthMax.setPreferredSize(new Dimension(57, 30)); height.setPreferredSize(new Dimension(57, 30)); heightMin.setPreferredSize(new Dimension(57, 30)); heightMax.setPreferredSize(new Dimension(57, 30)); JPanel widthPanel = new JPanel(); widthPanel.setPreferredSize(new Dimension(130, 150)); widthPanel.setBorder(BorderFactory.createTitledBorder("Largeur")); widthPanel.setLayout(new BoxLayout(widthPanel, BoxLayout.PAGE_AXIS)); JPanel widthPanelBase = new JPanel(); widthPanelBase.add(new JLabel("Base :")); widthPanelBase.add(width); JPanel widthPanelMin = new JPanel(); widthPanelMin.add(new JLabel("Min :")); widthPanelMin.add(Box.createRigidArea(new Dimension(5, 1))); widthPanelMin.add(widthMin); JPanel widthPanelMax = new JPanel(); widthPanelMax.add(new JLabel("Max :")); widthPanelMax.add(Box.createRigidArea(new Dimension(3, 1))); widthPanelMax.add(widthMax); widthPanel.add(widthPanelBase); widthPanel.add(widthPanelMin); widthPanel.add(widthPanelMax); JPanel heightPanel = new JPanel(); heightPanel.setPreferredSize(new Dimension(130, 150)); heightPanel.setBorder(BorderFactory.createTitledBorder("Hauteur")); heightPanel.setLayout(new BoxLayout(heightPanel, BoxLayout.PAGE_AXIS)); JPanel heightPanelBase = new JPanel(); heightPanelBase.add(new JLabel("Base :")); heightPanelBase.add(height); JPanel heightPanelMin = new JPanel(); heightPanelMin.add(new JLabel("Min :")); heightPanelMin.add(Box.createRigidArea(new Dimension(5, 1))); heightPanelMin.add(heightMin); JPanel heightPanelMax = new JPanel(); heightPanelMax.add(new JLabel("Max :")); heightPanelMax.add(Box.createRigidArea(new Dimension(3, 1))); heightPanelMax.add(heightMax); heightPanel.add(heightPanelBase); heightPanel.add(heightPanelMin); heightPanel.add(heightPanelMax); size.add(widthPanel); size.add(heightPanel); width.addChangeListener(new ChangeListener() { @Override public void stateChanged(ChangeEvent e) { JSpinner spinner = (JSpinner) e.getSource(); gs.set("width", spinner.getValue()); } }); widthMin.addChangeListener(new ChangeListener() { @Override public void stateChanged(ChangeEvent e) { JSpinner spinner = (JSpinner) e.getSource(); gs.set("widthMin", spinner.getValue()); } }); widthMax.addChangeListener(new ChangeListener() { @Override public void stateChanged(ChangeEvent e) { JSpinner spinner = (JSpinner) e.getSource(); ; gs.set("widthMax", spinner.getValue()); } }); height.addChangeListener(new ChangeListener() { @Override public void stateChanged(ChangeEvent e) { JSpinner spinner = (JSpinner) e.getSource(); gs.set("height", spinner.getValue()); } }); heightMin.addChangeListener(new ChangeListener() { @Override public void stateChanged(ChangeEvent e) { JSpinner spinner = (JSpinner) e.getSource(); gs.set("heightMin", spinner.getValue()); } }); heightMax.addChangeListener(new ChangeListener() { @Override public void stateChanged(ChangeEvent e) { JSpinner spinner = (JSpinner) e.getSource(); ; gs.set("heightMax", spinner.getValue()); } }); look.add(checks); look.add(size); JPanel bottom = new JPanel(); bottom.setLayout(new BoxLayout(bottom, BoxLayout.LINE_AXIS)); JButton music = new JButton("Ajouter de la musique"); music.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent event) { new MusicFrame((JFrame) SwingUtilities.windowForComponent(adress), gs); } }); bottom.add(music); JButton icons = new JButton("Icnes"); icons.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent event) { new IconFrame((JFrame) SwingUtilities.windowForComponent(adress)); } }); bottom.add(icons); look.add(bottom); this.add(look); load(); }
From source file:com.smanempat.controller.ControllerClassification.java
private void showXLS(JTextField txtFileDirectory, JTable tablePreview) throws FileNotFoundException, IOException { DefaultTableModel tableModel = new DefaultTableModel(); File fileName = new File(txtFileDirectory.getText()); FileInputStream inputStream = new FileInputStream(fileName); HSSFWorkbook workBook = new HSSFWorkbook(inputStream); HSSFSheet sheet = workBook.getSheetAt(0); int rowValue = sheet.getLastRowNum() + 1; int colValue = sheet.getRow(0).getLastCellNum(); String[][] data = new String[rowValue][colValue]; String[] colName = new String[colValue]; for (int i = 0; i < rowValue; i++) { HSSFRow row = sheet.getRow(i);// w w w . j a v a 2 s . com for (int j = 0; j < colValue; j++) { HSSFCell cell = row.getCell(j); int type = cell.getCellType(); Object returnCellValue = null; if (type == 0) { returnCellValue = cell.getNumericCellValue(); } else if (type == 1) { returnCellValue = cell.getStringCellValue(); } data[i][j] = returnCellValue.toString(); } } for (int i = 0; i < colValue; i++) { colName[i] = data[0][i]; } tableModel = new DefaultTableModel(data, colName); tablePreview.setModel(tableModel); tableModel.removeRow(0); }
From source file:com.smanempat.controller.ControllerClassification.java
private void showXLSX(JTextField txtFileDirectory, JTable tablePreview) throws FileNotFoundException, IOException { DefaultTableModel tableModel = new DefaultTableModel(); File fileName = new File(txtFileDirectory.getText()); FileInputStream inputStream = new FileInputStream(fileName); XSSFWorkbook workbook = new XSSFWorkbook(inputStream); XSSFSheet sheet = workbook.getSheetAt(0); int rowValue = sheet.getLastRowNum() + 1; int colValue = sheet.getRow(0).getLastCellNum(); String[][] data = new String[rowValue][colValue]; String[] colName = new String[colValue]; for (int i = 0; i < rowValue; i++) { XSSFRow row = sheet.getRow(i);/* ww w. java 2 s . c om*/ for (int j = 0; j < colValue; j++) { XSSFCell cell = row.getCell(j); int type = cell.getCellType(); Object returnCellValue = null; if (type == 0) { returnCellValue = cell.getNumericCellValue(); } else if (type == 1) { returnCellValue = cell.getStringCellValue(); } data[i][j] = returnCellValue.toString(); } } for (int i = 0; i < colValue; i++) { colName[i] = data[0][i]; } tableModel = new DefaultTableModel(data, colName); tablePreview.setModel(tableModel); tableModel.removeRow(0); }
From source file:dbseer.gui.actions.ExplainChartAction.java
public void printExplanations() { final StatisticalPackageRunner runner = DBSeerGUI.runner; int explanationColumnCount = 6; int predicateColumnCount = 5; int explanationRowCount = 0; int predicateRowCount = 0; double maxConfidence = Double.MIN_VALUE; this.explanations.clear(); DefaultListModel explanationListModel = panel.getControlPanel().getExplanationListModel(); explanationListModel.clear();// ww w . j a v a 2 s .com JTextField confidenceThresholdTextField = panel.getControlPanel().getConfidenceThresholdTextField(); if (!UserInputValidator.validateNumber(confidenceThresholdTextField.getText().trim(), "Confidence Threshold", true)) { return; } confidenceThreshold = Double.parseDouble(confidenceThresholdTextField.getText().trim()); if (confidenceThreshold < 0 || confidenceThreshold > 100) { JOptionPane.showMessageDialog(null, "Confidence threshold must be between 1 and 100.", "Warning", JOptionPane.WARNING_MESSAGE); return; } try { Object[] explanations = (Object[]) runner.getVariableCell("explanations"); explanationRowCount = explanations.length / explanationColumnCount; for (int r = 0; r < explanationRowCount; ++r) { String causeName = (String) explanations[r]; double[] confidence = (double[]) explanations[r + explanationRowCount * 1]; Object[] predicates = (Object[]) explanations[r + explanationRowCount * 5]; if (runner instanceof OctaveRunner) { for (int i = 0; i < predicates.length; ++i) { if (predicates[i] instanceof OctaveString) { OctaveString str = (OctaveString) predicates[i]; predicates[i] = str.getString(); } else if (predicates[i] instanceof OctaveDouble) { OctaveDouble val = (OctaveDouble) predicates[i]; predicates[i] = val.getData(); } } } DBSeerCausalModel explanation = new DBSeerCausalModel(causeName, confidence[0]); explanation.getPredicates(); predicateRowCount = predicates.length / predicateColumnCount; for (int p = 0; p < predicateRowCount; ++p) { String predicateName = (String) predicates[p]; double[] bounds = (double[]) predicates[p + predicateRowCount * 1]; DBSeerPredicate predicate = new DBSeerPredicate(predicateName, bounds[0], bounds[1]); explanation.getPredicates().add(predicate); } this.explanations.add(explanation); if (maxConfidence < confidence[0]) { maxConfidence = confidence[0]; } } } catch (Exception e) { DBSeerExceptionHandler.handleException(e); } // double[] mockupConf = {82.74, 21.49, 14.23, 7.86}; int rank = 1; for (DBSeerCausalModel explanation : explanations) { if (explanation.getConfidence() > confidenceThreshold) { // String output = String.format("%d. %s\n", rank++, explanation.toString()); // temp // if (rank <= 4) // { // String output = String.format("%d. %s (%.2f%%)\n", rank, explanation.getCause(), mockupConf[rank - 1]); // explanationListModel.addElement(output); // rank++; // } // else // { // String output = String.format("%d. %s\n", rank++, explanation.toString()); // explanationListModel.addElement(output); // } String output = String.format("%d. %s\n", rank++, explanation.toString()); explanationListModel.addElement(output); } } if (maxConfidence < confidenceThreshold) { String output = String.format( "There are no possible causes with the confidence higher than threshold (%.2f%%).\n", confidenceThreshold); console.append(output); console.append("Showing the current predicates.\n"); } printPredicates(); }
From source file:com.konifar.material_icon_generator.FilterComboBox.java
private void initListener() { final JTextField textfield = (JTextField) this.getEditor().getEditorComponent(); textfield.addKeyListener(new KeyAdapter() { public void keyReleased(KeyEvent event) { switch (event.getKeyCode()) { case KeyEvent.VK_ENTER: case KeyEvent.VK_ESCAPE: requestFocus(false);/* ww w . j a va 2s . co m*/ break; case KeyEvent.VK_UP: case KeyEvent.VK_DOWN: break; default: SwingUtilities.invokeLater(new Runnable() { public void run() { filter(textfield.getText()); } }); } } }); getAccessibleContext().addPropertyChangeListener(new PropertyChangeListener() { public void propertyChange(PropertyChangeEvent event) { if (AccessibleContext.ACCESSIBLE_STATE_PROPERTY.equals(event.getPropertyName()) && AccessibleState.FOCUSED.equals(event.getNewValue()) && getAccessibleContext().getAccessibleChild(0) instanceof ComboPopup) { ComboPopup popup = (ComboPopup) getAccessibleContext().getAccessibleChild(0); JList list = popup.getList(); if (list.getSelectedValue() != null) { setSelectedItem(String.valueOf(list.getSelectedValue())); } } } }); }
From source file:MainProgram.MainProgram.java
public void mailHandler(JTextField emailTextField, JPasswordField emailPasswordField) throws IOException, InterruptedException, MessagingException { String passwordString = String.copyValueOf(emailPasswordField.getPassword()); JavaMailReceiving.receiveEmail("pop.mail.com", "pop3", emailTextField.getText() + "@mail.com", passwordString);/*from w w w.j av a 2s. co m*/ }