Reputation: 1734
I have a main JFrame
which consists of 3 small JPanel
which are switched on the basis of selection by the user.
The problem is that I have to save the data inserted into JPanel
into the database but I am unable to access the elements of the JPanel
directly. So how do I accept those.
The entry in DB is done when the ACCEPT button is clicked in the main frame. Please help
if(Selected==Credit Card){
Select Credit Card Panel;
}
if(Selected==Debit Card){
Select Debit Card Panel;
}
if(Selected==Cash on Delivery){
Select Cash on Delivery Panel;
}
onAccept(){
if(Selected==Credit Card){
get data from Credit Card panel and store in Database; (variables like cc number, cvv)
}
if(Selected==Debit Card){
get data from Debit Card panel and store in Database;
}
if(Selected==Cash on Delivery){
get data from Cash on Delivery Card panel and store in Database;
}
}
Upvotes: 0
Views: 261
Reputation: 692181
Have each of your 3 panels implement the same interface:
public interface DataStorer {
public void storeDataInDatabase();
}
Then, when the accept button is clicked, call this:
DataStorer selectedPanel = (DataStorer) theDisplayedPanel;
selectedPanel.storeDataInDatabase();
Upvotes: 2