Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7006339
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T21:27:54+00:00 2026-05-27T21:27:54+00:00

Target: When user give valid login and password -> (JFrame – Destroy login content)

  • 0

Target:
When user give valid login and password -> (JFrame – Destroy login content)
And Change own content to game content.. (function GRA)

Problem:

When i try use :

main.contentpane.removeAll():
main.removeAll():
doLayout

And others (Command)

Program doesn’t load a new content.

Here is my code :

class GUI implements ActionListener {

    public static JPanel image_cont;

    // definicja klasy wątka
    runner pierwiast = new runner();

    public static JFrame main = new JFrame();

    public static JLabel ilosc_pkt = new JLabel("0");

    JTextField pole, login_p, haslo_p;

    dostep_z_o logowanie = new dostep_z_o("baza_danych.txt");

    public GUI() {







        // wymiary okna x, y (zasada oznakowania, wykresy matematyczne)
        main.setSize(900, 400);

        // porządkowanie pozycji elementów
        //setLayout(new FlowLayout());

        // tytuł okna
        main.setTitle("Gra ułamki - logowanie do gry");






        main.setResizable(false);
        main.setVisible(true);


        main.setLayout(null);


        JLabel login = new JLabel("Login : ");
        JLabel haslo = new JLabel("Hasło : ");
        login_p = new JTextField("",10);
        haslo_p = new JTextField("",10);
        JButton przycisk = new JButton("Zaloguj!");

        // nadanie akcji
        przycisk.setActionCommand("Login");

        // dodanie do Action listenera
        przycisk.addActionListener(this);

        // marginery - zakres, pozycji dla obiektu
        Insets insets = main.getInsets();

        main.add(login);
        main.add(login_p);
        main.add(haslo);
        main.add(haslo_p);
        main.add(przycisk);

        // preferowany rozmiar przez jave dla elementu
        Dimension size = przycisk.getPreferredSize();
        System.out.println(size);

        login.setBounds(296 + insets.left, 4 + insets.top, 41, 16);
        login_p.setBounds(342 + insets.left, 2 + insets.top, 114, 20);
        haslo.setBounds(296 + insets.left, 32 + insets.top, 41, 16);
        haslo_p.setBounds(342 + insets.left, 30 + insets.top, 114, 20);
        przycisk.setBounds(467 + insets.left, 2 + insets.top, 117, 48);
        // (900 / 2) - ((41 + 5 + 114 + 11 + 117) / 2 )
        // 450 -               144 = 296



        main.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

    }

    public void gra()
    {

        main.removeAll();
        main.getContentPane().removeAll();

        main.setTitle("Gra ułamki - złap pierwiastki chemiczne. Quickly! -- Aktualna ilość punktów : " + runner.punkty);

        JPanel content = new JPanel();
        content.setBackground(Color.green);
        //content.setLayout(new BorderLayout(200, 200));
        content.setPreferredSize(new Dimension(900, 75));
        content.setLayout(null);
        //content.setSize(0, 0);

        // pole tekstowe
        pole = new JTextField("",2);
        // definiowanie przycisku
        JButton przycisk = new JButton("Zatwierdź wprowadzenie!");
        // nadanie komendy wysyłanej do action listenera
        przycisk.setActionCommand("Spr");
        // dodanie do Action listenera
        przycisk.addActionListener(this);

        //opis punktów
        JLabel opis_p = new JLabel("Ilość punktów : ");

        JLabel n_pierw = new JLabel("Nazwa pierwiastka : ");
        //ilosc_pkt

        // marginery - zakres, pozycji dla obiektu
        Insets insets = content.getInsets();

        content.add(n_pierw);
        content.add(pole);
        content.add(przycisk);
        content.add(opis_p);
        content.add(ilosc_pkt);




        // setBounds - ustawia pozycje, Od lewej krawedzi, od gornej krawedzi, dlugosc_obiektu, _ jego wysokosc
        // przy ustalaniu pozyucji trzeba wziasc pod uwage margines     
        n_pierw.setBounds(284 + insets.left, 12 + insets.top, 117, 16);
        pole.setBounds(284 + 115 + insets.left, 10 + insets.top, 30, 20);
        przycisk.setBounds(284 + 153 + insets.left, 7 + insets.top, 179, 26);

        // Do prawego boku
        opis_p.setBounds(750 + insets.left, 12 + insets.top, 88, 16);
        ilosc_pkt.setBounds(840 + insets.left, 9 + insets.top, 88, 22);

        // ustawienia Fonta
        Font font = new Font ("Calibri", Font.BOLD, 20);
        ilosc_pkt.setFont(font);





        main.getContentPane().setLayout(new FlowLayout());
        main.getContentPane().add(pierwiast);
        main.getContentPane().add(content);





        pierwiast.kontrola_gui(this);
        pierwiast.init();     




        main.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

    }

