Reputation:
Some time ago I wrote a code in a single main class which worked fine. Later I added JPanel and JFrame in again its single main it again worked fine.
Now I am trying to break the code down and move them into packages.
here is my main -( src/start/Main.java)-
package start;
import javax.swing.JFrame;
import frames.*;
public class Main {
public static void main(String[] args) {
MainFrame.createFrame();
LogoPanel.createLogoPanel(); //this line is the problem
}
}
here is MainFrame -(src/frames/MainFrame.java)-
package frames;
import javax.swing.JFrame;
public class MainFrame {
public static JFrame createFrame() {
JFrame frame = new JFrame ("App");
frame.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
frame.setResizable(false);
frame.setBounds(140,140, 1000, 580);
frame.setVisible(true);
frame.setLayout(null);
return frame;
}
}
here is LogoPanel
-(src/frames/LogoPanel.java)-
package frames;
import java.awt.Color;
import javax.swing.JFrame;
import javax.swing.JPanel;
public class LogoPanel {
public static JPanel createLogoPanel(JFrame frame) {
JPanel logoPanel = new JPanel ();
logoPanel.setVisible(true);
logoPanel.setBounds(0, 0, 1000, 80);
logoPanel.setBackground(Color.gray);
logoPanel.setLayout(null);
frame.add(logoPanel);
return logoPanel;
}
}
as I said LogoPanel.createLogoPanel(); is the problem . It does not accept createLogoPanel(JFrame frame) from me ? setting it to null doesn't show the panel at all . anyway I can make this work ?
Upvotes: 0
Views: 133
Reputation: 6969
Your createLogoPanel
takes a JFrame
type argument.
But I don't see you passing an argument when you are actually invoking the method.
Do something along the lines of :
JFrame frame = MainFrame.createFrame();
LogoPanel.createLogoPanel(frame);
This error seem to suggest a lack of understanding about basic Java syntax and concepts. If you are able to accumulate knowledge in this area it will benefit you greatly in the future.
Upvotes: 1