title: Java override method from another class without inheritance
body: <p>I found a similar question here:<br>
  <a href="https://stackoverflow.com/questions/5992668/overriding-methods-without-subclassing-in-java">overriding methods without subclassing in Java</a>  </p>
  
  <p>But mine a little different, I have two classes, 1 GUI based, and the other just methods to modify elements in first class. If it just editing the basic function, I meet no problem, but now I want to override a jbutton in first class method from the second class without inheriting it. Where do I have to start?  </p>
  
  <p>I have temporary solution which is that the second class extends JButton, override method I want to, and add that class to my GUI class (anonymous object or not, is doesn't matter). But I want to discover a way to find a way to my question, is it even possible? Thanks :)</p>
  
  <p><strong>Edit</strong><br>
  Here's sample code:  </p>
  
  <p>First class, as it only a button in jframe, I only add these in constructor:<br>
  <code>ButtonOverrider bo=new ButtonOverrider();</code> -> this is the overrider class<br>
  <code>button=bo.overridePaintComponent(bo);</code> //first try<br>
  <code>button=bo.overridePaintComponent();</code> //second try<br>
  <code>bo.overridePaintComponent(bo);</code> //third try  </p>
  
  <p>And here's the ButtonOverrider method:  </p>
  
  <pre><code>public JButton ButtonOverrider(JButton button) {
    button = new JButton() {
      @Override
      protected void paintComponent(Graphics g) {
        Graphics2D g2 = (Graphics2D) g.create();
        GradientPaint gp = new GradientPaint(0, 0,
        Color.blue.brighter().brighter(), 0, getHeight(),
        getBackground().darker().darker());
  
        g2.setPaint(gp);
        g2.fillRect(0, 0, getWidth(), getHeight());
        g2.dispose();
  
        super.paintComponent(g);
        super.setContentAreaFilled(false);
        super.setFocusPainted(false);
        super.setBorder(new LineBorder(Color.yellow, 2));
        super.setText("Shuro");
      }
    };
    return button;
  }
  </code></pre>