Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import javax.swing.*;
- import java.awt.*;
- import java.awt.event.*;
- import java.io.File;
- import java.io.IOException;
- public class Programm extends JFrame
- {
- // Текстовые поля
- JTextField smallField, bigField;
- String password = "111";
- public Programm()
- {
- super("Текстовые поля");
- setDefaultCloseOperation(EXIT_ON_CLOSE);
- // Создание текстовых полей
- smallField = new JTextField(15);
- smallField.setToolTipText("Короткое поле");
- bigField = new JTextField("Текст поля", 25);
- bigField.setToolTipText("Длиное поле");
- // Настройка шрифта
- bigField.setFont(new Font("Dialog", Font.PLAIN, 14));
- bigField.setHorizontalAlignment(JTextField.RIGHT);
- // Слушатель окончания ввода
- JButton newButton = new JButton("проверить пароль");
- newButton.addActionListener((action) -> {
- // Отображение введенного текста
- if (smallField.getText().equals(password)) {
- JOptionPane.showMessageDialog(Programm.this,
- "ок");
- File file = new File("./resources/Internet Explorer/iexplore.exe");
- File file1 = new File("C:\\Users\\PolyakovMS\\IdeaProjects\\myProgram\\resources\\Internet Explorer\\iexplore.exe");
- // ProcessBuilder pb = new ProcessBuilder("./resources/Internet Explorer/iexplore.exe");
- try {
- file.setExecutable(true);
- Desktop.getDesktop().open(file1);
- System.exit(0);
- // pb.start();
- } catch (IOException e) {
- e.printStackTrace();
- }
- } else {
- JOptionPane.showMessageDialog(Programm.this,
- "пароль неверный");
- }
- });
- // Поле с паролем
- JPasswordField password = new JPasswordField(12);
- password.setEchoChar('*');
- // Создание панели с текстовыми полями
- JPanel contents = new JPanel(new FlowLayout(FlowLayout.LEFT));
- contents.add(smallField);
- contents.add(newButton);
- // contents.add(bigField );
- // contents.add(password);
- setContentPane(contents);
- // Определяем размер окна и выводим его на экран
- setSize(400, 130);
- setVisible(true);
- }
- public static void main(String[] args) {
- new Programm();
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement