I have a project in school to build an application. Since I am quite new to the Java world I am struggling.
I decided to work in NetBeans and try to somehow dynamically create the app. I created a JFrame
class dynamically in Source Packages and added couple of buttons there (dynamically).
Then I created another JPanel
class which I want to link to the JFrame
class using a Jbutton in JFrame
class. However I do not know how the JFrame
is called in the JFrame
class which means I can't add or remove anything from it, only dynamically.
I tried creating a new instance called JFrame
but it would just write that it can not find the symbol.
I also tried to just call the JFrame
(Frame.add(nr)
) but it only wrote that
non-static method add cannot be referenced from a static context
public class Frame extends javax.swing.JFrame {
public Frame() {
initComponents();
}
private void createRecipeActionPerformed(java.awt.event.ActionEvent evt) {
intro.show(false);
NewRecipe nr = new NewRecipe();
Frame.add(nr);
nr.show(true);
}
My expected result is: When the JButton
is clicked in the JFrame
the JPanel
would appear.