0
I have 2 screens in Swing, one that calls a method and registers the information in an array, and another screen that should fetch one of this information and display in it, the problem is that as the objects are different, I can’t get the data of the object that registers.
Is there any way to get the address of the object you register to use on the search screen and be able to extract the information from that array or do something like?
OBS: it has to be with array, I can’t use db or external files.
An example of a Register screen:
public void formularioCadastro() {
Alunos cadastrarAlunos = new Alunos();
// Cadastra os nomes numa Array
cadastrarAlunos.setNome("Maria", 0); // Nome, posição da Array
cadastrarAlunos.setNome("Lindovania", 1); // Nome, posição da Array
cadastrarAlunos.setNome("Jose", 2); // Nome, posição da Array
cadastrarAlunos.setNome("Josefina", 3); // Nome, posição da Array
cadastrarAlunos.setNome("Maristela", 4); // Nome, posição da Array
}
Search Screen:
public void formularioBusca() {
BuscarAluno buscarNome = new BuscarAluno();
buscarNome.buscar("Jose");
}
What happens is the following, if you run this code, it will give Nullpointerexception, because the data registered in the "Registration Screen" are in the object "register Students". In order to find the values that were registered there, you would have to use the same object, which in this case, is not possible because there are two different screens (files).
Here comes the question from above, how to recover this data or the reference of the object to make use as described above?
Put the code. Without it it is like trying to plug an outlet into a concrete block.
– ptkato
I edited the main post, with the example!
– rborgesds
Are you sure you want to use an array? It looks like a list.
– ptkato
What’s in your class
Alunos
and in his classBuscarAluno
? How your canvases are instantiated?– Victor Stafusa
Patrick, I don’t know how to use lists, and neither can I, it’s a college paper. Victor, in the Students class has a get and set method, and in Buscaraluno a method that scans the array with a for and returns whether it exists in the array or not. Ai would be just an example, but the swing screens would be, a jFrame(Home Screen) that calls 2 Jinternalframe(Register and Search).
– rborgesds