Applets :: Accessing External Resources - Play Particular Sound Whenever Button Is Pressed

May 4, 2014

I am quite new to developing Applets in java. I recently made an applet that will play a particular sound whenever a button is pressed. The sound files are placed in the same directory as the applet class file and i access them by using

AudioClip clip=getAudioClip(getCodeBase(),"A.wav").

The Applet runs fine in the appletviewer but whenever I try to open it using any browser like Chrome,IE,Firefox the applet loads but sound isn't played. I checked the java console and it showed

"java.security.AccessControlException: access denied ".

My questions are:

1. How do I allow the applet to get access to those files?

2. When the Applet is running from the local file system why CAN NOT I access those resources via getCodeBase() ???

3. I googled and found that I can sign a JAR and that can have full access to the computer. But how do I create a JAR from an applet (which has no Main method) while it asks me to point to the main class in the manifest?

View Replies


ADVERTISEMENT

Play A Sound When Button Is Clicked?

Mar 20, 2014

im trying to play a sound when button is clicked. here is the following code

InputStream in;
try {
in = new FileInputStream(new File("failure1.wav"));
AudioStream audios = new AudioStream(in);
AudioPlayer.player.start(audios);
} catch (Exception e) {
}

just wondering why it does load;

i do get the warning

warning: AudioStream is internal proprietary API and may be removed in a future release
AudioStream audios = new AudioStream(in);
warning: AudioStream is internal proprietary API and may be removed in a future release
AudioStream audios = new AudioStream(in);
warning: AudioPlayer is internal proprietary API and may be removed in a future release
AudioPlayer.player.start(audios);

View Replies View Related

Packaging And Accessing Resources In JAR

Jan 26, 2015

I'm working on an application and I would like to package my resources (icons, about dialog images, splash screen images, release version text, etc.) in the jar file I'm going to distribute for deployment.  I would like to access these resources from the JAR file in my deployed code.  But I would also like them accessible when I'm running the code in my Eclipse IDE.  Is there a way to do this using only one code base?
 
My Eclipse project structure is src (folder) which contains my source code, bin (folder) which contains my class files and res (folder) which contains my resource files.
 
I am using the javapackager utility to create my deployment JAR and build a self-contained deployment .exe for deploying to Windows.
 
Is there a way to have the javapackager build a single JAR file from multiple sources (i.e. my bin and res folders)?  What do I have to do in my code so that the same code can be used to load resources when I'm running in Eclipse and the self-contained deployment?

View Replies View Related

Applets :: Having Access To Local Resources

Jan 31, 2014

how I can configure an applet to get access to local resources such as file system, browser, etc.

View Replies View Related

Play Pause Sound In Java?

Jan 15, 2015

What I want to do is very clear, just play sound and pause it. The problem is that I can't pause the music. When I click the pause button music keeps playing .I have been working on for 2 hours. I can't find the mistake; what am I doing wrong?

