/* * PalindromeApplet.java * * Created on January 29, 2005, 4:46 PM */ /** * * @author levenick */ public class PalindromeApplet extends java.applet.Applet { /** Initializes the applet PalindromeApplet */ public void init() { initComponents(); } boolean isPalindromic(String s) { s = s.toLowerCase(); String filteredS = ""; for (int i=0; i= rightIndex; } boolean isPalindrome(String s) { int leftIndex = 0; int rightIndex = s.length()-1; while (leftIndex < rightIndex && s.charAt(leftIndex) == s.charAt(rightIndex)) { leftIndex++; rightIndex--; } return leftIndex >= rightIndex; } /** This method is called from within the init() method to * initialize the form. * WARNING: Do NOT modify this code. The content of this method is * always regenerated by the Form Editor. */ private void initComponents() {//GEN-BEGIN:initComponents answerTF = new java.awt.TextField(); inputTF = new java.awt.TextField(); setLayout(null); answerTF.setText(" "); add(answerTF); answerTF.setBounds(70, 150, 240, 20); inputTF.setText("racecar"); inputTF.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { inputTFActionPerformed(evt); } }); add(inputTF); inputTF.setBounds(60, 30, 260, 20); }//GEN-END:initComponents private void inputTFActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_inputTFActionPerformed if (isPalindromic(inputTF.getText())) answerTF.setText("yes"); else answerTF.setText("nope"); }//GEN-LAST:event_inputTFActionPerformed // Variables declaration - do not modify//GEN-BEGIN:variables private java.awt.TextField answerTF; private java.awt.TextField inputTF; // End of variables declaration//GEN-END:variables }