0

I'm trying to learn to code on my own and I've created a GUI. I have a Main class and some other classes created with WindowBuilder that represent screens in my GUI. I'm trying to create a method in my Main class from where I should specify properties like Font, BackgroundColor and what field to apply these on, and then append this method in those classes to be more clean but I don't know what to do.

Main class:

public class Main extends SomePackage implements ActionListener{
    public Main() {
    }

    private class Mouse_thing extends MouseAdapter {

        public void mouseReleased(MouseEvent event) {
            Object object = event.getSource();
            //some code 
             ...................................................

        }
    }
   //method I'd like to implement:

   protected Field initializeField(Field SomeField){       
       add(initializeField(SomeField));
       return initField(SomeField);
   }

Random class that I want to be more clean (let's call it Random1).

So I'm trying to get rid of these properties being written here and append them from the method initializeField in Main class. Can I get some insight from you, please? Thank you!

public class Random1 extends Main {
    public Random1() {
    }

    @Override
    public void init(){
        setLayout(null);
        setForeground(java.awt.Color.black);
        setFont(new Font("Courier", Font.BOLD, 10));
        setSize(200, 200);
        label1.setText("some text");
        label1.setBackground(java.awt.Color.black);
        label1.setFont(new Font("Courier", Font.BOLD, 10));
        add(label1);
GameDroids
  • 5,584
  • 6
  • 40
  • 59
Florianz
  • 1
  • 2

1 Answers1

0

I would suggest you learn Builder and Factory Method design patterns. And it's better to try them in a separate application first, to better understand their purpose and how to use them effectively.

Static initializations and other practices are error-prone in real applications.

humb1t
  • 87
  • 1
  • 4