Advertisement
timursaet

isPolindromeJavaUI

Oct 23rd, 2019
133
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.86 KB | None | 0 0
  1. import javax.swing.*;
  2. import java.awt.*;
  3. import java.awt.event.*;
  4. class CalculatorFrame extends JFrame {
  5.     CalculatorFrame(){
  6.         int w=270, h=240;
  7.         setTitle("Полиндром");
  8.         setBounds(100,100,w,h);
  9.         CPanel panel = new CPanel(w, h);
  10.         add(panel);
  11.         setResizable(false);
  12.         setVisible(true);
  13.         setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
  14.     }
  15. }
  16.  
  17. class CPanel extends JPanel {
  18.     public JTextField TF;
  19.     CPanel(int W,int H) {
  20.         int w=W/5, h=H/8,sx=w/5,sy=h/3;
  21.         setLayout(null);
  22.         setBounds(0,0,W,H);
  23.         JTextField TF = new JTextField();
  24.         TF.setHorizontalAlignment(JTextField.RIGHT);
  25.         TF.setBounds(sx,sy,2*sx+3*w,h);
  26.         TF.setEditable(true);
  27.         add(TF);
  28.         JButton Btn = new JButton("Проверить");
  29.         Btn.setBounds(10,50,175,50);
  30.         Btn.addActionListener(new ActionListener() {
  31.             @Override
  32.             public void actionPerformed(ActionEvent actionEvent) {
  33.                /* JOptionPane.showMessageDialog(CPanel.this,
  34.                         "Ваше слово: " + TF.getText());*/
  35.                 boolean palindrom = false;
  36.                 char[] warray = TF.getText().toCharArray();
  37.                 for (int i=0; i<warray.length;i++) {
  38.                     if(warray[i] != warray[warray.length-i-1]){
  39.                         palindrom = false;
  40.                     }else{
  41.                         palindrom = true;
  42.                     }
  43.                 }
  44.                   JOptionPane.showMessageDialog(CPanel.this,
  45.                         "Истинность: " + palindrom);
  46.             }
  47.         });
  48.         Btn.setFocusPainted(false);
  49.         Btn.setForeground(Color.RED);
  50.         add(Btn);
  51.     }}
  52.  
  53. class TypeConv{
  54.     public static void main(String[] args) {
  55.         new CalculatorFrame();
  56.     }
  57. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement