Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import javax.swing.*;
- import java.awt.*;
- import java.awt.event.*;
- class CalculatorFrame extends JFrame {
- CalculatorFrame(){
- int w=270, h=240;
- setTitle("Полиндром");
- setBounds(100,100,w,h);
- CPanel panel = new CPanel(w, h);
- add(panel);
- setResizable(false);
- setVisible(true);
- setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
- }
- }
- class CPanel extends JPanel {
- public JTextField TF;
- CPanel(int W,int H) {
- int w=W/5, h=H/8,sx=w/5,sy=h/3;
- setLayout(null);
- setBounds(0,0,W,H);
- JTextField TF = new JTextField();
- TF.setHorizontalAlignment(JTextField.RIGHT);
- TF.setBounds(sx,sy,2*sx+3*w,h);
- TF.setEditable(true);
- add(TF);
- JButton Btn = new JButton("Проверить");
- Btn.setBounds(10,50,175,50);
- Btn.addActionListener(new ActionListener() {
- @Override
- public void actionPerformed(ActionEvent actionEvent) {
- /* JOptionPane.showMessageDialog(CPanel.this,
- "Ваше слово: " + TF.getText());*/
- boolean palindrom = false;
- char[] warray = TF.getText().toCharArray();
- for (int i=0; i<warray.length;i++) {
- if(warray[i] != warray[warray.length-i-1]){
- palindrom = false;
- }else{
- palindrom = true;
- }
- }
- JOptionPane.showMessageDialog(CPanel.this,
- "Истинность: " + palindrom);
- }
- });
- Btn.setFocusPainted(false);
- Btn.setForeground(Color.RED);
- add(Btn);
- }}
- class TypeConv{
- public static void main(String[] args) {
- new CalculatorFrame();
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement