Skip to content

Commit 2d688c6

Browse files
committed
r extract class
1 parent eec43dc commit 2d688c6

File tree

2 files changed

+20
-12
lines changed

2 files changed

+20
-12
lines changed
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
package com.spun.swing;
2+
3+
import java.awt.Graphics;
4+
import javax.swing.JPanel;
5+
6+
class PaintablePanel extends JPanel
7+
{
8+
private final Paintable paintable;
9+
public PaintablePanel(Paintable paintable)
10+
{
11+
this.paintable = paintable;
12+
setPreferredSize(paintable.getSize());
13+
}
14+
@Override
15+
public void paint(Graphics g)
16+
{
17+
paintable.paint(g);
18+
}
19+
}
Lines changed: 1 addition & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,11 @@
11
package com.spun.swing;
22

3-
import java.awt.Graphics;
43
import javax.swing.JPanel;
54

65
public class Paintables
76
{
87
public static JPanel asPanel(Paintable paintable)
98
{
10-
return new JPanel()
11-
{
12-
{
13-
setPreferredSize(paintable.getSize());
14-
}
15-
@Override
16-
public void paint(Graphics g)
17-
{
18-
paintable.paint(g);
19-
}
20-
};
9+
return new PaintablePanel(paintable);
2110
}
2211
}

0 commit comments

Comments
 (0)