Question

I am learning java and starting with the concepts of JPanels. currently the program i am testing with consists of two windows. the first window contains one button. on clicking the button the second window containing a numpad opens up. now the question i have is 1. how can i return the number i have selected by clicking the numpad back to the parent panel? I need to use the method for the ease of accepting integers. 2. how do i restrict the length of the JTextField? say i need to accept only two characters... 3. how do i transfer back the control from the child panel to the parent panel by clicking a button along with the data ofcourse? 4. how can i design the child panel so that it does not show the header bar along with the close button?

Was it helpful?

Solution

How can i return the number i have selected by clicking the numpad back to the parent panel? I need to use the method for the ease of accepting integers.

You could:

  • Have a property in the parent class with the appropriate setter.
  • When you call the child frame, pass an instance of the parent frame to the child frame.
  • When you are done with your child frame, use the parent instance to change the property described in step 1 and call dispose() on the frame. This should allow your parent frame to have the value which was selected in the child frame.

How do i restrict the length of the JTextField? say i need to accept only two characters

You will need to create something like this since it seems that Java does not provide such functionality out of the box.

How do i transfer back the control from the child panel to the parent panel by clicking a button along with the data ofcourse?

There seems to be two options for this:

How can i design the child panel so that it does not show the header bar along with the close button

You will need to take a look at the setUndecorated(boolean bool)

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top