public void actionPerformed(ActionEvent e) { if(e.getSource()==b) { temp=tf.getText(); temp1[]=ta.getText().split(); index=0; index=temp1[].indexOf(temp,index); ta.select(index, index+temp.length()); b.setVisible(false); b1.setVisible(true); } if(e.getSource()==b1) { index=temp1.indexOf(temp,index+temp.length()); if(index!=-1) { ta.requestFocusInWindow(); ta.select(index, index+temp.length()); } else { b.setVisible(true); b1.setVisible(false); index=0; } } }
/** * Will select the Mars Messages tab error message that matches the given specifications, if it is * found. Matching is done by constructing a string using the parameter values and searching the * text area for the last occurrance of that string. * * @param fileName A String containing the file path name. * @param line Line number for error message * @param column Column number for error message */ public void selectErrorMessage(String fileName, int line, int column) { String errorReportSubstring = new java.io.File(fileName).getName() + ErrorList.LINE_PREFIX + line + ErrorList.POSITION_PREFIX + column; int textPosition = assemble.getText().lastIndexOf(errorReportSubstring); if (textPosition >= 0) { int textLine = 0; int lineStart = 0; int lineEnd = 0; try { textLine = assemble.getLineOfOffset(textPosition); lineStart = assemble.getLineStartOffset(textLine); lineEnd = assemble.getLineEndOffset(textLine); assemble.setSelectionColor(Color.YELLOW); assemble.select(lineStart, lineEnd); assemble.getCaret().setSelectionVisible(true); assemble.repaint(); } catch (BadLocationException ble) { // If there is a problem, simply skip the selection } } }