| | |
Spelling Test using a button GUI environment..how do I create a brand new window?
![]() |
•
•
Join Date: Oct 2004
Posts: 1
Reputation:
Solved Threads: 0
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:
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?
Java Syntax (Toggle Plain Text)
// // spell_test.java // spell_test // // Created by chocobo74 on 21/09/2004. // Copyright (c) 2004 __MyCompanyName__. All rights reserved. // A simple Java applet // import java.awt.*; import java.awt.event.*; import java.applet.*; public class TrivialApplet extends Applet implements ActionListener { private Button beuts, boots, bootz, bots, next_q; private Image image1, image2, image3, image4, image5; private AudioClip sound1, sound2; private int choice; public void init () { Label title1; title1= new Label ("How do you spell a pair of rather large shoes?"); add(title1); image1=getImage (getDocumentBase(), "beuts.jpg"); beuts = new Button ("beuts"); add(beuts); beuts.addActionListener(this); image2=getImage (getDocumentBase(), "boots.jpg"); boots = new Button ("boots"); add(boots); boots.addActionListener(this); image3=getImage (getDocumentBase(), "bootz.jpg"); bootz= new Button ("bootz"); add(bootz); bootz .addActionListener(this); image4=getImage (getDocumentBase(), "bots.jpg"); bots= new Button ("bots"); add(bots); bots.addActionListener(this); next_q = new Button ("Next Question"); add(next_q); next_q.addActionListener(this); image5=getImage (getDocumentBase(), "these.jpg"); sound1=getAudioClip(getDocumentBase(),"spam_song.au"); sound2=getAudioClip(getDocumentBase(),"doh.au"); //these declare the buttons, images and sounds to be used// } public void paint (Graphics g) { g.drawImage(image5,0,10,100,150,this); if (choice == 1){ //this method declares what will happen when the user chooses a button// g.drawImage(image1,200,70,100,150,this); g.drawString ("Incorrect answer!",250,60); sound2.play(); sound1.stop(); } if (choice == 2){ g.drawImage(image2,200,70,100,150,this); g.drawString ("Correct answer!",250,60); sound1.play(); sound2.stop(); } if (choice == 3){ g.drawImage(image3,200,70,100,150,this); g.drawString ("Incorrect answer! ",250,60); sound2.play(); sound1.stop(); } if (choice == 4){ g.drawImage(image4,200,70,100,150,this); g.drawString ("Incorrect answer!",250,60); sound2.play(); sound1.stop(); } if (choice == 5){ g.drawString("go to next question",250,60); } } public void actionPerformed(ActionEvent event) { if (event.getSource () == beuts) choice=1; if (event.getSource () == boots) // if user presses a button,this method declares their choices// choice=2; if (event.getSource () == bootz) choice=3; if (event.getSource () == bots) choice=4; if (event.getSource () == next_q) choice=5; repaint(); } }
Last edited by alc6379; Nov 1st, 2004 at 12:04 am. Reason: added [code] tags
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 ??
![]() |
Similar Threads
- Python GUI Programming (Python)
- i want output in a window (Python)
- How to create a pop-up window in VB.net (VB.NET)
- test after button clicked (PHP)
- Gui, Visual Studio 05, Loop + Events + Stuck (C++)
- Open folder by clicking a command button from VB GUI (Visual Basic 4 / 5 / 6)
- GUI Window - Exit Button? (Java)
Other Threads in the Java Forum
- Previous Thread: Cannot utilize an array properly
- Next Thread: Would like for someone to check this to see if works and any help if it does not
| Thread Tools | Search this Thread |
addball addressbook android applet application apps array automation awt bidirectional binary birt bluetooth businessintelligence busy_handler(null) button card class classes client code collision columns component constructor crashcourse css database designadrawingapplicationusingjavajslider draw eclipse ee error eventlistener exception expand fractal free game givemetehcodez graphics gui guidancer html ide image integration intellij j2me java javaarraylist javadoc javafx javamicroeditionuseofmotionsensor javaprojects jme jni jpanel jtree julia jvm linux loan loop method migrate mobile mobiledevelopmentcreatejar myaggfun netbeans newbie oracle phone physics plazmic print problem program project radio scanner server service set sharepoint smart sms smsspam software sql subclass support swing textfield threads tree trolltech unlimited utility windows






