In my program I want to 2 images changed randomly regulations, but on frame appear only img4. What is wrong?
public class Yes extends JPanel {
Image img3 = new ImageIcon("Yes/Untitled3.png").getImage();
Image img4 = new ImageIcon("Yes/Untitled4.png").getImage();
Random rand = new Random();
int randomNum = rand.nextInt();
I created tableviewer ( jface ). All the columns are editable ( using EditingSupport )
I want to know when cell is changed and then to raise a flag in other column. meaning that you start to write any data in the cell. I know that I need to create event of key changed listener to the cells. ( or there is different way )
How I can have access to the cell ? where do I need to add the event
public class MyGridViewer extends TableViewer { public MyGridViewer (Composite parent) { super(parent, SWT.MULTI | SWT.H_SCROLL | SWT.V_SCROLL | SWT.FULL_SELECTION | SWT.BORDER); final Table table = this.getTable(); table.setHeaderVisible(true); table.setLinesVisible(true);
I'm looking to figure out if it's possible to do the following:
HttpSession session = request.getSession(); session.setAttribute('name', 'Jane_Doe'); // more code here session.setAttribute('name', 'John_Doe');
Obviously, you can use the HttpSessionAttributeListener to determine which attribute has changed. However, it doesn't return the new value but rather the old one.
You can use the HttpSessionEvent listener to determine when a session object has been changed.
Is there a way you can determine when a session object changes (and it does NOT occur when the setAttribute method is called...) and determine the updated key:value pair?
I'm working on Java-GUI implementation in Ubuntu. Used font-type in the application throughout is "Arial". At earlier stage of application it was the same font-type("Arial"). As the implementation grew the font-type has been changed automatically to another font type. It seems Serif-font type.
Now I could not able to figure out the problem; why it is so.
Note- I used HTML code also for setting font style of Dialog box messages and buttons. This is the only point which I figured out. Can it is ?
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 having an issue with using FileWriter to print some text to a text file. In the following code, I am supposed to be able to print the initial attributes and the user changed inputs into a file but all I am getting is the memory locations of the objects I created in one long line.
package project3final; import java.io.*; import java.util.*; public class Project3Final { static class Instrument { char [] stringNames = {'E', 'A', 'D', 'G', 'B', 'E'}; private final String instrumentName;
"which code is best for randomly generating integer 0 or 1". Haven't gotten my grade back yet but in reading these during the test I didn't think any of these would kick out both of those numbers, but there was no "none of the above" option on the test.This is exactly how it appeared on the test:
A) (int)Math.random() + 1 B) (int)(Math.random() + 0.2) C) (int)Math.random() D) (int)(Math.random() + 0.8) E) (int)(Math.random() + 0.5)
I've tried all of them in the cs lab 100 times each and none of them generated both numbers. 'A' kicked out 1 every time. 'B,D and E' kicked out 0.2, 0.8 and 0.5 respectively each time, and 'C' kicked out 0. Did I just not run them enough times for the result to change or am I right in thinking there's a glitch on the test?
i'm trying to make a random card shuffler but the output would sometimes have same value multiple times. For example it might print out A5 at the fifth index then print out A5 again as the 32 index.
So I an assignment in Java to write a code which will randomly populate squares in a Tic Tac Toe Board. I pretty much have it I think, but I cannot get the 'O' to appear on the board, some squares will be blank. We were told to use the Random utility to generate the squares. I am attaching the .gif's which are used. Here is my code:
import javax.swing.*; import java.awt.*; import java.util.Random; public class LandryTicTacToe extends JFrame { /** * */ private static final long serialVersionUID = -8781512780135301721L; private final int HEIGHT = 450;//Set value for Height private final int WIDTH = 500;//Set value for Width private static JButton [] button = new JButton[9];//Declare array of Buttons
Display a frame that contains nine labels, arranged like a Tic Tac Toe board. A label may display an image icon for X, an image icon for O, or nothing. Display images randomly in each label. Use the Random class to generate 0, 1, or 2, which corresponds to displaying an X image, an O image, or nothing.
I need to make a string filled with naughts and crosses like this one : "xxx ooo xox". There are 3 groups separated with a space. how to fill the string randomly ?
I want to create a program that takes n number of people (String vector) and assigns them a random group number (int) the range from 1 to k. The number n is evenly divided by k.
I have created a program that associates every String with a random int number. There is however the problem that the random generator just gives a random number, but doesn't make an equal number of people for each group. Which means even if the numbers are random, some of the numbers happen to come up more times than others.
How can I write, to make sure that each number is generated the same amount of times?
I am making a game and i am trying to have enemies spawn slight off the screen and randomly each time the game is run. I can get them to spawn randomly but i cant seem to get them off the screen properly ( when i do they take too long to enter the screen). here is the code
for(int b = 0; b < GamePanel.enemy_amount; b++){ GamePanel.enemy.add(new Enemy((int)(Math.random() * 4000),(int)(Math.random() * 200))); }
I am trying to program a slot machine and as of now, I am trying to make my slots spin and randomly stop on one of the graphics. Right now, I am having difficultly making the animation/slot stop randomly.
Previously, I tried using a randomly set timer that would cancel the execution, but the image did not appear/stop on the screen.Right now, I am using a random generator and a while to say that if it is a certain number, then stop the image.Here's what I tried:
I must fill a 2d array randomly and then apply methods to the array. However i keep getting an out of bounds exception no matter what dimensions i use. I have a test and a class program.
import java.util.*; import java.lang.Math; import java.util.Arrays; import java.util.Random; class SummerStats { Random rand = new Random();
I have the code and it works very well, but my professor wants us to use Junit testing to test our code. I've never used JUnit before, how it works. Is it possible to have a boolean value (true or false) randomly set?
Here is the code I need to test:
package musicalinstruments; class MusicalInstrument { public String name; public boolean isPlaying; public boolean isTuned; public MusicalInstrument(){ isPlaying = false; isTuned = false;
i am trying to print out a randomly generated array, but i only get
[I@7852e922
i did some research and the "[" is for arrays, "I" is for the int and "@" is the hash. and the rest is some sort of hex. I need to override this in a way, but i can't seem to find out how. this is my current code:
import java.util.Random;
public class Oppgave { public static void main(String[] args){ int myint[] = fyll(); System.out.println(myint); } public static int[] fyll() {
I need figuring this problem out. It appears that I am attempting to generate a permutation of the string "ABCDEF" 720,000 times using this method:
In the second method, j is chosen randomly in the range from 0 to i (inclusive).
Once the permutations are generated, the program will proceed in counting the number of times each permutation occurs, calculating the chi square statistic of the situation, and creating the chi square distribution with 719 degrees of freedom, then outputting the statistic and the chi square probability of the permutations. The generatePermutation method is where all the magic happens. Only trouble, I can't figure out what I equals to. The times where I think I have i as a correct value only give me the program outputted as 1.0 probability every time. What it needs to be doing is outputting variable probability as a number always between 0 and 1, not 1 all the time. Here is my code:
Dice are used in many games. One die can be thrown to randomly show a value from 1 through 6.
Design a Die class that can hold an integer data field for a value (from1 to 6).
Include a constructor that randomly assigns a value to a die object. Appendix D contains information on generating randomnumbers. To fully understand the process, you must learn more about Java classes and methods. However, for now, you can copy the following statement to generate a random number between 1 and 6 and assign it to a variable. Using this statement assumes you have assigned appropriate values to the static constants.
Also include a method in the class to return a die's value. Save the class as
Die.java.
Write an application that randomly "throws" two dice and displays their values. After you read the chapter Making Decisions, you will be able to have the game determine the higher die. For now, just observe how the values change as you execute the program multiple times. Save the application as TwoDice.java.
I'm trying to build a monopoly like game, and atm I'm trying to find way how to build the Community and Chance chest cards. so far, my logic is
1-create an ArrayList of cards with a given order
2-for a given number of times(for loop) generate 2 random numbers ,which will be the parameters for Collection.swap().
3-swap.
here's the code for the shuffler Button
shuffler.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { for(int i=0;i<shuffeledMessages.length;i++){ int randoma=(int)(Math.random()*4); int randomb=(int)(Math.random()*4); Collections.swap(myMessages,randoma,randomb); } } });
For now things seem to work pretty ok, but I'm wondering if this is a good and efficient way to shuffle a card chest especially in case of large number of cards. plus, I'm not sure what would be a good loop count for effective shuffling, in my case I used i<arraylist.size
How would I randomly assign colors and a with a name? Some functionality may require command-line arguments but I am a bit confused on how to structure this. Also, these names must appear on a color coded on a gui
I'm trying to generate a random word from the array that I have made including the words by making it corresponding with a randomly generated number. So for example, if the number generated is 0, then the word that the person has to guess would be "AUNT". How would I transfer the randomly generated number from one method into the array method to get the word the person has to guess?
Write a program called Word Guessing Game. Open the file FourLetterWords.txt and write the contents into an array of Strings (the file has 87 words in it). Then use a randomly generated number between 0 and 86 to select a word. The player will then try to guess the word selected by the game. The player is allowed 7 tries, if the player does not guess the word on the 7th try he/she losses. Display the letter of the word as they are guessed in the correct order, you will also display the incorrect letters. The game is over when:
- The player completes the word, or guesses the whole word correctly. - The player does not guess the word in seven tries. The player must also be allowed to terminate the game. The game must have at least 5 classes: - Main Class - Class to return a random integer between 0 and 86. - Class to return a populated array of 87, 4 letter words. - Class to return a character that the player enters from the keyboard. - Class to display both the correctly guessed letters and the incorrect letters.
My code (it is not complete, my attempt to do what I am trying to do is obviously not working.)
import java.util.Scanner; public class WordGuessingGame { public static void main(String[] args) { final int NUMBER_OF_WORDS = 87; RandomWordGenerator.random(NUMBER_OF_WORDS);
For some reason, when I test out my code, my randomly generated numbers don't appear. Here is a sample result:
> What do you want to generate, integer, double, or character?
>integer
>What is the upper limit and lower limit of the integers you want to generate?
>1
>10
>How many integers do you want to generate?
>10
>BUILD SUCCESSFUL (total time: 9 seconds)
Is this because my code is not passing my parameters correctly? I'm not sure how to fix this either.
Here is my code for reference (it's not completed at the moment)
import java.util.Scanner; public class NewNumberCharacter { /** Main method * @param args */ public static void main(String[] args) { int return_int; double return_double;