I'm new to java, I would like some advice from you:
I would insert in setPreferredSize() the width and the height of the manager class, without using the "evil" statics, can someone tell me the smartest thing to do in this case?
is it possible to not create a constructor in manager class and pass the width and height always respecting the OOP's flexibility classes?
- I was wrong to write add(Panel.getPanel()), it is correct? it respects the OOP?
Tell me where am I wrong in this code or what to fix, I want to learn,thanks you.
public class MainFrame extends JFrame {
public static void main(String[] args) {
final MainFrame mainFrame = new MainFrame();
mainFrame.setVisible(true);
}
public MainFrame() {
initFrame();
}
private void initFrame() {
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
add(Panel.getPanel());
setResizable(false);
setUndecorated(true);
pack();
setLocationRelativeTo(null);
}
}
public class Panel extends JPanel {
public Panel() {
setPreferredSize(new Dimension(/*?????????*/));
}
}
public class Manager {
private int width = 700;
private int height = 700;
// Some unrelated code follows
public int getHeight(){
return height;
}
public int getWidth(){
return width;
}
}