Advertisement
sergAccount

Untitled

Apr 4th, 2021
694
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 2.12 KB | None | 0 0
  1. /*
  2.  * To change this license header, choose License Headers in Project Properties.
  3.  * To change this template file, choose Tools | Templates
  4.  * and open the template in the editor.
  5.  */
  6. package com.spec.ui;
  7.  
  8. import java.awt.event.ActionEvent;
  9. import java.awt.event.ActionListener;
  10. import javax.swing.JButton;
  11. import javax.swing.JFrame;
  12. import javax.swing.JPanel;
  13. import javax.swing.JTextField;
  14.  
  15. public class MainWindow extends JFrame implements ActionListener{
  16.    
  17.     private JTextField t1;
  18.     private JTextField t2;
  19.    
  20.     public MainWindow(){
  21.         // устанавливаем главное
  22.         setTitle("MainWindow");
  23.         // устанавливаем размеры окна
  24.         setBounds(10, 10, 800, 600);
  25.         // размещаем панель внутри главного - используем createPanel()
  26.         getContentPane().add(createPanel());        
  27.         // завершение работы программы при закрытии окна
  28.         setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
  29.         // показываем окно на экране  
  30.         setVisible(true);
  31.     }    
  32.     // панель которая содержит компоненты UI
  33.     public JPanel createPanel(){
  34.         JPanel panel = new JPanel();
  35.         // поле ввода  
  36.         t1 = new JTextField(20);        
  37.         t2 = new JTextField(20);                
  38.         // добавляем t1 в контейнер
  39.         panel.add(t1);
  40.         panel.add(t2);
  41.         // созданим компонент - кнопка
  42.         JButton b1 = new JButton("Copy");        
  43.         b1.addActionListener(this);        
  44.         panel.add(b1);
  45.         //      
  46.         return panel;
  47.     }
  48.     @Override
  49.     public void actionPerformed(ActionEvent e) {
  50.         System.out.println("MainWindow.actionPerformed!!!!");
  51.         System.out.println("e.getActionCommand()=" + e.getActionCommand());
  52.         // при нажатии на кнопку получаем тест из t1 и устанавливаем в t2
  53.         t2.setText(t1.getText());
  54.     }
  55. }
  56.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement