Advertisement
Guest User

Untitled

a guest
Mar 14th, 2016
207
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.20 KB | None | 0 0
  1. import java.awt.FlowLayout;
  2. import java.awt.event.ActionEvent;
  3. import java.awt.event.ActionListener;
  4. import javax.swing.JButton;
  5. import javax.swing.JFrame;
  6. import javax.swing.JTextField;
  7.  
  8. public class NameStart implements ActionListener{
  9. static JTextField jt;
  10. static JButton bt;
  11. static NameGenRules ngr = new NameGenRules();
  12. //I need to learn more about creating GUI in new class, I know
  13. public static void main(String[] args) {
  14. JFrame frame = new JFrame();
  15. frame.setLayout(new FlowLayout());
  16. ngr.setNames();
  17. jt = new JTextField("Генерируй же!",10);
  18. jt.setEditable(false);
  19. frame.add(jt);//I've added text field to frame
  20. bt = new JButton("Генерировать!");
  21. frame.add(bt);//I've added button to frame
  22. NameStart ns = new NameStart();
  23. bt.addActionListener(ns);
  24. jt.addActionListener(ns);
  25. frame.setSize(150, 150);
  26. frame.setVisible(true);
  27. frame.setResizable(false);
  28. frame.setLocationRelativeTo(null);//that's for "appearance in center position"
  29. }
  30. @Override//here is action listener for my miserable GUI, ha-ha!
  31. public void actionPerformed(ActionEvent e) {
  32. if(e.getSource().equals(bt)){
  33. jt.setText(ngr.RunName());
  34. }
  35. }
  36. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement