public void findNext() { String selection = txt.getSelectedText(); try { selection.equals(""); } catch (NullPointerException e) { selection = textF.getText(); try { selection.equals(""); } catch (NullPointerException e2) { selection = JOptionPane.showInputDialog("Find:"); textF.setText(selection); } } try { int select_start = txt.getText().toLowerCase().indexOf(selection.toLowerCase(), startIndex); int select_end = select_start + selection.length(); txt.select(select_start, select_end); startIndex = select_end + 1; if (select_start == txt.getText().toLowerCase().lastIndexOf(selection.toLowerCase())) { startIndex = 0; } } catch (NullPointerException e) { } }
public void actionPerformed(ActionEvent ae) { if (ae.getActionCommand().equals("Add User")) { jta.append("\n" + userId.getText()); User user = new User(userId.getText()); } else if (ae.getActionCommand().equals("Add Group")) { jta.append("\n" + groupId.getText()); Group group = new Group(groupId.getText()); } else if (ae.getActionCommand().equals("Open User View")) { try { if (!jta.getSelectedText().equals("null")) { userView.setVisible(true); } } catch (Exception e) { JOptionPane.showMessageDialog( frame, "Nothing selected", "Error", JOptionPane.ERROR_MESSAGE); } } else if (ae.getActionCommand().equals("Show User Total")) { JOptionPane.showMessageDialog(frame, User.getUserTotal()); } else if (ae.getActionCommand().equals("Show Group Total")) { JOptionPane.showMessageDialog(frame, Group.getGroupTotal()); } else if (ae.getActionCommand().equals("Show Messages Total")) { JOptionPane.showMessageDialog(frame, User.getMessageTotal()); } else if (ae.getActionCommand().equals("Show Positive Percentage")) { String[] newsFeed = User.getNewsFeed(); int positive = 0; int i = 0; while (!(newsFeed[i] == null)) { if (newsFeed[i].contains("good") || newsFeed[i].contains("great") || newsFeed[i].contains("excellent")) positive++; i++; } JOptionPane.showMessageDialog(frame, positive * 100.0 / i + "%"); } else if (ae.getActionCommand().equals("Follow User")) { following.append("\n" + userId2.getText()); } else if (ae.getActionCommand().equals("Post Tweet")) { User.postTweet(tweet.getText()); newsFeed.append("\n" + jta.getSelectedText() + ": " + tweet.getText()); } }