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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T23:07:59+00:00 2026-06-03T23:07:59+00:00

before I start, I’m a beginner programmer. How can I enable a text field

  • 0

before I start, I’m a beginner programmer.

How can I enable a text field when a button is clicked.

I have two frames, one that has the JFields and the other for the exception.
When the exception occurs > setEditable(false)
but what statement should I make to enable the JFields once the user click on okay button -that i’ve made in the exception-?

I’ve tried to add static boolean to exception frame, and inside the action performed of this class I initialized that boolean to true.

in the other class, I added an if statment, if that boolean is true, then setEditable(true)

-========-
The point of this program, that when the exception occurs the user cannot enter anything in the fields until he closes the exception window.

I wish you’d help me.

With all love, programmers.

The code of action performed for THE EXCEPTION WINDOW FRAME ( having Okay button. )

  public void actionPerformed(ActionEvent e){
      {
      allow=true; //static boolean
        Container TheFrame = OKButton.getParent();
        do TheFrame = TheFrame.getParent(); 
                 while (!(TheFrame instanceof JFrame));

        ((JFrame) TheFrame).dispose();

     }

The code of action performed for THE MAIN PROGRAM (having three fields, an exception will occur once the user enters non digits )
I added some comments to clarify.

  public void actionPerformed(ActionEvent event) {

     try{
        r =Double.parseDouble(RField.getText());
        s=Double.parseDouble(SField.getText());
        h=Double.parseDouble(HField.getText());


        Cone C = new Cone(r,s,h);//class cone 
        if (event.getSource() instanceof JButton) {
           JButton clickedButton = (JButton) event.getSource();
           if (clickedButton == VolumeButton) {
              Result.append("VOLUME =  "+C.volume()+ "\n");
              ifV= true;//this's for clearing the fields for new entries.


           }
           if (clickedButton == AreaButton) {
              Result.append("SURFACE AREA =  "+C.surfaceArea()+ "\n");
              ifA= true;//this's for clearing the fields for new entries.


           }

           if(ifA&&ifV){ // clearing the fields for new entries.
              SField.setText(CLEAR);
              HField.setText(CLEAR);
              RField.setText(CLEAR); 
              ifV=false; ifA= false;}



        } 


        SList.addShape(C);

     }

        catch(NumberFormatException e){ 

        //Object of type "Exception__" already created 

           Ex.setVisible(true);//class "Exception__" is the one i've made for Exception window

           SField.setText(CLEAR);
           HField.setText(CLEAR);
           RField.setText(CLEAR);
           SField.setEditable(false);
           HField.setEditable(false);
           RField.setEditable(false);


        }/*here, if the user clicked on -that okay in Exception window- 
and variable allow initialized to "true" those statements should extend. I guess? 
- everything worked correctly except for this ?*/
     if(Ex.allow){    
        SField.setEditable(true);
        HField.setEditable(true);
        RField.setEditable(true);  } 


  }

THANK YOU ALL IT FINALLY WORKED.

I added

Ex.allow(SField,HField,RField);

to the catch.

and added this method in class Exception__:

        public void allow(JTextField js,JTextField jh,JTextField jr){

     HField =jh;
     SField =js;
     RField =jr;
  }

finally, to the action performed of class Exception__:

  SField.setEditable(true);
           HField.setEditable(true);
           RField.setEditable(true);

WOHOOOO. It feels so awesome lol. Thanks all. should I delete my question or leave it for others who might face the same problem as mine? 😛

  • 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-03T23:08:01+00:00Added an answer on June 3, 2026 at 11:08 pm

    Your question needs a lot more detail. But if all you want to to show an ‘exception window’ and allow the user to do anything else only after she dismisses this window, I think all you need is a MessageDialog:
    See JOptionPane

    If you need more details to be displayed you can create your own modal JDialog.

    See How to Make Dialogs

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

Sidebar

Related Questions

I want to get one record before start date and end date DtpFrom means
I have written some code to check two dates, a start date and an
Before start let me tell my experience: I am experienced with C#.NET, web services,
Am using Mediainfo library in my C# project,before start invoking this dll,i just ran
I usually try to do TDD with not much analysis (no diagrams) before start
I am working on a Media up-loader which uploads images to Server. Before start
Before I start, I know there is this post and it doesn't answer my
Before you start firing at me, I'm NOT looking to do this, but someone
Before I start developing a desktop application, I was wondering how large the installer
Before you start flaming, I'm going to tell you that I am trying 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.