public class MainC extends JFrame implements Runnable,ActionListener {
private JPanel contentPane;
private JTextField txtname;
JButton btnopen;
JButton btnSave;
JButton btnplay;

[code]....

View Replies View Related

Sound Clip Using Mediatools Class Will Not Play

Oct 5, 2014

I wrote the below program to set up and play the game breakout as an assignment for Stanford's CS106 programming class. I wrote it on my old mac running OSX 10.6.8, with the version of Eclipse JDK that works on that machine. When I tested it back on the mac, the program worked normally. But now I am using a Windows 8.1 computer with the corresponding version of eclipse, and when I test the program again, the sound effect I coded does not play. I get the following error message in console when the ball hits the paddle or brick, which previously caused the sound clip to play.

Exception in thread "Thread-4" java.lang.IllegalArgumentException: Requested value -120.0 smaller than allowable minimum value -80.0.
at javax.sound.sampled.FloatControl.setValue(Unknown Source)
at com.sun.media.sound.DirectAudioDevice$DirectDL$Gain.setValue(Unknown Source)
at acm.util.SoundPlayer.setLineVolume(SoundClip.java:909)
at acm.util.SoundPlayer.run(SoundClip.java:860)
at java.lang.Thread.run(Unknown Source)

why my code would request a value below the min. I am using the mediatools class that is part of the ACM libraries we are required to use for the class to play the sound in question, found here: URL....I went ahead and tested all parts of the program and the missing sound effect is the only problem. Here is my complete code:

package Breakout_package;

import acm.graphics.*;
import acm.program.*;
import acm.util.*;
import java.applet.*;
import java.awt.*;
import java.awt.event.*;

[code]....

View Replies View Related

Sound Won't Play When Player Dies And A Game Over Screen Pops Up

Jan 14, 2014

I am making a game with java in a program called greenfoot.My problem is that a sound won't play when the player dies and a Game Over screen pops up..

- I have saved the audio file in my sound map of the scenario
- Applied the good name of the file
- tested the sound effect and it's working

this is my code:

public GameOver()
{
setImage(new GreenfootImage("GAME OVER", 100, Color.BLACK, null));
Greenfoot.playSound("fail-trombone-03.wav");
Greenfoot.stop();
}

View Replies View Related

Applets :: Accessing HTML Through DOM

May 14, 2014

I do not think this is possible, but I'd like to confirm. If I have an HTML page that has an embedded Java applet, and that applet in turn renders an HTML document (within the applet window), is the HTML *within* the applet part of / accessible through the DOM for the parent page?

View Replies View Related

How To Get JList To Update When Refresh Button Pressed

Mar 15, 2015

I am able to update the array holding the items but I don't know how to refresh the JList to include all the new items in the array.

Code for GUI:

import java.awt.ScrollPane;
import java.awt.event.ActionListener;
import javax.swing.*;
public class ListView extends JFrame{
HobbyList stuff = new HobbyList();

[Code] .....

View Replies View Related

Change Text In JLabel When Button Pressed

Dec 4, 2014

Ok, so I am trying to learn about JFrames and JPanels. I have figured out buttons, layouts, etc. What im having trouble with is accessing the label object from the ButtonHandler class since it is static and I need my JLabel to be non-static so that it can change. Basically, I want JLabel to change to a pre-determined text string once a button is pressed. Here's what I have so far

package makewindow;
import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;

[code]....

View Replies View Related

JavaFX 2.0 :: Keep Last Button Pressed With Custom Style

Dec 27, 2014

I have a VBox with 20 buttons and I have this style applied (menu.css) (only for VBox wrapper):
 
.button:focused {
    -fx-background-color: #0768A9;
    -fx-text-fill: #FFFFFF;
}

But when I pressed other button outside the VBox the style disappears, because the other button get the focus.

How I can do to keep the last button pressed with a custom style? (Only for buttons containing the VBox).

View Replies View Related

Classing White Space As Invalid Name When Close Button Is Pressed

Oct 29, 2014

I have a filechooser that works how it should and if anyone enters anything with a dot that isnt .xml it shows an invalid file name message. However when I dont choose a file and press cancel it still says that because when my boolean hits false it's the first thing it hits in that section of code.

if(!writeSuccess)
{
//display output messages in JOptionPane
JOptionPane.showMessageDialog(null,"Error, file name invalid", "Error", JOptionPane.ERROR_MESSAGE);
} else {
JOptionPane.showMessageDialog(null,"Export successful", "Success", JOptionPane.INFORMATION_MESSAGE);
//close the form
me.dispose();
}

If I want it to just close down without it saying anything is there sort of if statement I could do that would prevent this? But if it is an invalid file name it will still show that message?

View Replies View Related

Create A Simple GUI With One Button That Just Says Play

Feb 25, 2014

I am new to Java, I am using Netbeans to create a simple GUI with one button that just says "play". I want this to play an mp3 file i specify. I have found code to simply play a WAV which works great.There is lots of information on the net about playing an mp3 but it's all long an complicated. There must be a simple way to just have java play an mp3 file.

View Replies View Related

Applets :: Accessing Java Application Without Adding Site To Java Security

Sep 12, 2014

I have tried running the java application without adding the site to site list in java security tab. But I get a sand box message as APPLICATION BLOCKED BY SECURITY SETTINGS. How to run the java application without adding the site to site list in java security tab.

View Replies View Related

Loading JPanel From Another JPanel When Button Is Pressed

Jun 9, 2014

I am making a game in java and i want to make a title screen. What I am trying to do is make a jpanel and load another jpanel when a button is pressed in one of the japenls. Here is the code for the runner

import java.awt.BorderLayout;
import javax.swing.JFrame;
public class Runner extends JFrame {
// Have these set up so they can be seen everywhere
public static final int GAMEWIDTH = 540;
public static final int GAMEHEIGHT = 710;
static boolean loading = false;

[Code] ....

here is the code for the jpanel that loads the other jpanel

import java.awt.Color;
import java.awt.FlowLayout;
import java.awt.Graphics;
import java.awt.Graphics2D;
import java.awt.Image;
import java.awt.Rectangle;

[Code] ...

How do load a jpanel when a button is pressed in another jpanel

View Replies View Related

Reading Properties File From Resources Folder

Jan 31, 2011

In my java app there is a code which reads the properties file from src/main/resources folder.

Java Code:

@Component("mailerProperties")
public class MailerProperties {
private static Properties properties;
public MailerProperties() {
properties = new Properties();

[Code] ....

Now I need to create a jar file and also remove the properties file from src/main/resources folder and place it outside the jar file(in the same location as jar file) so that data inside it can be changed easily in future.

Question: Currently it uses ClassPathResource("mailer.properties") to read the prop file. What change I need to make to read it from outside the jar file...

View Replies View Related

XLS Resources Not Loaded After Created Executable JAR For Project

Jun 18, 2014

I have one Project -"A".Inside of that I use, .XLS to read data.

Structure - A/src/TestData
Inside of the TesetData - I have placed XLS files.

I have main method in TestDriver class.If I run this in Eclipse, running fine.But after exported to executable/runnable Jar, and ran via command line (command - jar -jar myjar.jar), I see issue: "Exception in thread "main" java.io.FileNotFoundException: srcTestDataTestCaseController.xls"

public static void main(String[] args)
throws Exception
{
ResultSet rs;
rs = readExcelData(testControllerName, sheetName, "");
}

As I use main() method which is static, I am getting error if I write like the below:

public void getXls(){
String testControllerName ="TestCaseController.xls"
TestDriver.getClass().getClassLoader().getResource (testControllerName);
}

How to read/access the XLS, after I exported as runnable jar

View Replies View Related

JSF :: Null Pointer Exception While Creating File From Resources In Managed Bean Class

Feb 7, 2014

i want to list files from resources folder like this:

@ManagedBean
public class galley implements Serializable {
private List<String> list;
@PostConstruct
public void init() {
list = new ArrayList<String>();

[Code] ....

but it give me a null pointer exception on fList .... The directory of resources is :

How is this caused and how can I solve it?

View Replies View Related

Applets :: SecurityException When Using Applets

Dec 26, 2013

I am new to applets, and my manifest file is:

Manifest-Version: 1.0
Ant-Version: Apache Ant 1.8.3
Permissions: all-permissions
Created-By: 1.6.0-internal (Sun Microsystems Inc.)

Name: com/myPackage/test/client/TaskApplet.class
SHA1-Digest: pLmraui35IkgfAq+v3WGj1LwCYQ=

The error I get is as follows...When the page is loaded I get the following error: java.lang.SecurityException: class "com.myPackage. test.client. TaskApplet" does not match trust level of other classes in the same package

View Replies View Related

How To Loop A Sound

Sep 24, 2014

I created a game but want some music in it, and as I write in the title i want the sound to loop. This is the code fore the sound class i have:

Java Code:

import java.applet.Applet;
import java.applet.AudioClip;
public class Sound {
private AudioClip clip;
//all sounds
public static final Sound ScoreSound = new Sound("/Score.wav");
public static final Sound BounceSound = new Sound("/Bounce.wav");

[code].....

View Replies View Related

How To Get Sound To Import It To Game

Apr 7, 2015

how to make a simple game. I am having trouble when it comes to adding sound though. It tells me to do this:

package net.game.Game;
 
import java.applet.Applet;
import java.applet.AudioClip;
 public class Sound {
public static final AudioClip BALL = Applet.newAudioClip(Sound.class.getResource("ball.wav"));
public static final AudioClip GAMEOVER = Applet.newAudioClip(Sound.class.getResource("gameover.wav"));
public static final AudioClip BACK = Applet.newAudioClip(Sound.class.getResource("back.wav"));
}

What this does is it gets the sound file then gives it a name(BALL=ball.wav GAMEOVER=gameover.wav ect..) and then there is other code in other classes that call the sound so it will run but it keeps giving me an error and I don't know what to do. How can I get it to import the sound? Here is the error.

PHP Code:

Exception in thread "main" java.lang.ExceptionInInitializerError
    at net.game.Game.stuff.<init>(stuff.java:35)
    at net.game.Game.stuff.main(stuff.java:62)
Caused by: java.lang.NullPointerException
    at sun.applet.AppletAudioClip.<init>(Unknown Source)
    at java.applet.Applet.newAudioClip(Unknown Source)
    at net.game.Game.Sound.<clinit>(Sound.java:7)
    ... 2 more 

View Replies View Related

Speed Of Sound Program

Feb 11, 2015

I have to write a program that asks the user to enter "air", "water", or "steel", and the distance that a sound wave will travel in the medium. The program should then display the amount of time it will take. The amount of time it takes sound to travel in air can be calculated as follows;

Time = Distance/1,100

The amount of time it takes sound to travel in water can be calculated with the following formula:

Time=Distance/4,900

The amount of time it takes sound to travel in steel can be calculated with the following formula:

Time=Distance/16400

Here is my code:

import java.lang.String;
/**
This program displays numbers padded with leading zeros.
*/
 
public class SpeedofSound {
public static void main(String[] args) {
double D; // declares this as double
D = keyboard.nextDouble();
 const double A = 1100; // declares this as a constant

[Code] .....

The following is the error I'm getting:

----jGRASP exec: javac SpeedofSound.Java
error: Class names, 'SpeedofSound.Java', are only accepted if annotation processing is explicitly requested
1 error
----jGRASP wedge2: exit code for process is 1.
----jGRASP: operation complete.

View Replies View Related

How To Synthesize Simple Sound

Sep 15, 2014

Okay, so I'm looking for a way to synthesize sound, and from what I've found around the interwebs it seems amazingly complex. Is there really not a function like "sound(wavelength, time)"? Alternatively a way to use an integer array to determine the acoutstic pressure at a given time, or some other way to determine the pressure at a given time?

View Replies View Related

Speed Of Sound Java

Jul 27, 2014

I can't get the output to read correctly. I get 0 as the answer.

import java.util.Scanner;
public class TheSpeedofSound777
{

public static void main(String[] args)
{

System.out.println("Gordon Elam Sr July 26, 2014 ");

[code]...

View Replies View Related

How To Change Image When A Key Is Pressed

Aug 21, 2014

I am very much new to Java. I have just started learning event handling. Currently I am learning about Key Events. And am learning by doing. Well that is how one could learn anything in fact. I want to write a program in which the currently loaded image in the panel of a frame changes upon a key press say "Enter" or any other key.

View Replies View Related

How To Set Color When Space Is Pressed

Apr 11, 2014

The title says it all and i'm a fairly new java programmer but here is the code:

package TestVersion;
import java.awt.Color;
import java.awt.Graphics;

[Code]......

I think i need a variable or something oh and here is the 2 other classes, the keylistener one:

package TestVersion;
import java.awt.event.KeyEvent;
import java.awt.event.KeyListener;

[Code].....

View Replies View Related







Copyrights 2005-15 www.BigResource.com, All rights reserved