Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public class Main extends JFrame {
- JFrame frame = new JFrame ("Aaaaa");
- JButton button_name = new JButton("Wpisz imie");
- JFrame frame_name = new JFrame ("Podaj swoje imię");
- Point center =
- GraphicsEnvironment.getLocalGraphicsEnvironment().getCenterPoint(); //Get center of screen
- ButtonListener bl = new ButtonListener();
- /**************************************************************************/
- //Imię
- String name = new String();
- JButton button_get_name = new JButton("OK");
- JTextField field_name = new JTextField(15);
- JPanel panel_name = new JPanel();
- /**************************************************************************/
- public Main(){
- button_name.addActionListener(bl);
- button_get_name.addActionListener(bl);
- JFrame.setDefaultLookAndFeelDecorated(true);
- frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
- frame.setLayout(new GridLayout(2,2));
- frame.add(new JLabel (name));
- frame.add(button_name);
- frame.add(new JLabel ("HEHEHE"));
- frame.setBounds(center.x - 400 / 2, center.y - 400 / 2, 400, 400); //Set window in a center of screen
- frame.setVisible(true);
- }
- /**
- * @param args the command line arguments
- */
- public static void main(String[] args) {
- new Main();
- }
- public class ButtonListener implements ActionListener {
- @Override
- public void actionPerformed(ActionEvent e) {
- if (e.getSource() == button_name){
- frame.dispose();
- frame_name.setBounds(center.x - 100 / 2, center.y - 100 / 2, 100, 100);
- frame_name.setLayout(new GridLayout(2,1));
- frame_name.add(field_name);
- frame_name.add(button_get_name);
- frame_name.setVisible(true);
- }
- if (e.getSource() == button_get_name){
- name = field_name.getText();
- frame_name.dispose();
- frame.setVisible(true);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement