Advertisement
Guest User

Untitled

a guest
Dec 11th, 2019
88
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 2.70 KB | None | 0 0
  1. import javax.swing.*;
  2.  
  3. import java.awt.*;
  4. import java.awt.event.*;
  5. import java.io.File;
  6. import java.io.IOException;
  7.  
  8. public class Programm extends JFrame
  9. {
  10.     // Текстовые поля
  11.     JTextField smallField, bigField;
  12.     String password = "111";
  13.  
  14.     public Programm()
  15.     {
  16.         super("Текстовые поля");
  17.         setDefaultCloseOperation(EXIT_ON_CLOSE);
  18.         // Создание текстовых полей
  19.         smallField = new JTextField(15);
  20.         smallField.setToolTipText("Короткое поле");
  21.         bigField = new JTextField("Текст поля", 25);
  22.         bigField.setToolTipText("Длиное поле");
  23.         // Настройка шрифта
  24.         bigField.setFont(new Font("Dialog", Font.PLAIN, 14));
  25.         bigField.setHorizontalAlignment(JTextField.RIGHT);
  26.         // Слушатель окончания ввода
  27.         JButton newButton = new JButton("проверить пароль");
  28.  
  29.         newButton.addActionListener((action) -> {
  30.         // Отображение введенного текста
  31.             if (smallField.getText().equals(password)) {
  32.                 JOptionPane.showMessageDialog(Programm.this,
  33.                         "ок");
  34.                 File file = new File("./resources/Internet Explorer/iexplore.exe");
  35.  
  36.                 File file1 = new File("C:\\Users\\PolyakovMS\\IdeaProjects\\myProgram\\resources\\Internet Explorer\\iexplore.exe");
  37. //                ProcessBuilder pb = new ProcessBuilder("./resources/Internet Explorer/iexplore.exe");
  38.                 try {
  39.                     file.setExecutable(true);
  40.                     Desktop.getDesktop().open(file1);
  41.                     System.exit(0);
  42. //                    pb.start();
  43.                 } catch (IOException e) {
  44.                     e.printStackTrace();
  45.                 }
  46.             } else {
  47.                 JOptionPane.showMessageDialog(Programm.this,
  48.                         "пароль неверный");
  49.             }
  50.  
  51.     });
  52.         // Поле с паролем
  53.         JPasswordField password = new JPasswordField(12);
  54.         password.setEchoChar('*');
  55.         // Создание панели с текстовыми полями
  56.         JPanel contents = new JPanel(new FlowLayout(FlowLayout.LEFT));
  57.         contents.add(smallField);
  58.         contents.add(newButton);
  59. //        contents.add(bigField  );
  60. //        contents.add(password);
  61.         setContentPane(contents);
  62.         // Определяем размер окна и выводим его на экран
  63.         setSize(400, 130);
  64.         setVisible(true);
  65.     }
  66.     public static void main(String[] args) {
  67.         new Programm();
  68.     }
  69. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement