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 7608551
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T00:56:31+00:00 2026-05-31T00:56:31+00:00

Based on the diagram above; I would like Frame1 to show Frame2 using New(Jbutton)

  • 0

enter image description here

Based on the diagram above; I would like Frame1 to show Frame2 using New(Jbutton) and Frame3 show using Show(JButton). Frame3 has this default “Hello World”(JtextField) and I would like to make this empty using the Yes(JButton) from Frame2.

The problem is that I don’t know the code for Frame2 and how to empty the textfield from frame3.

Here is my code so far:

Frame1.java

public class Frame1 extends JFrame implements ActionListener{

JButton b1 = new JButton("New");
JButton b2 = new JButton("Show");

Frame2 f2 = new Frame2();
Frame3 f3 = new Frame3();

public Frame1(){
    setLayout(new FlowLayout());
    setVisible(true);
    setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    setSize(300,300);
    add(b1);
    add(b2);
    b1.addActionListener(this);
    b2.addActionListener(this);
}

public static void main(String args[]){
    new Frame1();
}

public void actionPerformed(ActionEvent e) {
    if(e.getSource()==b1){
        f2.setVisible(true);
    }
    else{
        f3.setVisible(true);
    }
}
}

Frame2.java

public class Frame2 extends JFrame implements ActionListener{

JButton b1 = new JButton("Yes");
JButton b2 = new JButton("No");

public Frame2(){
    setLayout(new FlowLayout());
    setVisible(false);
    setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    setSize(300,100);

    add(b1);
    add(b2);
}
public void actionPerformed(ActionEvent e) {
    if(e.getSource()==b1){

    }else{

    }
}
}

Frame3.java

public class Frame3 extends JFrame{

JTextField t1 = new JTextField("Hello WOrld");

public Frame3(){
    setLayout(new FlowLayout());
    setVisible(false);
    setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    setSize(200,200);

    add(t1);

}

}
  • 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-31T00:56:33+00:00Added an answer on May 31, 2026 at 12:56 am

    You could just just pass a reference to the frame3 in your frame2 constructor, and then when you click on the Yes button, clear the JTextField of your frame3.

    EDIT

    Well when you declare your frames, you could create your frame3 before and pass it to the frame2 constructor:

    Frame3 f3 = new Frame3();
    Frame2 f2 = new Frame2(f3);
    

    and in your frame2

    Frame refToFrame3;
    ...
    public Frame2(Frame f){
       ...
       refToFrame3 = f;
       ...
    ...
    
    public void actionPerformed(ActionEvent e) {
        if(e.getSource()==b1){
            refToFrame3.clearText()
            ...
    

    and then in your frame3 you create a clearText method that will clear the text in your JTextField.

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

Sidebar

Related Questions

Based on this question it appears that the default template for CheckStyle will allow
I'm writing a diagram editor in java. This app has the option to export
Is there some javascript alternative or solution like this: www.objecthandles.com I'm making a web-based
Essentially what I would like to do is draw a circuit diagram in a
This question is based on my plan at the thread . My entity-relationship diagram
Based on the response to this question: Why does C++ have header files and
Based on my previous question here my new concern is how do I unit
Based on this question I don't want to litter my ready stuff waiting for
Can you suggest some UML diagram drawing tool based on the script similar to
I'm looking for a very simple wpf diagram toolset that would allow me to

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.