Search...
FAQs
Subscribe
Pie
FAQs
Recent topics
Flagged topics
Hot topics
Best topics
Search...
Search within Beginning Java
Search Coderanch
Advance search
Google search
Register / Login
Post Reply
Bookmark Topic
Watch Topic
New Topic
programming forums
Java
Mobile
Certification
Databases
Caching
Books
Engineering
Micro Controllers
OS
Languages
Paradigms
IDEs
Build Tools
Frameworks
Application Servers
Open Source
This Site
Careers
Other
Pie Elite
all forums
this forum made possible by our volunteer staff, including ...
Marshals:
Campbell Ritchie
Jeanne Boyarsky
Ron McLeod
Paul Clapham
Liutauras Vilda
Sheriffs:
paul wheaton
Rob Spoor
Devaka Cooray
Saloon Keepers:
Stephan van Hulst
Tim Holloway
Carey Brown
Frits Walraven
Tim Moores
Bartenders:
Mikalai Zaikin
Forum:
Beginning Java
I would like to know the format to display the output at a particular location
Radhika Srinivasan
Ranch Hand
Posts: 32
posted 14 years ago
Number of slices to send:
Optional 'thank-you' note:
Send
import java.applet.*; import java.awt.*; import java.awt.event.*; public class MultipleChoice1 extends Applet implements ItemListener { String question1 = new String("1. 7+2 = ? a.6 b.8 c.9 d.10"); String question2 = new String("2. 9-5 = ? a.2 b.4 c.6 d.8"); String question3 = new String("3. 144/12 = ? a.12 b.10 c.14 d.16"); String question4 = new String("4. 5*5 = ? a.10 b.20 c.25 d.125"); String question5 = new String("5. 2+3+5 = ? a.7 b.8 c.9 d.10"); Font regFont = new Font("Arial", Font.BOLD,16); CheckboxGroup ques1Grp = new CheckboxGroup(); Checkbox a1 = new Checkbox("6",false,ques1Grp); Checkbox b1 = new Checkbox("8",false,ques1Grp); Checkbox c1 = new Checkbox("9",false,ques1Grp); Checkbox d1 = new Checkbox("10",false,ques1Grp); CheckboxGroup ques2Grp = new CheckboxGroup(); Checkbox a2 = new Checkbox("2",false,ques2Grp); Checkbox b2 = new Checkbox("4",false,ques2Grp); Checkbox c2 = new Checkbox("6",false,ques2Grp); Checkbox d2 = new Checkbox("8",false,ques2Grp); CheckboxGroup ques3Grp = new CheckboxGroup(); Checkbox a3 = new Checkbox("12",false,ques3Grp); Checkbox b3 = new Checkbox("10",false,ques3Grp); Checkbox c3 = new Checkbox("14",false,ques3Grp); Checkbox d3 = new Checkbox("16",false,ques3Grp); CheckboxGroup ques4Grp = new CheckboxGroup(); Checkbox a4 = new Checkbox("10",false,ques4Grp); Checkbox b4 = new Checkbox("20",false,ques4Grp); Checkbox c4 = new Checkbox("25",false,ques4Grp); Checkbox d4 = new Checkbox("125",false,ques4Grp); CheckboxGroup ques5Grp = new CheckboxGroup(); Checkbox a5 = new Checkbox("7",false,ques5Grp); Checkbox b5 = new Checkbox("8",false,ques5Grp); Checkbox c5 = new Checkbox("9",false,ques5Grp); Checkbox d5 = new Checkbox("10",false,ques5Grp); public void init() { add(a1); a1.addItemListener(this); add(b1); b1.addItemListener(this); add(c1); c1.addItemListener(this); add(d1); d1.addItemListener(this); add(a2); a2.addItemListener(this); add(b2); b2.addItemListener(this); add(c2); c2.addItemListener(this); add(d2); d2.addItemListener(this); add(a3); a3.addItemListener(this); add(b3); b3.addItemListener(this); add(c3); c3.addItemListener(this); add(d3); d3.addItemListener(this); add(a4); a4.addItemListener(this); add(b4); b4.addItemListener(this); add(c4); c4.addItemListener(this); add(d4); d4.addItemListener(this); add(a5); a5.addItemListener(this); add(b5); b5.addItemListener(this); add(c5); c5.addItemListener(this); add(d5); d5.addItemListener(this); } public void paint(Graphics gr) { gr.fillRect(20,20,800,800); setBackground(Color.pink); gr.setFont(regFont); gr.setColor(Color.pink); gr.drawString(question1,250,100); a1.setLocation(250,114); b1.setLocation(280,114); c1.setLocation(310,114); d1.setLocation(340,114); gr.drawString(question2,250,200); a2.setLocation(250,214); b2.setLocation(280,214); c2.setLocation(310,214); d2.setLocation(340,214); gr.drawString(question3,250,300); a3.setLocation(250,314); b3.setLocation(280,314); c3.setLocation(310,314); d3.setLocation(340,314); gr.drawString(question4,250,400); a4.setLocation(250,414); b4.setLocation(280,414); c4.setLocation(310,414); d4.setLocation(340,414); gr.drawString(question5,250,500); a5.setLocation(250,514); b5.setLocation(280,514); c5.setLocation(310,514); d5.setLocation(340,514); gr.setColor(Color.blue); } public void itemStateChanged(ItemEvent e) { int numberCorrect=0; int score; Checkbox user1Selection = ques1Grp.getSelectedCheckbox(); System.out.println(user1Selection); if(user1Selection == c1)// checks whether the answer matches { System.out.println("Correct");[b] [quote] I would like to know the format to display this output at the location 250,150 [/quote][/b] //displays correct if the answer matches numberCorrect++; // adds 1 to the number of correct answers }else System.out.println("Sorry! The correct answer is c \n"); [b][quote] I would like to know the format to display this output at the location 250,150 [/quote][/b] // if the answer is incorrect displays the correct answer Checkbox user2Selection = ques2Grp.getSelectedCheckbox(); System.out.println(user2Selection); if(user2Selection == b2)// checks whether the answer matches { System.out.println("Correct");[b] [quote] I would like to know the format to display this output at the location 250,250 [/quote][/b] //displays correct if the answer matches numberCorrect++; // adds 1 to the number of correct answers }else System.out.println("Sorry! The correct answer is b \n");[b] [quote] I would like to know the format to display this output at the location 250,250 [/quote][/b] // if the answer is incorrect displays the correct answer Checkbox user3Selection = ques3Grp.getSelectedCheckbox(); System.out.println(user3Selection); if(user3Selection == a3)// checks whether the answer matches { System.out.println("Correct"); [b][quote] I would like to know the format to display this output at the location 250,350 [/quote][/b] //displays correct if the answer matches numberCorrect++; // adds 1 to the number of correct answers }else System.out.println("Sorry! The correct answer is a \n");[b] [quote] I would like to know the format to display this output at the location 250,350 [/quote][/b] // if the answer is incorrect displays the correct answer Checkbox user4Selection = ques4Grp.getSelectedCheckbox(); System.out.println(user4Selection); if(user4Selection == c4)// checks whether the answer matches { System.out.println("Correct");[b] [quote] I would like to know the format to display this output at the location 250, 450 [/quote][/b] //displays correct if the answer matches numberCorrect++; // adds 1 to the number of correct answers }else System.out.println("Sorry! The correct answer is c \n"); [b][quote] I would like to know the format to display this output at the location 250, 450 [/quote][/b] // if the answer is incorrect displays the correct answer Checkbox user5Selection = ques5Grp.getSelectedCheckbox(); System.out.println(user5Selection); if(user5Selection == d5)// checks whether the answer matches { System.out.println("Correct");[b][quote] I would like to know the format to display this output at the location 250, 550 [/quote] [/b]//displays correct if the answer matches numberCorrect++; // adds 1 to the number of correct answers }else System.out.println("Sorry! The correct answer is d \n"); [b] [quote] I would like to know the format to display this output at the location 250,550 [/quote][/b] // if the answer is incorrect displays the correct answer System.out.println("\n You had "+numberCorrect+" question correct.\n");[b] [quote] I would like to know the format to display this output at the location 250,650 [/quote] [/b]// displays number of questions correct score = (numberCorrect*20);//score calculation if (score>=60) { // Displays the end result if the user scores >= 60 it congratulates them or if it's <60 displays better luck next time. System.out.println("Congratulations,you passed with a score of "+score+ "%\n");[b][quote] I would like to know the format to display this output at the location 250, 680 [/quote][/b] }else{ System.out.println("Sorry, your grade was "+score+"% Better luck next time!");[b] [quote] I would like to know the format to display this output at the location 250, 700 [/quote][/b] repaint();} } }
Many thanks,
Radhika
David Newton
Author
Posts: 12617
I like...
posted 14 years ago
Number of slices to send:
Optional 'thank-you' note:
Send
Use a text element.
Radhika Srinivasan
Ranch Hand
Posts: 32
posted 14 years ago
Number of slices to send:
Optional 'thank-you' note:
Send
Could you give me an example as to, how do I use a text element??
Thanks,
Radhika
David Newton
Author
Posts: 12617
I like...
posted 14 years ago
Number of slices to send:
Optional 'thank-you' note:
Send
If that doesn't work (I hadn't noticed you were using an
applet
; it's been awhile since I've done that) I'm a little confused at how you're able to draw your questions at certain coordinates but can't draw an answer at certain coordinates.
Did you see how Paul
cut 87% off of his electric heat bill with 82 watts of micro heaters
?
reply
reply
Bookmark Topic
Watch Topic
New Topic
Boost this thread!
Similar Threads
CheckboxGroup in Dialog
Need ur suggestion... Urgent!
Illegal start of expression
How to display the output using Labels??
Some of you are experts this could be your next problem!
More...