DaniWeb IT Discussion Community

DaniWeb IT Discussion Community (http://www.daniweb.com/forums/index.php)
-   Java (http://www.daniweb.com/forums/forum9.html)
-   -   Spelling Test using a button GUI environment..how do I create a brand new window? (http://www.daniweb.com/forums/thread13240.html)

chocobo74 Oct 31st, 2004 2:19 pm
Spelling Test using a button GUI environment..how do I create a brand new window?
 
This is my skeleton of my very basic computing project, which is to create a spelling test displaying twenty questions:

//
//  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();
                       
                       
  }
 
  }
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?

nanosani Oct 31st, 2004 9:45 pm
Re: Spelling Test using a button GUI environment..how do I create a brand new window?
 
couldnt you make a new frame and just hide the one that called the new frame ??


All times are GMT -4. The time now is 12:42 am.

Forum system based on vBulletin Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.
©2003 - 2009 DaniWeb® LLC