| | |
jpanel swicthing problem....
Please support our Java advertiser: Programming Forums - DaniWeb Sister Site
Thread Solved |
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
•
•
Join Date: Jun 2008
Posts: 23
Reputation:
Solved Threads: 0
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)
private void setQuestion(String str){ question = str;} public String getQuestion(){ return question;}
•
•
•
•
Test class as suggested
java Syntax (Toggle Plain Text)
public class Test { private String question; private String optionA; private String optionB; private String optionC; private String answer; public Test(){} public Test(String quest, String oA, String oB, String oC, String ans) { setQuestion(quest); setOptionA(oA); setOptionB(oB); setOptionC(oC); setAnswer(ans); } private void setQuestion(String str){ question = str;} public String getQuestion(){ return question;} private void setOptionA(String str){ optionA = str;} public String getOptionA(){ return optionA;} private void setOptionB(String str){ optionB = str;} public String getOptionB(){ return optionB;} private void setOptionC(String str){ optionC = str;} public String getOptionC(){ return optionC;} private void setAnswer(String str){ answer = str;} public String getAnswer(){ return answer;} }
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
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
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
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
but this would be time consuming if we want to initialize more one object.
Getter method
More about how classes works, members variable declaration, defining methods and more could be found here
private void setQuestion(String str){ question = str;} public String getQuestion(){ return question;}
In original code there is call for initializeTest() method that looks like this
Java Syntax (Toggle Plain Text)
private void initializeTest() { test[0] = new Test("Question 1 to ask", "I like A", "I like B", "I like C", "I like B"); test[1] = new Test("Question 2 to ask", "I like A", "I like B", "I like C", "I like A"); test[2] = new Test("Question 3 to ask", "I like A", "I like B", "I like C", "I like C"); }
Java Syntax (Toggle Plain Text)
public Test(String quest, String oA, String oB, String oC, String ans) { setQuestion(quest); setOptionA(oA); setOptionB(oB); setOptionC(oC); setAnswer(ans); }
Java Syntax (Toggle Plain Text)
test[0] = new Test(); test[0].setQuestion("Question 1 to ask"); test[0].setOptionA("I like A"); test[0].setOptionB("I like B"); test[0].setOptionB("I like B"); test[0].setAnswer("I like B");
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");
}
} 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
Publilius Syrus
(~100 BC)
LJC - London Java Community, Graduate & Undergraduate Software Development Community, JAVAWUG (Java Web User Group), The London Android Group
![]() |
Other Threads in the Java Forum
- Previous Thread: Hi i am thinking about using java to write a Program for Cell phones
- Next Thread: Hi My dear friends, Pls help me
| Thread Tools | Search this Thread |
Tag cloud for Java
android api apple applet application arc arguments array arrays automation binary bluetooth c++ chat class classes client code codesnippet component csv database doctype draw ebook eclipse error event exception fractal freeze game givemetehcodez graphics gui html ide image input integer intellij iphone j2me java java.xls javaprojects jmf jni jpanel julia linux list loop loops mac map method methods mobile netbeans newbie number online oracle page parameter plazmic print problem program programming project recursion reporting rotatetext scanner screen sell server set size sms socket sort sourcelabs sql string superclass swing system template test testautomation threads time title tree tutorial-sample windows working






