Advertisement
far_light

Blocker

Feb 10th, 2018
93
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 2.80 KB | None | 0 0
  1. package com.vladislav;
  2.  
  3. import javax.swing.*;
  4. import java.awt.*;
  5. import java.awt.event.*;
  6.  
  7. // Главный класс, в котором расположен запускаемый метод
  8. public class Main {
  9.     // Главный вызываемый метод
  10.     public static void main(String[] args) {
  11.         // Создание окна
  12.         Window window = new Window();
  13.     }
  14. }
  15.  
  16. class Window extends JFrame {
  17.     private JTextArea text;
  18.  
  19.     private void setWindow() {
  20.         Toolkit toolkit = Toolkit.getDefaultToolkit();
  21.         Dimension dimension = toolkit.getScreenSize();
  22.  
  23.         setBounds(0, 0, dimension.width, dimension.height);
  24.         setMinimumSize(dimension);
  25.         setMaximumSize(dimension);
  26.         setUndecorated(true);
  27.  
  28.         requestFocus();
  29.         setFocusable(true);
  30.         toFront();
  31.  
  32.         setTitle("Blocker");
  33.         setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
  34.         setVisible(true);
  35.     }
  36.  
  37.     private void setContent() {
  38.         Container container = getContentPane();
  39.         JPanel panel = new JPanel();
  40.         panel.setLayout(null);
  41.  
  42.         Font first = new Font("serif", 0, 40),
  43.                 second = new Font("serif", 0, 25);
  44.  
  45.         JLabel label = new JLabel("Компьютер заражён!!!");
  46.         label.setForeground(Color.BLUE);
  47.         label.setFont(first);
  48.         label.setBounds(50, 0, 800, 100);
  49.         panel.add(label);
  50.  
  51.         // Other text...
  52.  
  53.         JLabel name = new JLabel("Введите своё имя для снятия блокировки: ");
  54.         name.setForeground(Color.BLUE);
  55.         name.setFont(second);
  56.         name.setBounds(50, 150, 800, 100);
  57.         panel.add(name);
  58.  
  59.         text = new JTextArea();
  60.         text.setFont(second);
  61.         text.setBounds(50, 250, 300, 35);
  62.         text.setForeground(new Color(0, 0, 128));
  63.         text.setBackground(Color.WHITE);
  64.         panel.add(text);
  65.  
  66.         JButton button = new JButton("Enter");
  67.         button.setSize(150, 35);
  68.         button.setFont(second);
  69.         button.setLocation(50, 300);
  70.         button.addActionListener(new ActionListener() {
  71.                  @Override
  72.                  public void actionPerformed(ActionEvent e) {
  73.                      String string = text.getText().toLowerCase().trim(),
  74.                              result = "far__light";
  75.  
  76.                      if (string.equals(result)) {
  77.                          JOptionPane.showMessageDialog(null, "Unlocked!");
  78.                          System.exit(0);
  79.                      } else {
  80.                          text.setText("Try again!");
  81.                      }
  82.                  }
  83.              }
  84.         );
  85.         panel.add(button);
  86.  
  87.         container.add(panel);
  88.     }
  89.  
  90.     Window() {
  91.         setContent();
  92.         setWindow();
  93.     }
  94. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement