Advertisement
Guest User

do

a guest
Jul 19th, 2019
90
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.03 KB | None | 0 0
  1. vimport javax.swing.*;
  2.  
  3. import java.awt.Color;
  4. import java.awt.event.ActionEvent;
  5. import java.awt.event.ActionListener;
  6. import java.io.*;
  7. import java.util.*;
  8.  
  9. public class WindowApplication extends JFrame implements ActionListener{
  10. private JTextField textField;
  11. private JFrame frame;//
  12. private JButton button;
  13.  
  14. public WindowApplication() {
  15. setSize(320 , 240);
  16. setDefaultCloseOperation(EXIT_ON_CLOSE);
  17. setLocationRelativeTo(null);
  18. setBackground(Color.BLACK);
  19.  
  20. button = new JButton("Change title");
  21. button.addActionListener(this);
  22.  
  23. textField = new JTextField(20);
  24. getContentPane().add(textField);
  25. getContentPane().add(button);
  26. }
  27.  
  28. @Override
  29. public void actionPerformed(ActionEvent arg0) {
  30. String text = textField.getText();
  31. setTitle(text);
  32. }
  33.  
  34. public static void main(String[] args) {
  35. Work work = new Work();
  36. Thread t = new Thread(work);
  37. t.start();
  38. }
  39. }
  40.  
  41. class Work implements Runnable{
  42. @Override
  43. public void run() {
  44. new WindowApplication().setVisible(true);
  45. }
  46. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement