Spelling Test using a button GUI environment..how do I create a brand new window?

Reply

Join Date: Oct 2004
Posts: 1
Reputation: chocobo74 is an unknown quantity at this point 
Solved Threads: 0
chocobo74 chocobo74 is offline Offline
Newbie Poster

Spelling Test using a button GUI environment..how do I create a brand new window?

 
0
  #1
Oct 31st, 2004
This is my skeleton of my very basic computing project, which is to create a spelling test displaying twenty questions:

  1. //
  2. // spell_test.java
  3. // spell_test
  4. //
  5. // Created by chocobo74 on 21/09/2004.
  6. // Copyright (c) 2004 __MyCompanyName__. All rights reserved.
  7. // A simple Java applet
  8. //
  9.  
  10. import java.awt.*;
  11. import java.awt.event.*;
  12. import java.applet.*;
  13.  
  14. public class TrivialApplet extends Applet implements ActionListener {
  15.  
  16. private Button beuts, boots, bootz, bots, next_q;
  17. private Image image1, image2, image3, image4, image5;
  18. private AudioClip sound1, sound2;
  19. private int choice;
  20.  
  21. public void init () {
  22. Label title1;
  23. title1= new Label ("How do you spell a pair of rather large shoes?");
  24.  
  25. add(title1);
  26.  
  27. image1=getImage (getDocumentBase(), "beuts.jpg");
  28. beuts = new Button ("beuts");
  29. add(beuts);
  30. beuts.addActionListener(this);
  31.  
  32. image2=getImage (getDocumentBase(), "boots.jpg");
  33. boots = new Button ("boots");
  34. add(boots);
  35. boots.addActionListener(this);
  36.  
  37. image3=getImage (getDocumentBase(), "bootz.jpg");
  38. bootz= new Button ("bootz");
  39. add(bootz);
  40. bootz .addActionListener(this);
  41.  
  42. image4=getImage (getDocumentBase(), "bots.jpg");
  43. bots= new Button ("bots");
  44. add(bots);
  45. bots.addActionListener(this);
  46.  
  47. next_q = new Button ("Next Question");
  48. add(next_q);
  49. next_q.addActionListener(this);
  50.  
  51. image5=getImage (getDocumentBase(), "these.jpg");
  52.  
  53. sound1=getAudioClip(getDocumentBase(),"spam_song.au");
  54. sound2=getAudioClip(getDocumentBase(),"doh.au");
  55. //these declare the buttons, images and sounds to be used//
  56.  
  57. }
  58.  
  59. public void paint (Graphics g) {
  60.  
  61. g.drawImage(image5,0,10,100,150,this);
  62.  
  63. if (choice == 1){ //this method declares what will happen when the user chooses a button//
  64. g.drawImage(image1,200,70,100,150,this);
  65. g.drawString ("Incorrect answer!",250,60);
  66. sound2.play();
  67. sound1.stop();
  68. }
  69.  
  70. if (choice == 2){
  71. g.drawImage(image2,200,70,100,150,this);
  72. g.drawString ("Correct answer!",250,60);
  73. sound1.play();
  74. sound2.stop();
  75. }
  76.  
  77. if (choice == 3){
  78. g.drawImage(image3,200,70,100,150,this);
  79. g.drawString ("Incorrect answer! ",250,60);
  80. sound2.play();
  81. sound1.stop();
  82. }
  83.  
  84. if (choice == 4){
  85. g.drawImage(image4,200,70,100,150,this);
  86. g.drawString ("Incorrect answer!",250,60);
  87. sound2.play();
  88. sound1.stop();
  89. }
  90.  
  91. if (choice == 5){
  92. g.drawString("go to next question",250,60);
  93. }
  94. }
  95.  
  96. public void actionPerformed(ActionEvent event) {
  97.  
  98. if (event.getSource () == beuts)
  99. choice=1;
  100. if (event.getSource () == boots) // if user presses a button,this method declares their choices//
  101. choice=2;
  102. if (event.getSource () == bootz)
  103. choice=3;
  104. if (event.getSource () == bots)
  105. choice=4;
  106. if (event.getSource () == next_q)
  107. choice=5;
  108.  
  109.  
  110.  
  111. repaint();
  112.  
  113.  
  114. }
  115.  
  116. }
I've tried using the repaint method to redraw the screen and wish to create a window with four new buttons, images and sounds for the next question. I will also shortly be adding arrays (which i know how to do) but how do i create a new window? Also tried WindowListener closing window method, got an error in Metrowerks Code Warrior 3.2 for Mac OS 9.2.1. Any suggestions?
Last edited by alc6379; Nov 1st, 2004 at 12:04 am. Reason: added [code] tags
Reply With Quote Quick reply to this message  
Join Date: Jul 2004
Posts: 1,749
Reputation: nanosani is an unknown quantity at this point 
Solved Threads: 55
Team Colleague
nanosani's Avatar
nanosani nanosani is offline Offline
Unauthenticated Liar

Re: Spelling Test using a button GUI environment..how do I create a brand new window?

 
0
  #2
Oct 31st, 2004
couldnt you make a new frame and just hide the one that called the new frame ??
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:


Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC