I am still playing around with decks of cards, and am now trying to implement some visualizations using Applets.
Here is how I enter my deck of cards into an array list: this works just fine:
String[] Suits = new String[]{"S","H","D","C"};
String[] Values = new String[]{"A","2","3","4","5","6","7","8","9","10","J","Q","K"};
ArrayList<String> deck = new ArrayList<String>();
for(String suit : Suits) {
for(String value : Values) {
deck.add(suit+"_"+value);
}
}
The end result of this is an array 'deck' which contains a string representing each of the 52 playing cards. Great.
Now I would also like to use some pictures for future implementations I am working on. I have 52 images (.png, though I doubt it matters) stored in the right place. They are named as "H_5.png", and "S_A.png", for example, just as I named the cards in the previous array. I would like to do something as follows
ArrayList<Image> deckpic = new ArrayList<Image>();
for(String suit : Suits) {
for(String value : Values) {
deckpic.add(getImage(suit+"_"+value+".png"));
}
}
Now of course this doesn't work. The line
suit+"_"+value+".png"
is a string, not the name of a file. How I have previously loaded images is to use something like this:
the_pic = getImage("picture_of_pony.jpg");
but of course I can't use the quotations in my card loop, since I want "suit" and "value" to range and not just be the strings suit and value.
What I'm trying to do is display an entire deck of cards in 4 hands, randomly shuffled. These will be displayed as images in a pane. The images are numbered 1-52(not using Jokers) so what I have done is created an array that contains those numbers. Then I am randomly shuffling that array. What I can't figure out how to do is display the images using the randomly shuffled numbers in the array to do it? Is this even possible or am I totally on the wrong track on how to do this? This seemed like the obvious way to go when I started. Showing images isn't a problem, it's showing them using the array's element to get the image name that I'm having trouble figuring out.
Exception in thread "main" java.lang.NullPointerException at javax.swing.ImageIcon.<init>(ImageIcon.java:205) at GUI.<init>(GUI.java:26) at Apples.main(Apples.java:7)
i think the problem is to do with my images not being recognised. I put them in my source in User>...>workspace>src which is correct as far as i know. From what i know the images should show up if i look at my src file in eclipse but they dont. I tried changing the file type from .png to .jpg but it makes no difference.
i am migrating my web application from Server1 (Tomcat 5 and Java 1.5) to Server2 (Tomcat 7 wand Java 1.6).
In my web application, I have multiple adapters (web clients) that are connecting to external web services, https interfaces, sftp servers etc.
In order to connect with all these external interfaces, i have installed multiple certificates in my JRE keystore on Server1.
Now since the application is going to be migrated to Server2, i need to know if there is any way I can import all the existing certificates from Server1 JRE to Server2 JRE?
Since the application has been running on Server1 for a long time, I am not sure, what exactly is a complete list of certificates that I need to install on my Server2 JRE.
So i am kind of looking how can i generate the keystore file with certificates from the existing server1 JRE and then import it into Server2 JRE.
Does this command provide a list of all the installed certificates on my Server1 JRE?
The other solution i can think of is to manually download/save all the certificates by opening all the URLs in the browser and then import the .pfx files through keytool into my Server2 JRE.
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'm making an import/export of xml - I have the import of xml sorted I'm just trying to finish off the export. My export class is called XmlWriter.java. Inside the class I have an updateFile method to update an xml file as such:
public void updateFile(Environment environment,Document doc) { // code }
I then in my main method have
public static void main(String argv[]){ //declare new object of class XmlWriter xmlWriter = new XmlWriter(); //test testUpdate method // xmlWriter.testUpdate(); Environment environment = ;
[code]....
I don't know what to make my variables equal to - eclipse keeps trying to use null but obviously that won't work. The Environment is another class that just contains getters and setters for the 3 different databases (that are in the xml file) and the getter/setter for the environment ID (also in xml file).
Often times i don't remember which package a specific class (like ArrayList) belongs to. Is there an easy way to find that java.util.* is what i need to import, if i wanted to use the class ArrayList ?
I have imported several maven projects but I am trying to import a spring project via eclipse and it is not displaying. I did the following file->import->Existing maven projects->browse (found my project)->finish..... The project does not display and I cannot find it. I tired to do it again and the project cannot import because I cannot select it meaning it is already installed.
This code doesn't recognise the package ( and therefore class ) timetest3, when I try to import it. The package I try to reference/call, follows, and works fine.
import javax.swing.JOptionPane; import timetest3.TimeTest3; public class timetest4 { public static void main(String args[]) { TimeTest3 time = new TimeTest3(); time.setTime(13,45,52);
I have written a library in one project but cannot seem import to import it into my main project whenever I try Maven says it cant find it though it is installed in the repository and the .jar file is in the classpath.
Stack trace org.jclarion.clarion.lang.ClarionCompileError: Class Not Found:com.MyProj.app.MyClass near line:310 (selma012.clw) at org.jclarion.clarion.lang.Lexer.error(Lexer.java:190) at org.jclarion.clarion.compile.grammar.AbstractParser.error(AbstractParser.java:111) at org.jclarion.clarion.compile.grammar.AbstractParser.importJava(AbstractParser.java:463) at org.jclarion.clarion.compile.grammar.AbstractParser.emptyLex(AbstractParser.java:258)
I am trying to write a program, which includes an import data option. This option is used to import information from a text file.
The data is read from the file and objects are created and added to the student's record (The text file contains some information of the courses that the student is taking).
So my question is, how do i import information from a text file ?
and after they are imported, how do i create the objects in order to add them to the student's record ?
I'm getting errors on all the exceptions called EmptyCollectionException. I think this is because the import statement has a error on it but I'm not sure. I'm suppose to add methods for peek, isEmpty, size, and toString methods. I only started isEmpty also am wondering what I have to change from peek method if anything at all.
import jsjf.exceptions.*;//Error on jsjf import java.util.Arrays; public class ArrayStack<T> implements StackADT <T> { //Error on StackADT private final static int DEFAULT_CAPACITY = 100; private int top; private T[] stack;
So im trying to make a coin flip game in java. Im relatively new to the language and the only other language i knew was javascript so im still learning. Ive already made one before using just one class and putting all the code inside, but im now trying to do it with methods since im trying to learn them. The basic idea of the game is that the user picks how many coins they'd like to flip, they pick heads or tails, then the computer flips the coins and calculates if there was more heads or tails to tell the user if they won or not. Im not quite complete with the program as you can see but ive already run itno an error. I was just doing some tests on the code i already have and i found that when i call the method settingUpCoin in my main class the program terminates. So basically, when i run it, it executes userImp right, transform right, but then it dosent let you enter a value for howManyCoins and terminates before you get to settingUpCoin.
(Notes: this was all done in eclipse luna build or the java ide. The class files are all separate in the actual thing i just put them together here to demonstrate my code.
import java.io.IOException; public class Coin { double myCoin; int numOfCoins; int counter; double arrayOfCoins[] = { };
I have a small issue with my code where im encrypting and decrypting messages.
My import org.apache.commons.codec.binary.Base64;. does not work.
It says binary does not exist_ Why this happens?. I've downloaded the codec but im starting to wonder if it has to do with where the codec folder is located, but i may be wrong.
I have a library that I'm writing, the library contains a spring xml configuration file (lets say it's called libraryContext.xml) that sets the library up correctly for runtime, it also includes a test spring xml file that sets the library up for test by importing libraryContext.xml and overriding certain dependency injection beans (the library basically connects to a real database under normal conditions and uses dummy DAO's under test conditions). That bit is all fine.
The thing is, when I build the jar for the library (lets say it's called library-0.1.jar), the jar does not seem to contain the libraryContext.xml and that means that I can't import library.xml into my applications context.xml.
Basically, I have this line in my applications context.xml
Unsurprisingly, since the xml file is not contained in the library-0.1.jar, the error I get is,
Java Code:
Offending resource: class path resource [applicationContext.xml]; nested exception is org.springframework.beans.factory.BeanDefinitionStoreException: IOException parsing XML document from class path resource [libraryContext.xml]; nested exception is java.io.FileNotFoundException: class path resource [libraryContext.xml] cannot be opened because it does not exist mh_sh_highlight_all('java');
With respect to potential solutions to the above problem, I could:
1) physically copy the libraryContext.xml file (and its other *.xml and *.properties dependencies) into the application, but then I'd have to maintain duplicate files - I don't like this option.
2) find out if there is a better way to handle this problem from people who know better. E.g. is there a way to embed the libraryContext.xml file (and it's dependencies) into the jar file so that it can then be imported into the application. I've spent a while on google trying to figure this out and haven't come up with anything overly useful (perhaps I've been using the wrong search parameters).
I am puzzled by a note in the book I am reading (by Mala Gupta). Page 55 says "All java components you've heard of can be defined within a java class: import and package statements, variables.....". But the online oracle doc (tutorial) clearly says the following 2 statments:
"If present, package statement must be the very first line in a file"
"To import a specific member into the current file, put an import statement at the beginning of the file before any type definitions but after the package statement, if there is one. " (Here).
So, how can import and package be present inside a class ? (This seems to go against the 2 statements from oracle online tutorial).
I would like to build a GUI where by I can import a text file and interrogate certain values and then display them in a window. Thing is I would like to know what window type that will support this. i.e Panel,internal frame,dialog box.. etc etc... I am using Netbeans.
I was wondering how Java knows where to Import classes from when we don't specify the whole directory path.
For example: import java.util.* Does It automatically search In both your current directory and the directory created during Installation that contains the standard library (wherever It may have been Installed) ?