    @Override
    public void actionPerformed(ActionEvent e) {
        if(e.getActionCommand().equals("Spr"))
        {
            // pobranie tekstu z TextFielda
            String w_pierw = pole.getText();

            // Sprawdza czy String nie jest pusty
            if(!("").equals(w_pierw) && pierwiast.x1 != -1)
            {

                // sprawdza wprowadzony pierwiastek czy jest taki sam jak wpisalismy
                if (!w_pierw.equals(pierwiast.tab_pierw[pierwiast.x1].p_ch_n))
                {

                    // Zmniejszenie ilości punktów
                    pierwiast.punkty -=1;
                    ilosc_pkt.setText(Integer.toString(pierwiast.punkty));

                    JOptionPane.showMessageDialog(null, "Źle! Módl się byś nie zostął/a potraktowany/a chlorem!");
                    main.setTitle("Gra ułamki - złap pierwiastki chemiczne. Quickly! - " + pierwiast.tab_pierw[runner.x1].p_ch_n + " - Źle (-1 punkt) -- Aktualna ilość punktów : " + pierwiast.punkty);
                }
                else
                {
                    JOptionPane.showMessageDialog(null, "Poprawnie! Pani z chemii się cieszy!");

                    // Zwiększenie ilości punktów
                    pierwiast.punkty +=1;
                    ilosc_pkt.setText(Integer.toString(pierwiast.punkty));

                    main.setTitle("Gra ułamki - złap pierwiastki chemiczne. Quickly! - " + pierwiast.tab_pierw[runner.x1].p_ch_n + " - Dobrze (+1 punkt) -- Aktualna ilość punktów : " + pierwiast.punkty);
                    // ustawienie statusu do znikniecia
                    pierwiast.tab_pierw[pierwiast.x1].status_p = 2;

                    // usuwanie poprzedniego wyboru pierwiastka (unikniecie ponownego odkrycia)
                    pierwiast.x1 = -1;

                    //czyszczenie pola - do wpisywania
                    pole.setText("");

                }
            }
            else
            {
                 JOptionPane.showMessageDialog(null, "Nie wpisano nazwy pierwiastka lub nie kliknięto");
            }

        }
        else if (e.getActionCommand().equals("Login"))
        {
            String login = login_p.getText();
            String haslo = haslo_p.getText();

            if(!"".equals(login) && !"".equals(haslo))
            {
                logowanie.logowanie(login, haslo);

                if (logowanie.login)
                {
                    this.gra();
                }
            }
            else
            {
                JOptionPane.showMessageDialog(null, "Nie wpisano loginu i hasła");
            }
        }
    }


}

Where I make fault?
What is wrong?

— [edit] —

Resolve (For other seekers):

@Dave tip

//add revalidate for each component (Gra function)

        main.getContentPane().add(pierwiast);
        main.getContentPane().add(content);

        pierwiast.revalidate();
        content.revalidate();

And (At the start gra function)

        //main.getContentPane().removeAll(); <- Delete this
        //main.getContentPane().validate(); <- Delete this

        main.setTitle("Gra ułamki - złap pierwiastki chemiczne. Quickly! -- Aktualna ilość punktów : " + runner.punkty);

And
Before load (function gra) (public void actionPerformed)
in

                if (logowanie.login)
                {
                    main.getContentPane().removeAll(); //add this
                    main.repaint(); //add this
                    main.validate(); //add this
                    this.gra();
                }
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-27T21:27:55+00:00Added an answer on May 27, 2026 at 9:27 pm

    You need to call revalidate() on main when you’re done setting up the new content.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am using ajax to allow the user to filter content that appears in
I'm making a game that involves a 4*4 grid. The user enters letters and
Target application is a medium-sized website built to support several hundred to several thousand
Target failed to run: Remote exception encountered: Faild to get task for pid 3103
The target machine is running Ububtu server 8.04. Here's the tramp output: tramp: Opening
The target language is C/C++ and the program has only to work on Linux,
setTimeout(target.mousedown, 200) doesn't seem to work. I can do setTimeout(target.mousedown(), 200) , but this
(The target browser is IE8) I have a div that contains a list of
On an embedded target I use far pointers to access some parts of the
If I target the x86 platform for my .NET app, will it run properly

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.