Advertisement
Guest User

Untitled

a guest
Oct 16th, 2014
55
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 2.16 KB | None | 0 0
  1. public class Main extends JFrame {
  2.    
  3.     JFrame frame = new JFrame ("Aaaaa");
  4.     JButton button_name = new JButton("Wpisz imie");    
  5.     JFrame frame_name = new JFrame ("Podaj swoje imię");
  6.     Point center =
  7.             GraphicsEnvironment.getLocalGraphicsEnvironment().getCenterPoint(); //Get center of screen
  8.     ButtonListener bl = new ButtonListener();
  9.    
  10.     /**************************************************************************/
  11.     //Imię
  12.     String name = new String();
  13.     JButton button_get_name = new JButton("OK");
  14.     JTextField field_name = new JTextField(15);
  15.     JPanel panel_name = new JPanel();
  16.     /**************************************************************************/
  17.    
  18.     public Main(){
  19.         button_name.addActionListener(bl);
  20.         button_get_name.addActionListener(bl);
  21.                
  22.         JFrame.setDefaultLookAndFeelDecorated(true);
  23.         frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
  24.         frame.setLayout(new GridLayout(2,2));
  25.        
  26.         frame.add(new JLabel (name));
  27.         frame.add(button_name);
  28.         frame.add(new JLabel ("HEHEHE"));
  29.        
  30.         frame.setBounds(center.x - 400 / 2, center.y - 400 / 2, 400, 400);      //Set window in a center of screen
  31.        
  32.         frame.setVisible(true);
  33.        
  34.     }
  35.  
  36.     /**
  37.      * @param args the command line arguments
  38.      */
  39.  
  40.     public static void main(String[] args) {
  41.         new Main();
  42.     }
  43.    
  44.     public class ButtonListener implements ActionListener {
  45.         @Override
  46.         public void actionPerformed(ActionEvent e) {
  47.             if (e.getSource() == button_name){
  48.                 frame.dispose();
  49.                 frame_name.setBounds(center.x - 100 / 2, center.y - 100 / 2, 100, 100);
  50.                 frame_name.setLayout(new GridLayout(2,1));
  51.                 frame_name.add(field_name);
  52.                 frame_name.add(button_get_name);
  53.                 frame_name.setVisible(true);
  54.             }
  55.             if (e.getSource() == button_get_name){
  56.                 name = field_name.getText();
  57.                 frame_name.dispose();
  58.                 frame.setVisible(true);
  59.             }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement