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;
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);
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:
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
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
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?
I'm making a game of checkers for my A2 Computing coursework which is due in within a week. I have completely finished the game, and only thing I have left to do is connect the two JPanels together via a CardLayout that I have made. However I am unsure how to do so
I have kept the code I am displaying to a minimal, hence I have removed all the action listeners for my buttons, anyway the problem I have is that, I would like it so that when the user clicks on the 'Multiplayer' button which is the array button ourButtons[1], it will then transition into my main game screen so that the user can then play a game of checkers.
Here is the main important GUI from my CheckerBoard class:
import java.awt.*; import java.awt.event.*; import javax.swing.*; public class CheckerBoard extends JPanel implements ActionListener, MouseListener { // Main routine that opens an Applet that shows a CheckerBoard public static void main(String[] args) { new CLayout();
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
I wrote a single player blackjack code and i want to play this game with multiplayers, which steps should i take to do this
package blackjack; import java.util.Random; import java.util.Scanner; public class Blackjack { public static void main(String[] args) { Random kagit=new Random ();
I am creating a hangman code. So the game i am creating is 2 player, first player enters the word and second player guesses. i made the code but i don't know how to restrict the first player from adding random characters into the secret word because for my project the word can only contain letters. so i need making the code so the player 1 can only enter letters.
My code is below:
/** * Auto Generated Java Class. */ import java.util.Scanner; public class Hangman { public static void main(String[] args) { Scanner input= new Scanner(System.in); String player1,player2; int wrongguessamount = 0; //keeps the count of the amount of wrong guesses int correctguessamount = 0; //keeps count of the amount of correct guesses int maxincorrect=6;//makes sure the user cant guess more than 6 times
I am a begMy task is to write a program that plays the "Hi Lo guessing game." The program runs smoothly. However, it does not proceed to the next game after the previous game is done. I need to add a "play again" choice to the program so that the user will continue to play until they have chosen to quit. I have tried several different ways but each one has failed. I am completely stuck on this. I have attached my code to this.
So, after my graphics card melted down, I decided to use a chat program because I can't play the game server which I am staff on. I've downloaded this:
CactusChat: MC 1.7.4 - 1.7.5 chat client for Windows, Mac and Linux Operating Systems | EcoCityCraft Economy | Minecraft Servers
After I knew it was a .jar file, it would basically fail, I would launch it, it turns into a cmd for 0.5 seconds, and closes without any progress. Typical, and expected.I downloaded the latest java update, removed 3 older versions, and now my Java SE Binary program went missing. I can't even launch it, and it tells me to look for another program to launch it with.
So I am trying to create a Multi-Player game in java, and I have a Game server and a Client. They normally connect with either but I would like to add a login server so that there can be an option to go to a different world then just the main one. It will have the same map and data but will be separate from the Players that are on world one per say. Now if you are on world two I would like it to have the option for you to be able to Private message players that are on World one. That is where the login server comes in to play.
I am still new at Java and would like to be able to understand Packets and how to handle them more clearly. So far I have gotten the basis of the login server connected to the server and the client connects to the server via the login server. But I am getting a bunch of "unhandled packets" and I would like to know how to handle them. Here are some bits of the code.
I am trying to design a monopoly board game with a class and a main program. I can not make the method to keep track of the player's position after every roll. After every roll it prints "Previous position: 0".The player should also not go over 14th spot because the board is just 15 including 0. That is what I have (just the particular method and the part from the main program which call it).
public int getpospl1() { System.out.println( getplayer1name() + " Rolls " + "Dice 1: " + getrolld1() + "" + "Dice 2: " + getrolld2() + "" ); int spot1 = 14; //The end spot int start = 0; int previousPosition = start;
class blackjack { public static void main ( String[] args ) { Random r = new Random(); Scanner keyboard = new Scanner(System.in); String money; String name;
[Code]...
I know people will want me to tidy it up, or do it "their" way, but honestly I just need method of getting the user to press h or s and have the program continue under it's own steam.
I am creating a roulette program that I converted from C++ to Java. Why its not finding the main class. Therefore it will not compile. Heres the code:
import java.util.Scanner; public class P1RouletteDB { // This program demonstrates the use use multiple arrays to play a roulette game. //Also a random number will generated to be used as the ball in the game. The user will be provided the random number to test the win algorithms // Program Set 2 Roulette Game
// Global constants public static final int COLS = 3; // Number of columns in each array
I have been working on this function and i can't get it to work. It's a little bit complicated so let me first explain what this is about:
1. As a little exam in my studies i have to program a halma console game with KI an stuff.
2. Everything is finished and works except for the Move-Calculation.
3. A Move is a Move from Field a to Field b which a player can perform in one round based on the game rules (Careful: We are not using the standard halma rules, we use different ones).
4. Class Move consists of the Starting Cell where the Figure before the Move stands and a target Cell where the figure will stay on at the Move end. It may include an Array of serveral Cells, the stop cells which the figure passes from start -> target since several jumps can be performed in one Move.
Valid Examples for Moves:
a -> b (From Field a to Field b) d -> f through g,h,i (From Field d to Field f through the Field g,h,i
My Move Calculation where all possible Moves are calculated for a given figure consists of 2 parts. An expand() function which will generate all possible moves (works perfectly) and a jumpFix() function which isn't working properly.
Example:
After expand() I'm getting something like that:
a -> b b -> c c -> d s -> t
This is however not finished, because the first 3 Moves are actually 1 Move. Because the player can Move from a -> d in one turn because those 3 are consecutive Move. The fixed Move would look like that:
a -> d through b,c
jumpFix() is also perfectly working for that situation, however there is one specific situation when it doesn't work. Let's say we have this situation.
a -> b b -> c c -> d b -> e e -> f f -> g s -> t
Then the only valid jumpFix() output would be:
a -> d through b,c a -> g through b,e,f s -> t
However i can not get it to work yet. Note: It definitely needs to be iterative, not rekursive else i would get an StackoverflowError.
This is my current Code of jumpFix():
Java Code:
/** * Takes a look into all calculated moves and finds those which should be seen as one move, but are still considered to be more than one move (several jumps in one move) */
public static List<Move> jumpFix(List<Move> moves) { Set<Move> result = new HashSet<Move>(); Set<Move> remove = new HashSet<Move>(); int lastSize = -1; // repeat action until no moves could be merged while (lastSize != remove.size()) {
[Code] ....
How to implement the special case where a Move splits into 2 or more branches and jumpFix() able to handle this case.
Its a basic program that is played by 2 people. Player one is suppose to type a number and the second player is suppose to guess the number. However after I test it out, and if I guess too low or too high I get stuck in "Your guess is too low, try again." infinite loop, what is wrong.
import java.io.*; class GuessingGame { public static void main (String[] args) throws IOException { BufferedReader stdin = new BufferedReader (new InputStreamReader (System.in)); String firstPlayer, secondPlayer; int firstInput, secondInput; int guessCount = 0;
Tank war game thats ran over a network and is multiplayer, however whenever I fire a bullet it shows on my screen but not the other player's screen. Here's the code:
I am currently making a 5 card stud game for my Java Programming class at my highschool. I am deciding to go a little above expectations and make my poker game a little more fun than just comparing a few cards. However I want there to be text that is changing on my screen, but the repaint() is not the most reliable way to make the screen update, I am wanting a way for have the program constantly update the screen so that if I do something like someLabel.setText("Text"); then the text will update automatically whenever it is changed.
Here is my declarations and main/constructor method
import javax.swing.*; import java.awt.*; import java.awt.event.*; import java.util.Random; public class FiveCard extends JFrame implements ActionListener {
[Code] .....
Here is the method addMainPage, which is called in the constructor. Whenever the enterButton is pressed, the actionListener directs it to loadBoard();
I use GridBag Layout, so to skip through all of the constraints
public void addMainPage() { for (int i = 0; i < 4; i++) { players[i] = new Player(); } Icon cardBackImage = new ImageIcon("back.gif");
[Code] .....
Game intro is a method that changes the text of a label every second using .setText(), however it does not work because the enterButton is pressed, then after loadBoard() and gameIntro() is ran, it repaints the frame with the board objects and the gameIntro's final .setText() command.The action listener is simple...
public void actionPerformed(ActionEvent e) { if (e.getSource() == enterButton) { players[0].setName(playerNameField.getText()); loadBoard(); } p.repaint(); }
Tank war game thats ran over a network and is multiplayer, however whenever I fire a bullet it shows on my screen but not the other player's screen. Here's a snippet of code form where i think the problem is coming from:
class Tank implements Ball { double locX, locY, radius, angle; int self; // index of this tank in WarPanel.tanks public boolean turnL, turnR, forth, back, fire; boolean prevtL, prevtR, prevfo; Color color;
This is code for a game I am making where you are a character at the bottom of the screen dodging falling rocks. I was wondering how to add in the falling rocks. I think I need to use Timer and an ArrayList but I am not sure if that would work and not truly sure how to go about doing it.
I've got a simple main routine that instantiates two structurally identical classes, and attempts to write them both out to System.out with an XMLEncoder:
package xmlencoding; import java.beans.XMLEncoder; public class Twice { public String name; public static void main(String[] args)
[code]....
I expected Line 16 and Line 24 to both write some XML-formatted output, looking very similar to each other. But here's my output:
Now, if I change Line 24 so that the second call to writeObject is to a different stream("23. XMLEncoder e2 = new XMLEncoder(System.err);"), I do get both outputs:
So, I am inferring that this means two XMLEncoder objects can't both hold references to the same OutputStream, even if the first object is closed before the second is created. In actual practice, I guess I can live with that, since I wouldn't write the XML-encoded version of two objects to the same stream (I'd get the header twice in the same file, and I believe that's a no-no). But I am surprised that this doesn't generate some kind of exception, either when the second XMLEncoder is constructed, or when its writeObject method is called. But, it just silently dies.
The problem I'm having is when the text box pops up and ask to start with a root name, I cannot enter anything and I am not sure what I have done wrong.
import javax.swing.*; import java.awt.*; import java.awt.event.*; import java.util.*; public class FamilyTreeDemo extends JFrame
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");