Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.awt.*;
- import java.awt.event.*;
- import javax.swing.*;
- public class palindrome{
- public static void main( String args[]) {
- JFrame frame = new JFrame("PAL_GUI");
- frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE
- );
- final int FIELD_WIDTH = 20 ;
- final JTextField inpField = new JTextField(FIELD_WIDTH);
- final JTextField outField = new JTextField(FIELD_WIDTH);
- JButton checkPalindromeButton = new JButton("ok");
- checkPalindromeButton.addActionListener(new ActionListener(){
- public void actionPerformed(ActionEvent event) {
- String s = inpField.getText();
- boolean ispalindrome = true ;
- for (int i = 0 , j = s.length()-1;i<j;i++,j--)
- {
- if(s.charAt(i) != s.charAt(j))
- {
- ispalindrome = false ; break ;
- }
- }
- outField.setText(""+ ispalindrome) ;
- }
- });
- frame.setLayout(new FlowLayout()) ;
- frame.add(inpField);
- frame.add(checkPalindromeButton) ;
- frame.add(outField) ;
- frame.setVisible(true) ; }}
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement