943,734 Members | Top Members by Rank

Ad:
  • Java Discussion Thread
  • Marked Solved
  • Views: 1332
  • Java RSS
You are currently viewing page 2 of this multi-page discussion thread; Jump to the first page
Dec 22nd, 2008
0

Re: jpanel swicthing problem....

uhhm..i have another question..
whats the simpliest code to display a PDF file inside a JTextArea??
Reputation Points: 10
Solved Threads: 0
Light Poster
rude04 is offline Offline
26 posts
since Jun 2008
Dec 22nd, 2008
0

Re: jpanel swicthing problem....

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
Moderator
Featured Poster
Reputation Points: 3239
Solved Threads: 838
Posting Genius
Ezzaral is offline Offline
6,761 posts
since May 2007
Dec 23rd, 2008
0

Re: jpanel swicthing problem....

thanks Ezzaral!!^^
Reputation Points: 10
Solved Threads: 0
Light Poster
rude04 is offline Offline
26 posts
since Jun 2008
Dec 25th, 2008
0

Re: jpanel swicthing problem....

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..



java Syntax (Toggle Plain Text)
  1. private void setQuestion(String str){ question = str;}
  2. public String getQuestion(){ return question;}




Click to Expand / Collapse  Quote originally posted by peter_budo ...
Test class as suggested
java Syntax (Toggle Plain Text)
  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. }
Reputation Points: 10
Solved Threads: 0
Light Poster
rude04 is offline Offline
26 posts
since Jun 2008
Dec 25th, 2008
0

Re: jpanel swicthing problem....

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
Java Syntax (Toggle Plain Text)
  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
Java Syntax (Toggle Plain Text)
  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
Java Syntax (Toggle Plain Text)
  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
Moderator
Featured Poster
Reputation Points: 2786
Solved Threads: 871
Code tags enforcer
peter_budo is offline Offline
6,656 posts
since Dec 2004
Dec 25th, 2008
0

Re: jpanel swicthing problem....

I didn't want to use a code that i didn't understand..
thanks for the explanation peter_budo..
Reputation Points: 10
Solved Threads: 0
Light Poster
rude04 is offline Offline
26 posts
since Jun 2008

This thread is solved

Either the thread starter or a moderator has marked this thread as solved. You can most likely trust the responses and answers given. There is most likely no reason for any further responses to be posted here. If you have a related question, please start a new thread in this forum instead.

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in Java Forum Timeline: JOptionPanes
Next Thread in Java Forum Timeline: Hi My dear friends, Pls help me





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC