• Post Reply Bookmark Topic Watch Topic
  • New Topic

Passing values between two JPanel forms in Java Swing.

 
Chiranthaka Jayakody
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have created 3 classes. 1st class is used to store variable. other classes are use to input data and to display data.


1st Class




This is class is designed using the Swing JPanel object and used to enter StudNo, StudName, Marks for 3 subjects. This also include 2 buttons as btnCalculate and btnCancel. This user interface was developed using Java swing class by auto generating. When the btnCalculate clicks the data within the textfields will be assign to the 1st classes variables. And at there the calculations will be done using 3 methods.


2nd Class




The other user interface that used to view the final results of the calculations i.e. Total marks, Average marks and the grade. When the btnCalculate clicks the result should pass to the 3rd class i.e. DisplayInfo JPanel
class. My Problem is when I click the btnCalculate button it does calculate the total marks, average marks and the grade. The 3rd class i.e. the DisplayInfo JPanel form will also displayed but the data did not pass the text
fields were empty.


3rd Class



[b] All I want is when the 2nd JPanel form i.e. DisplayDetails opens the data in the Student class to be inserted to the TextFields of the DisplayDetails form. I am stuck at that point. If you please give me some clue about that. Because Ypu have mentioned about the JPanel's update ( ) but I couldn't find that. I don't think that is an inbuilt one. Thank You![/b]
 
Chiranthaka Jayakody
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have solved my problem by using the static keyword. I changed all the variables in the Student class from non-static to static content and also I changed all
the getter () and setter () from non-static to static content.

Then the access of the variables and other methods are as the below.




 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!