Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.awt.FlowLayout;
- import java.awt.event.ActionEvent;
- import java.awt.event.ActionListener;
- import javax.swing.JButton;
- import javax.swing.JFrame;
- import javax.swing.JTextField;
- public class NameStart implements ActionListener{
- static JTextField jt;
- static JButton bt;
- static NameGenRules ngr = new NameGenRules();
- //I need to learn more about creating GUI in new class, I know
- public static void main(String[] args) {
- JFrame frame = new JFrame();
- frame.setLayout(new FlowLayout());
- ngr.setNames();
- jt = new JTextField("Генерируй же!",10);
- jt.setEditable(false);
- frame.add(jt);//I've added text field to frame
- bt = new JButton("Генерировать!");
- frame.add(bt);//I've added button to frame
- NameStart ns = new NameStart();
- bt.addActionListener(ns);
- jt.addActionListener(ns);
- frame.setSize(150, 150);
- frame.setVisible(true);
- frame.setResizable(false);
- frame.setLocationRelativeTo(null);//that's for "appearance in center position"
- }
- @Override//here is action listener for my miserable GUI, ha-ha!
- public void actionPerformed(ActionEvent e) {
- if(e.getSource().equals(bt)){
- jt.setText(ngr.RunName());
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement