im trying to make a gui im trying to add a new jbutton for every empty cell in the array, and for some reason its giving me array index out of bounds error, this is what i have, im trying to to do it in an 80 by 80 array.
public JButton[][] buttons = new JButton[80][80];
public void addButtons(){
for(int i=0;i<buttons.length;i++){
for(int j=0;i<buttons[i].length;j++){
buttons[i][j]= new JButton();
}
}
How do i parse a String of text in a JTable Cell to work as a button?For example lets say a row of IDs such as 1,2,3,4,5,6 id like the whole column to parse as JButtons that are titled 1,2,3,4,5,6..Id like to then use these buttons to call a function with the title as a parameter.Its just a simple row of entries where the button will open up an edit screen to edit the corresponding clicked entry.So how do i parse them as buttons for a start?
I am trying to create an array filled with the object Card. It keep throwing the exception that the "deck is empty". I am not sure why that's happening because the code for filling the array seems fine.
public class Deck { private Card[] deck; private CardPile cardPile; private int numCards; public Deck() throws InvalidDataException{ this.deck = new Card[52];
I am trying to create an empty array that has no assigned length as the amount of elements it needs to hold will be dependent on another value. I then want to use a while loop to assign values to it. Here is an example of what im looking for it doesnt work. Iam trying to do:
int x = 12; int i = 1; int k = 0; int[] factors = {} while (i<x) { if (x%i==0) { factors[k] = i; k++; i++;
I am trying to do a simple noughts and crosses game. I have displayed a board using a 2 dimensional array and display it using a for loop. The array is of type int. What I want to do is allow the user to choose a specific cell within the array to change to an x or o but I am not sure how to go about doing this. I have seen lots of examples of noughts and crosses online but seem to all be examples of how to check a win or lose situation.how to allow a user to choose certain cells in a 2d array would be great.
I'm trying to set a variable to point to the last full cell of an array and then create a new larger array and then have the variable be updated to point to the new array's last full cell index value.
a) Should the variable be declared static? b) What would be the best initial value to set this variable to? Shouldn't it correspond to a <for> loop index rather than a solid integer?
private lastfullcell = a[i]; private int [] a;
c) How would you update <lastfullcell> because if you passed the index through a method's loop index isn't the array index value garbage collected after the method completes?
I am trying to have a Jbutton (blocker02) act like a wall that will not allow a moving Jbutton to pass through. I tried using " if (blocker02. getBounds (). intersects(r_wall)) but it hasn't been successful.
I have been creating a Java program to track inventory using an array. I need to add a search function to it to take a term, input through a text field, and locate a matching instance within the array. How can I code a JButton to grab test input from a JTextField and search for it within the array then display the corresponding information? I also need to add buttons to add and delete items as well.
I have a HashMap with multiple values at runtime. In that map one key has empty value , how to avoid this value to add in a list. some code sample is below:
public HashMap getLoop2Map(Map map, String xslFile , int sheetNo){ HashMap hashMap = new HashMap(); try{ ArrayList list = new ArrayList(); System.out.println("-------Map : " +map); list.add(map.values()); //System.out.println("------- boolean : " +val); System.out.println("------List : " +list); }
I do not want to add the empty value in a list ...
result in map
-------Map : {Free Text Entry={}, Mouth / Throat={Free Text Entry={Free Text Entry=<FORMFILENAME>EditChartPhysicalExamText.form </FORMFILENAME><TAG>"<MUSCULOSKELETAL.PE>"</TAG>}, Salivary Glands Condition={Salivary Glands Condition=MouthAttribute}, Examination Overview- Mouth / Throat={Examination Overview- Mouth / Throat=MouthAttribute}, Tonsils={Tonsils=MouthAttribute},
@ManagedBean @SessionScoped public class HelloBean { public void downloadFile() { File file = new File("C:datacontacts.doc"); HttpServletResponse response = (HttpServletResponse)
1) productType that have name and price of the productType and an empty consturcor. 2) superMarket that have name of supermarket and arraylist of productTypes (
private ArrayList<ProductType> products;
) and an empty constructor.
In each class I have function that get input from console and should store it into each class variables.
In productType i have function:
public void getFromUser() throws IOException { BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); System.out.println("Enter product name:"); name = br.readLine(); System.out.println("Enter price:"); price = Integer.parseInt(br.readLine());
[Code] ....
The main is something like:
public static void main(String[] args) throws IOException{ SuperMarket s1 = new SuperMarket(); SuperMarket s2 = new SuperMarket(); s1.getFromUser(); }
The problem is when i get to line "products.add(i,p)" I get java.lang.NullPointerException
In the debug mode I can see that when I get to this line the "products" is null.
why do you think this happening, when I do "new SuperMarker()" in the main it should run the empty constructor and create new arraylist...
I've been beavering away with Java for a few months. But as with all languages the String implementation looks designed to trip up even experienced programmers.
My current development gets data from various sources outside my control. When I get a string I want to test if it is empty/null/or whatever. Simple enough one thinks.
But if you search the internet you see everone seems to have a slightly different approach. So what is the best way of determining that a string is not useful to you?
I've had success with this
if(string == null || string.length() == 0)
But I've seen people using methods - not necessarily of String (e.g equals, empty) and regular expressions.
What is the best approach to this considering coding efficiency and/or processing efficiency (accepting you'd have to be processing a lot of strings for the latter to be an issue).
I'm writing basically my first program for school. I've written small ones, following instructions, but this is the most vague. I'm having issues. I can't figure out what the error means. I'm not done with the code, but I think the ArrayList is throwing me off. I'm trying to gather user input and sum the total. Here's the code:
package graduationplanner; import java.util.ArrayList; import java.util.Scanner; import java.lang.Double; public class GraduationPlanner { public static void main(String[] args) {
I am learning Java on my own, and I am creating little programs to do so.The program below asks the user to input text and hit enter. When user does that, it asks if that is correct. If the user enters "y," the program ends. That's good.If the users enters "n," the strGrategul is set to empty which triggers the while statement to start over again. That's good. However, when the program asks the user to "Tell me one thing you are grateful for..." it doesn't wait for user input. Instead it skips to "You said ''? Enter 'y' or 'n'" It thinks the user enter an empty line.
I am having issues with the program below everything works but I can't figure out a way to add code that if a user just hits enter without inputting anything it says "entering in nothing is not a valid choice" I am stuck on how to compare a int to a string ...
//import statements import java.util.*; //for scanner class // class beginning public class Guess { public static void main(String[] args ) { //Declare variables area
table.addKeyListener(new KeyListener() { public void keyPressed(KeyEvent e) { if (e.getKeyCode()==KeyEvent.VK_ENTER) { model.addRow(new Object[]{"", "","",""}); } } public void keyReleased(KeyEvent e) { } public void keyTyped(KeyEvent e) { } } );
I've added JTable to JPanel and used DefaultTableModel. I have to add a new empty Row to table after i press enter key. But somehow I've not been successful so far.
It works in the first time. But, after sometime the data is not retrieved and display empty screen. Once, i stop and start the server again, the data is getting retrieved again. But, later when we refresh the empty page is getting displayed again.
I've been trying to get my program to not accept empty strings when the user inputs, but I'm having some difficulties. I've tried for loops, as well as while loops.
import java.util.Scanner; public class GasMileage { /** * displayIntro * This method displays the introduction to the user */ public static void displayIntro()
When i run my program i see a JTable with data in it. The first 3 columns are filled with data, the next one is empty. Other columns that come afther the empty one are also filled.
So my 4th column is empty. But it only apears empty, cause when i move the 4th column to the left. The same column that was at 4th place is now at 3th place and filled up with data.
So the 4th column apears empty but it contains data when i move it to the left or the right.
Why does it show an empty column at the 4th place?
Some printscreens to get it clear:
In attachment:
attachment1 = 4th Column is empty attachement2 = 4th column is moved to 3th place and is filled with data.