Hello Community,
I am doing an apprenticeship as a Java developer and I am working with a mini Java project which creates a window with a JScrollPanel
to display String
which is programmed in the component class.
I already create two java class files (main and component). I am stuck with linking the component one to the main. This part of the code is from my main file:
private void initGUI(){
{
jScrollPane1 = new JScrollPane();
getContentPane().add(jScrollPane1);
jScrollPane1.setBounds(31, 31, 300, 175);
{
jListWolkenkrazer = new DefaultListModel();
jListalcobareno = new JList();
jScrollPane1.setViewportView(jListalcobareno);
jListalcobareno.setModel(jListWolkenkrazer);
skyscrapers = new SkyScrapers();
}
}
{
jBShow = new JButton();
getContentPane().add(jBShow);
jBShow.setText("Show");
jBShow.setBounds(174, 230, 94, 23);
jBShow.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent evt) {
jBShowActionPerformed(evt);
}
});
}
}
private void jBShowActionPerformed(ActionEvent evt) {
int[] clues = {5100};
int[][] result = SkyScrapers.solvePuzzle(clues);
skyscrapers.setText(skyscrapers);
}
If you look at the private void jBShowActionPerformed
method, I used the objects clues
and result
from the component file. The problem is, what kind of value I am supposed to put in the array of clues
. You can see 5100 filled in here, but it already gave me some errors (ThrowNumberException) once I run this code and click the show button in the displayed UI.
There is another problem in private void jBShowActionPerformed
, I wanted to display what I coded in my component file into the jScrollPanel
component. That is why I placed skyscrapers.setText(skyscrapers);
, which also threw me Exception error. I guess I should have used any other getSomething() method, but I have no idea what that Something is.
I appreciate any suggestion on the above problems. I do NOT wish anyone to rewrite the code for me, but I hit the wall and just need another set of insights.
If you’d like to see the full codes for better context of what I am fighting for, please take a look at SkyScrapers (component) and SkyScrapersTest (main).