I am making a Sudoku game and creating a matrix of JTextFields. However I am getting the following errors
Exception in thread "main" java.lang.NullPointerException
at SudokuView.board(SudokuView.java:30)
at SudokuView.<init>(SudokuView.java:18)
at SudokuMain.main(SudokuMain.java:5)
I know the problem is with this code
box[i][j] = new JTextField();
panel.add(box[i][j]);
I know this because when I do this:
panel.add(new JTextField());
It works. However it puzzles me why it is not working.
Whole Code:
import java.awt.GridLayout;
import javax.swing.*;
public class SudokuView {
JFrame frame;
JPanel panelBoard;
JTextField[][] box;
int row=10; int col=10;
SudokuView(){
frame = new JFrame("Play Sudoku GOOD LUCK");
I have to create a square matrix that has a min and max value as well as a size value which is given a integer value in the main method. The matrix has to be filled with random values. Also I have to add that matrix to another one in an addMatrix method and I have to subtract both in a subMatrix method. These are the requirements:
Methods: Constructor() - receives the row and col size for myMatrix and a max and min values for range of random fill values for the matrix. RandFill() - fills matrices with random numbers addMatrix() - receives a matrix object. adds its myMatrix with the received object's myMatrix. The result is placed in this object's myResultMatrix. subMatrix() - subtracts both matrices
I typed up this code but I'm not sure about some parts of it and I would creating min and max values in the Random method and in the main printing the separate 2 matrices and adding and subtracting them:
import java.util.*; public class SquareMatrix2 { public int size; public int myMatrix [][]; public int myResultMatrix; public int [][] ResultStatus;
I'm trying to get my matrix1 and matrix2 to add up to create a third matrix, I've gotten that down, but now I'm just having some trouble getting it to print out the matrix1, matrix2 and then the final matrix3 or the result matrix?
import java.util.Scanner; public class Exercise_7_5{ public static void main(String[] args){ Scanner input = new Scanner(System.in); System.out.print("Enter Matrix 1: "); double[][] matrix1 = new double [3][3];
I am required to read user input to create two matrices which will eventually be added together. I am unsure as to how I can read the input from the user as an int and not a String. The input is from size 0-10 for both column and row size. Also, can you have a new button created in the actionPerformed method of a previous button?
import javax.swing.*; import java.awt.*; import java.awt.event.*; import java.util.*; public class Matrices implements ActionListener { private JFrame win1, win2, win3, win4;
Here's My code to create multiple JTextfields in a Single Option Pane.
My goal is simple.
Take some input from the user and then store it a TEXT File.
package printer; import java.awt.Toolkit; import java.io.BufferedWriter; import java.io.FileWriter; import java.io.IOException; import javax.swing.*; public class Database { JTextField name = new JTextField(); JTextField roll = new JTextField();
I was assigned to create a program that opens up a window that asked the user for an input of 0-10. This input will create three windows with the correct number of rows and columns of JTextFields in the form of a matrix. the third window has a button that adds the two matrices (which also take user input) and adds them together and prints them in the correct matrix fields. I am having trouble declaring the 2d array from the user input and creating the windows with the correct amount of jtextfields to move on with my program.
I need to create a JFrame with a user given amount of text fields in the form of a matrix. Say the user inputs 5 rows and 5 columns, I need to read those ints and create a 5 by 5 box of JTextFields in matrix form (i.e. 25 total text boxes in the form of a box). Here is some of the code I have been trying to use to do this...
int x = 10; int y = 10; for(int i = 0; i<rowSize; i++){ y= y+40; for(int k =0; k<colSize; k++) { newField = new JTextField("0"); newField.setBounds(x,y,40,20); win2.add(newField,0); win2.repaint(); x= x+60; } }
In order to go through the loop a given amount of times and create that amount of text fields in the correct places.Am I even close to doing this right?? Cuz I can't get the text fields to even show up on my window.
I am trying to create an event handler for two JTextFields to only allow numerical input. It consumes all letter but for some reason the "n" key still gets through. I have the spaghetti code below.
public void keyTyped(KeyEvent in) { char input = in.getKeyChar(); if (in.getSource() == scaleField){ if (!(Character.isDigit(input) || (input==KeyEvent.VK_BACK_SPACE) ||
Code given below does real time validation for 2 JTextFields. While entering some values to txt1 and txt2 enables the save button and removing values from txt2 or txt1 reset the save button to disable. I use Netbeans as IDE.What I want to do is, enable Save button after checking multiple JTextFields for validity. If any of the text fields is empty, btnSave must be disabled.This program gives expected result up to some extent. But there is little issue. After form appears for the first time, When I type something on Textfield1, Save button enables without checking Textfield2. This happens only at the first time.
public class NewJFrame extends javax.swing.JFrame { private Boolean isValidFromTextField1 = true; private Boolean isValidFromTextField2 = true; public NewJFrame() { initComponents(); btnSave.setEnabled(false);
I am working on my second javafx program and I am getting confused. The program that I am writing is a payroll calculator. A secondary window opens at the start of the program where the user first enters the number of employees and clicks submit to save the number and to close this window. Then, the user begins to enters the employee information (first name, last name, pay rate and hours worked) when the user clicks the NextEmp button, I want the data in the text fields to be entered into arrays for later use, then clear the fields for the next use. I am running into 2 issues. The first is the close event for the secondary window that pops up. I cannot figure out the syntax. The second issue that I am running into is the loop to store the data into the arrays. I believe I am getting the text field data correctly, but I cannot figure out how to stop the loop until the NextEmp button is pressed again.
I have an ArrayList of JTextFields in a CAMSetup1 class that contains a bunch of named JTextFields: Layer_textField_1, Layer_textField_2, Layer_textField_3, ... etc
I would like to check the .isEnabled status of a particular JTextField in that ArrayList from my main class by passing the name of the JTextField to a method in the CAMSetup1 class as a string
The peice of code calling the method from the main class is something like this:
if (CAMSetup1.getFieldEnabledStatus("Layer_textField_1") == true) { data.writeToFile(CAMSetup1.getFieldText("Layer_textField_2") + " LAYER 2 LIST FILE "); }
The method for checking the .isEnabled that I have so far is:
public boolean getFieldEnabledStatus(String textFieldname) { boolean status = false; //<need code here> return status; }
I have made a window using JFrame and on my JPanel I have added 3 components: 2 JTextFields ("field1" and "field2") and inbetween them a JButton ("switch"). My goal is to switch the value of field1 to field2 and vice versa when the JButton is clicked. I thought this ActionListener which I have added to my JButton would achieve my goal:
public void actionPerformed(ActionEvent e) { field2.setText(field1.getText()); field1.setText(field2.getText()); }
However, it changes the value of field2 into the value of field1 but not the other way around.
Im trying to get the user to input the rows one by one but my input stops after the first. the examples i looked at in my book had this way i used as well. i are my rows and j are my columns. What is the correct way to do it?
import java.util.Scanner; public class Exercise08_01 { public static void main(String[] args) {
My code then is supposed to read it in and store it as an Array of singly linked lists. I am having trouble with my code, I am only getting outputs where it is only storing the first line of the txt matrixs like so:
The Java-program Matrix below first asks the user for the number of rows and columns in a matrix. After this the program asks for the values of the elements. Finally, program prints the elements of the matrix and their sum on screen. Your task is to create the missing methods. Check the example print to see how to modify the print. When printing the matrix, values on the same row are separated using tabulator.
Program to complete:
import java.util.Scanner; public class Matrix { public static void main(String[] args) { int rows, columns; Scanner reader = new Scanner(System.in); System.out.print("Type in the number of rows: ");
[code]...
Write the missing methods here / Methods are written in the text box below.
Example output
Type in the number of rows: 3 Type in the number of columns: 4 Type in the element 1 of the row 1: 1 Type in the element 2 of the row 1: 2 Type in the element 3 of the row 1: 3 Type in the element 4 of the row 1: 4 Type in the element 1 of the row 2: 5
[code]...
Matrix:
1 2 3 4 5 6 7 8 9 10 11 12
Sum of the elements of the matrix: 78
my code
import java.util.Scanner; public class apples { public static void main(String[] args) { int rows, columns; Scanner reader = new Scanner(System.in); System.out.print("Type in the number of rows: ");
I am attempting to get the x and y coordinate of a matrix of buttons. I have googled my way to failure and read the docs and I think I am traveling of track.
Below is where I create a matrix of buttons via Swing
public class View extends Mybuttons{ private static final long serialVersionUID = 1L; JFrame frame; JPanel matrixPanel, optionsPanel; Mybuttons[][] matrixBtn;
Later in this class:
JPanel matrixPan(){ matrixBtn = new Mybuttons[25][25]; JPanel panel = new JPanel(); panel.setSize(550,550); panel.setLayout(new GridLayout(25,25)); //creating a 25x25 matrix of buttons
[Code]...
In the controller class I am trying to get the index of each button in the getUnvisitedChildNode method. I need to do this so I can search the buttons around the button passed to it and check if they are been visited yet. Below getUnvisitedChildNode you will be bfs (breadth first search).
private Mybuttons getUnvisitedChildNode(Mybuttons b){ //example of some of the things I have tried int x= Mybuttons.getComponentAt(b); int y= Mybuttons.indexOf(b); int j=0; return b; }
I have a programming assignment in which I have to make a program which loads a crossword from a Properties file and then, when the user press a button, the program checks if the letters the user has typed in the interface are the same as in the correct matrix. If all the letters from a word are correct, the program must paint every letter of the word green.
I'm using two matrix, one that is called "mundo" (I 'm from Latin America) , which has the correct letter for each box. The other one is a JtextField matrix which ='ve created using a Gridllayout. I called this one crucigrama (crossword in Spanish)
This is the code I wrote to validate: So you can understand, here is a translation:
numero = number fila = row column = columna bien - a boolean I used to check if the letter I've checked before are the same as the correct ones .darLetra() - returns a string with the correct letter
If the user for example enter the number 2 for index I need to swap the matrix from this index two lines with two line so this is the result what I need
I have a 5x5 array of which I read from an external file and I am supposed to print out the original matrix and then add up each row and column, proceeding to store them into the sixth positions in my matrix. After that I print out the new matrix.
I am confused as to how to isolate rows and print them out. I know how to add the entire matrix up but isolation is my issue.
Here is what I have including how to read the matrix and the sum of the whole thing
import java.io.*; import java.util.*; public class prog470cAddingRandC { public static void main (String [] args) { //read the file Scanner inFile=null;
I have some N*M matrix or N*N matrx , and there's a "worm" that can start from any index in the first column, or, any index in the first row. i need to choose the longest worm that satisfying this :
The index that comes after the index before him must be greater then 1. and i must use recursion, also for helper methods. no loops at all. that's it. i'm having a problem to find the longest worm in the matrix.
My idea was to create an helper array and assign to the array indexes a variable that will count the steps of the worm and finally assigns in to the helper array index. then i used findMax method to find the max value in an index. and thats will be the longest worm. i wrote a lot of code so i wont put it here. i will say that i'm close. if the longest worm is 6 i get in my output 7.
I have found out the area that causes this, my toString, but I want to know if there is something built in or not that will allow me to print it such that I can continue printing it at the same row level as its neighbor, even though I create a new line for each individual column? Here is the code that I try to print out the entire cube: