jpanel swicthing problem....

Please support our Java advertiser: Programming Forums - DaniWeb Sister Site
Thread Solved

Join Date: Jun 2008
Posts: 23
Reputation: rude04 is an unknown quantity at this point 
Solved Threads: 0
rude04 rude04 is offline Offline
Newbie Poster

Re: jpanel swicthing problem....

 
0
  #11
Dec 22nd, 2008
uhhm..i have another question..
whats the simpliest code to display a PDF file inside a JTextArea??
Reply With Quote Quick reply to this message  
Join Date: May 2007
Posts: 4,501
Reputation: Ezzaral has much to be proud of Ezzaral has much to be proud of Ezzaral has much to be proud of Ezzaral has much to be proud of Ezzaral has much to be proud of Ezzaral has much to be proud of Ezzaral has much to be proud of Ezzaral has much to be proud of Ezzaral has much to be proud of Ezzaral has much to be proud of 
Solved Threads: 521
Moderator
Featured Poster
Ezzaral's Avatar
Ezzaral Ezzaral is offline Offline
Industrious Poster

Re: jpanel swicthing problem....

 
0
  #12
Dec 22nd, 2008
Haven't used it myself, but you might take a look at this article on using the Acrobat Viewer bean: http://today.java.net/pub/a/today/20...-javabean.html
Reply With Quote Quick reply to this message  
Join Date: Jun 2008
Posts: 23
Reputation: rude04 is an unknown quantity at this point 
Solved Threads: 0
rude04 rude04 is offline Offline
Newbie Poster

Re: jpanel swicthing problem....

 
0
  #13
Dec 23rd, 2008
thanks Ezzaral!!^^
Reply With Quote Quick reply to this message  
Join Date: Jun 2008
Posts: 23
Reputation: rude04 is an unknown quantity at this point 
Solved Threads: 0
rude04 rude04 is offline Offline
Newbie Poster

Re: jpanel swicthing problem....

 
0
  #14
Dec 25th, 2008
i really appreciate the code that you gave me but could you explain to me how this code works and what each part do??thanks..



  1. private void setQuestion(String str){ question = str;}
  2. public String getQuestion(){ return question;}




Originally Posted by peter_budo View Post
Test class as suggested
  1. public class Test
  2. {
  3. private String question;
  4. private String optionA;
  5. private String optionB;
  6. private String optionC;
  7. private String answer;
  8.  
  9. public Test(){}
  10.  
  11. public Test(String quest, String oA, String oB, String oC, String ans)
  12. {
  13. setQuestion(quest);
  14. setOptionA(oA);
  15. setOptionB(oB);
  16. setOptionC(oC);
  17. setAnswer(ans);
  18. }
  19.  
  20. private void setQuestion(String str){ question = str;}
  21. public String getQuestion(){ return question;}
  22.  
  23. private void setOptionA(String str){ optionA = str;}
  24. public String getOptionA(){ return optionA;}
  25.  
  26. private void setOptionB(String str){ optionB = str;}
  27. public String getOptionB(){ return optionB;}
  28.  
  29. private void setOptionC(String str){ optionC = str;}
  30. public String getOptionC(){ return optionC;}
  31.  
  32. private void setAnswer(String str){ answer = str;}
  33. public String getAnswer(){ return answer;}
  34. }
Reply With Quote Quick reply to this message  
Join Date: Dec 2004
Posts: 4,241
Reputation: peter_budo has much to be proud of peter_budo has much to be proud of peter_budo has much to be proud of peter_budo has much to be proud of peter_budo has much to be proud of peter_budo has much to be proud of peter_budo has much to be proud of peter_budo has much to be proud of peter_budo has much to be proud of peter_budo has much to be proud of 
Solved Threads: 491
Moderator
Featured Poster
peter_budo's Avatar
peter_budo peter_budo is offline Offline
Code tags enforcer

Re: jpanel swicthing problem....

 
0
  #15
Dec 25th, 2008
These methods are setter and getter as they help you initialize and retrieve value from an Object to which they are related to, hence the prefix of each method
private void setQuestion(String str){ question = str;}
public String getQuestion(){ return question;}
depending on project requirement you will make setter private or public, where getter is usually public.

In original code there is call for initializeTest() method that looks like this
  1. private void initializeTest()
  2. {
  3. test[0] = new Test("Question 1 to ask", "I like A", "I like B", "I like C", "I like B");
  4. test[1] = new Test("Question 2 to ask", "I like A", "I like B", "I like C", "I like A");
  5. test[2] = new Test("Question 3 to ask", "I like A", "I like B", "I like C", "I like C");
  6. }
in this method with every call for new Test a new object of type Test is created and because arguments been provided newly created object is automatically initialized with these arguments. The initialization take place in the constructors like in our case in this one
  1. public Test(String quest, String oA, String oB, String oC, String ans)
  2. {
  3. setQuestion(quest);
  4. setOptionA(oA);
  5. setOptionB(oB);
  6. setOptionC(oC);
  7. setAnswer(ans);
  8. }
where with the help of setter methods we initialize every variable of the Test object. If the setter method would be public instead of private we could do something like this
  1. test[0] = new Test();
  2. test[0].setQuestion("Question 1 to ask");
  3. test[0].setOptionA("I like A");
  4. test[0].setOptionB("I like B");
  5. test[0].setOptionB("I like B");
  6. test[0].setAnswer("I like B");
but this would be time consuming if we want to initialize more one object.

Getter method public String getQuestion(){ return question;} as you see return value of associated variable. These been used here
    private void setTest()
    {
    	titleLabel.setText("Question No. " + (qNum+1));
        questionNumLabel.setText((qNum+1)+"/3");
        
        questionLabel.setText(test[qNum].getQuestion());
        jrbA.setText(test[qNum].getOptionA());
        jrbB.setText(test[qNum].getOptionB());
        jrbC.setText(test[qNum].getOptionC());
        qNum++;
        if(qNum == 3)
        {
        	nextButton.setText("SUBMIT");
        }        
    }
More about how classes works, members variable declaration, defining methods and more could be found here
Learn to see in another's calamity the ills which you should avoid.
Publilius Syrus
(~100 BC)

LJC - London Java Community, Graduate & Undergraduate Software Development Community, JAVAWUG (Java Web User Group), The London Android Group
Reply With Quote Quick reply to this message  
Join Date: Jun 2008
Posts: 23
Reputation: rude04 is an unknown quantity at this point 
Solved Threads: 0
rude04 rude04 is offline Offline
Newbie Poster

Re: jpanel swicthing problem....

 
0
  #16
Dec 25th, 2008
I didn't want to use a code that i didn't understand..
thanks for the explanation peter_budo..
Reply With Quote Quick reply to this message  
Reply

This thread has been marked solved.
Perhaps start a new thread instead?
Message:


Thread Tools Search this Thread



Tag cloud for Java
About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC