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

  • SEARCH
  • Home
  • 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 8234853
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T18:37:21+00:00 2026-06-07T18:37:21+00:00

Ok guys, I’ve made some changes in my code as told by you. I

  • 0

Ok guys, I’ve made some changes in my code as told by you. I have 3 classes:

The second class (and first GUI): I have 4 JButtons – Simulare, CazParticular, Start and HandSelection, some JLabels and 3 JTextFields; When I press the HandSelection button another frame it’s created with different content.

The 3rd class (and second GUI): I have 2 JButtons – Ok and Cancel and other stuff. When I press the Ok button I want to the access to the JTextField(QuesHandText) from the first Gui and use the method setText(). I can’t figure this out, I’m thinking on this like 4-5 days and still can’t get the answer. Please help me!

Screenshot

What code should I write in if statement to be able to modify the text in the JTextField from 2nd class (first GUI) ?

First class:

import javax.swing.JFrame;
public class Main {

    public static void main(String[] args){

        //other stuff
        GuiMain gui = new GuiMain();

        gui.frame1.setLocation(150,150);
        gui.frame1.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); 
        gui.frame1.setSize(400,250);
        gui.frame1.setResizable(false);
        gui.frame1.setVisible(true);

        //other stuff
    }
}

Second class:

import java.awt.*;
import java.awt.event.ActionListener;
import java.awt.event.ActionEvent;
import java.awt.event.ItemEvent;
import java.awt.event.ItemListener;
import java.awt.event.KeyEvent;
import java.awt.event.KeyListener;
import java.awt.event.WindowEvent;
import javax.swing.*;

public class GuiMain {

    public static GuiMain instance;
public static GuiMain getInstance(){
    if(GuiMain.instance == null){GuiMain.instance = new GuiMain();}
    return GuiMain.instance;
}
    public JFrame frame1 = new JFrame();

    public JTextField QuesHandText, FlopTurnRiverText, RezultatText; 
    public JButton Simulare, CazParticular, Start, HandSelection;
    public int w1,h1;
    public JLabel someText;
    static int u=0;
    public int j=0;

    public GuiMain(){

        frame1.setTitle("HoldemTool");
        frame1.setLayout(null);
        QuesHandText = new JTextField(4);

        Simulare = new JButton("Simulare");
        CazParticular = new JButton("Caz particular");
        Start = new JButton("Start");
        HandSelection = new JButton(new ImageIcon(getClass().getResource("GuiPic.png")));
        Handler handler1 = new Handler();

        CazParticular.addActionListener(handler1);
        Simulare.addActionListener(handler1);

        HandSelection.addActionListener(handler1);
        Start.addActionListener(handler1);

        QuesHandText.setEditable(false);
        FlopTurnRiverText.setEditable(false);
        RezultatText.setEditable(false);

        frame1.add(Welcome1);
        frame1.add(Welcome2);
        frame1.add(QuesHand);
        frame1.add(FlopTurnRiver);
        frame1.add(Rezultat);
        frame1.add(QuesHandText);
        frame1.add(FlopTurnRiverText);
        frame1.add(RezultatText);
        frame1.add(Simulare);
        frame1.add(CazParticular);
        frame1.add(Start);

    }

    public JTextField getQuesHandText(){
    return QuesHandText;
}
    public class Handler implements ActionListener{
        public void actionPerformed(ActionEvent e){

            if(e.getSource()==Simulare)
            {

            }
            if(e.getSource()==CazParticular){
                QuesHandText.setEditable(true);
                FlopTurnRiverText.setEditable(true);

                QuesHandText.setText("");
                FlopTurnRiverText.setText("");
                RezultatText.setText("");

                frame1.setSize(470, 250);
                Start.setBounds(3*FlopTurnRiverText.getX(), QuesHand.getY(), 65, h1);
                HandSelection.setBounds(3*FlopTurnRiverText.getX(), FlopTurnRiverText.getY(), 65, h1);

                frame1.add(HandSelection);
                frame1.add(Start);
            }
            if(e.getSource()==Start){
                QuesHandText.setText("Text");
            }
            if(e.getSource()==HandSelection){
                GuiSelection gui2 = new GuiSelection();  
                gui2.frame2.setVisible(true);
            }
        }

    }}

3rd class

import java.awt.*;
import java.awt.event.ActionListener;
import java.awt.event.ActionEvent;
import java.awt.event.ItemEvent;
import java.awt.event.ItemListener;
import java.awt.event.KeyEvent;
import java.awt.event.KeyListener;
import java.awt.event.WindowEvent;
import javax.swing.*;

public class GuiSelection extends GuiMain {

    JFrame frame2 = new JFrame();
    GuiMain guiMain;
    public JButton Ok,Cancel;

    //other stuff

    public GuiSelection(){
        guiMain = new GuiMain();
        frame2.setTitle("Hand selection");
        frame2.setSize(1135,535);
        frame2.setLayout(null);
        frame2.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        frame2.setVisible(true);
        frame2.setResizable(false);

        //other stuff

        Handler2 handler2 = new Handler2();

        Ok.addActionListener(handler2);
        Cancel.addActionListener(handler2);

        frame2.add(Ok); frame2.add(Cancel); 

    }

    public class Handler2 implements ActionListener{
        public void actionPerformed(ActionEvent e){
            if(e.getSource()==Cancel){
                frame2.hide();
            }
            if(e.getSource()==Ok)
            {
            GuiMain.getInstance().getQuesHandText().setText("From Ok");

                //When I prees this button "Ok" I want to get access to the JTextField(QuesHandText) in the         GuiMain class, and .setText();
                //somothing like QuesHandtText.setText("someText");
            }
        }
    }
}
  • 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-06-07T18:37:22+00:00Added an answer on June 7, 2026 at 6:37 pm

    Add to your first GUI the method public JTextField getQuesHandText() and a static method public static JFrame getInstance() which returns the instance of the first GUI. Now you can call SecondClass.getInstance().getQuesHandText() from anywhere to get the JTextField instance. Note that with this method you can only have a single instance of SecondClass at any time.

    Your getInstance() method will look as follows:

    public class SecondClass extends JFrame {
    
        private static SecondClass instance;
    
        public static SecondClass getInstance() {
            if(SecondClass.instance == null)
                SecondClass.instance = new SecondClass();
    
            return SecondClass.instance
        }
    
    }
    

    Note that you shouldn’t create an instance of SecondClass manually.

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

Sidebar

Related Questions

guys. I have two view controllers with two uiwebviews. Here is my code: First
guys. I have UITableView with different cells and I have code, which counts height.
Guys if I have class like below: template<class T> class X { T** myData_;
Guys can you suggest me any software who have some similarities with Microsoft's SQL
guys I want to start programing with C++. I have written some programs in
guys I am newbie to Hive and have some doubts in it. Normally we
Guys, for some reason EL is not telling actions from properties. I have this
Guys, I need some help! I have a fully rendered menu (a safe html
guys, I have UITableView with some images, which are loading from internet. Images is
Guys I have an activity which has a home button, when the button is

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.