Skip to content
Snippets Groups Projects
Commit 078d90ed authored by Brady James Garvin's avatar Brady James Garvin
Browse files

Fixed simulated duck typing in App.

parent 571e3eea
No related branches found
No related tags found
No related merge requests found
...@@ -46,16 +46,19 @@ public class App extends JFrame { ...@@ -46,16 +46,19 @@ public class App extends JFrame {
context.setFont(TEXT_FONT); context.setFont(TEXT_FONT);
context.setColor(TEXT_COLOR); context.setColor(TEXT_COLOR);
context.setColor(Color.BLUE); context.setColor(Color.BLUE);
for (Class<?> type = chart.getClass(); type != null; type = type.getSuperclass()) {
try { try {
chart.getClass().getDeclaredMethod("draw", Graphics2D.class).invoke(chart, context); type.getDeclaredMethod("draw", Graphics2D.class).invoke(chart, context);
break;
} catch (NoSuchMethodException exception) { } catch (NoSuchMethodException exception) {
throw new RuntimeException(exception); continue;
} catch (InvocationTargetException exception) { } catch (InvocationTargetException exception) {
throw new RuntimeException(exception); throw new RuntimeException(exception);
} catch (IllegalAccessException exception) { } catch (IllegalAccessException exception) {
throw new RuntimeException(exception); throw new RuntimeException(exception);
} }
} }
}
public static void main(String... arguments) { public static void main(String... arguments) {
String[] labels = { "Alpha", "Bravo", "Charlie", "Delta", "Echo", "Foxtrot", "Golf" }; String[] labels = { "Alpha", "Bravo", "Charlie", "Delta", "Echo", "Foxtrot", "Golf" };
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment