diff --git a/chart_inheritance/src/main/java/edu/unl/cse/soft160/chart_inheritance/App.java b/chart_inheritance/src/main/java/edu/unl/cse/soft160/chart_inheritance/App.java index 087b0a22f8608e1018445784d9b8359c7f524712..0f4d2e3ceadf0eed3bd42178e0b0d0bfd6764439 100644 --- a/chart_inheritance/src/main/java/edu/unl/cse/soft160/chart_inheritance/App.java +++ b/chart_inheritance/src/main/java/edu/unl/cse/soft160/chart_inheritance/App.java @@ -46,14 +46,17 @@ public class App extends JFrame { context.setFont(TEXT_FONT); context.setColor(TEXT_COLOR); context.setColor(Color.BLUE); - try { - chart.getClass().getDeclaredMethod("draw", Graphics2D.class).invoke(chart, context); - } catch (NoSuchMethodException exception) { - throw new RuntimeException(exception); - } catch (InvocationTargetException exception) { - throw new RuntimeException(exception); - } catch (IllegalAccessException exception) { - throw new RuntimeException(exception); + for (Class<?> type = chart.getClass(); type != null; type = type.getSuperclass()) { + try { + type.getDeclaredMethod("draw", Graphics2D.class).invoke(chart, context); + break; + } catch (NoSuchMethodException exception) { + continue; + } catch (InvocationTargetException exception) { + throw new RuntimeException(exception); + } catch (IllegalAccessException exception) { + throw new RuntimeException(exception); + } } }