The Artima Developer Community
Sponsored Link •

Java Answers Forum
Some basic problems

8 replies on 1 page. Most recent reply: Nov 13, 2004 8:01 AM by Karen

Welcome Guest
  Sign In

Go back to the topic listing  Back to Topic List Click to reply to this topic  Reply to this Topic Click to search messages in this forum  Search Forum Click for a threaded view of the topic  Threaded View   
Previous Topic   Next Topic
Flat View: This topic has 8 replies on 1 page
Karen

Posts: 11
Nickname: karry1412
Registered: Nov, 2004

Some basic problems Posted: Nov 10, 2004 3:53 AM
Reply to this message Reply
Advertisement
Hi! I am working on a project & I am stuck on two of the smallest parts! I can't insert an image or a sound file. I know how to do both in Applets but not in Frames... Please help!!!


Also, when I click a button the desired text appears but when I click the next button more text appears over it. I tried repainting but it doesn't seem to work... Any ideas? Thanks!


Karen

Posts: 11
Nickname: karry1412
Registered: Nov, 2004

Re: Some basic problems Posted: Nov 10, 2004 9:20 AM
Reply to this message Reply
Also, if anyone knows how to make text appear on the next line it would be a great help (not by using \n!)

Karen

Posts: 11
Nickname: karry1412
Registered: Nov, 2004

Re: Some basic problems Posted: Nov 10, 2004 9:22 AM
Reply to this message Reply
I fixed the repainting thing...

Angsuman Chakraborty

Posts: 19816
Nickname: angsuman
Registered: Dec, 2003

Re: Some basic problems Posted: Nov 10, 2004 10:35 PM
Reply to this message Reply
Use createImage methods in Toolkit ( Toolkit.getDefaultToolkit() ) for image. Also java.awt.image package.


For sound use javax.sound.
There are other options for sound also.


Angsuman
http://blog.taragana.com/

Karen

Posts: 11
Nickname: karry1412
Registered: Nov, 2004

Re: Some basic problems Posted: Nov 11, 2004 9:46 AM
Reply to this message Reply
Thank you so much! The images are working perfectly know! :)

However, I am still having problems with the sound... I have 4 check boxes representing 4 bands. When you click a check box a song by that band should begin to play. Any ideas?

Angsuman Chakraborty

Posts: 19816
Nickname: angsuman
Registered: Dec, 2003

Re: Some basic problems Posted: Nov 11, 2004 11:29 AM
Reply to this message Reply
What is the mdeia type. In other words what is the file extension of the files you are trying to play?

Angsuman
http://blog.taragana.com/

Karen

Posts: 11
Nickname: karry1412
Registered: Nov, 2004

Re: Some basic problems Posted: Nov 12, 2004 4:18 AM
Reply to this message Reply
They are midi files. I am using midis that I know work 0 I used them before.

I have private AudioClip currentClip; declared up the top of the program * albumSound declared as a String.

In the actionPerformed I have soundname set to null. In the if statement (for if album button clicked) I have@

currentClip = createAudioClip(albumSound);
currentClip.play();

Then as a seperate method I have:

public AudioClip createAudioClip(String soundname)
{
// Get the URL for the file name

URL url = this.getClass().getResource("Sounds/" + soundname);

currentClip = Applet.newAudioClip(url);

// Return the audio clip

return currentClip;
}

Do I have to import anything in particular that I might not have already imported in order to use midis? I think I already have everything I need.

The particular midi should be read in from the ConcreteProduct. I am using the Abstract Factory pattern.

Thank you so much for all your help!

Angsuman Chakraborty

Posts: 19816
Nickname: angsuman
Registered: Dec, 2003

Re: Some basic problems Posted: Nov 12, 2004 7:35 AM
Reply to this message Reply
Use javax.sound.midi.MidiSystem.

See the example I have provided for you in the form of a sample java application to play midi file - http://blog.taragana.com/index.php?p=76.

Karen

Posts: 11
Nickname: karry1412
Registered: Nov, 2004

Re: Some basic problems Posted: Nov 13, 2004 8:01 AM
Reply to this message Reply
Thanks very much! I finally got it working. Turns out I had a line of code commented out that I needed - the one to actually play the sound when the button was clicked... Typical! Thanks again! :)

Flat View: This topic has 8 replies on 1 page
Topic: How to widen the drop-down list in a JComboBox Previous Topic   Next Topic Topic: problem with parsing script tag through HTMLEditorKit

Sponsored Links



Google
  Web Artima.com   

Copyright © 1996-2019 Artima, Inc. All Rights Reserved. - Privacy Policy - Terms of Use