私はそれがよく言われていないことを知っていますが、私はそれをよりよく言葉にする方法を知らない。基本的に私自身のJComponent MyComponent
を持っていて、グラフィックスにいくつかのものをペイントします。別のクラスで、その後クラスを私のペイント関数に追加させるにはどうすればいいですか?
public class MyComponent extends JComponent{
// etc
@Override
protected void paintComponent(Graphics g) {
super.paintComponent(g);
g2 = (Graphics2D)g;
g2.drawSomething(); // etc
// Once it is done, check if that function is exists, and call it.
if(secondaryPaint != null){
secondaryPaint(g2);
}
}
}
::私はそれは、その後、そのようなものをペイント塗料を終了するメソッドを呼び出したい、ここでは一例である
// etc
MyComponent mc = new MyComponent()
mc.setSecondaryDrawFunction(paint);
// etc
private void paint(Graphics2D g2){
g2.drawSomething();
}
私はどのようにラムダわかりません彼らがこの状況に適応できるかどうか、それは多分でしょうか?
あなたは抽象クラスを意味していますか? JComponentから継承した抽象クラスを作成し、ペイントしたpaintComponentメソッドをオーバーライドし、抽象クラスで定義された抽象メソッドを最後に呼び出すことができます – Pali