I have an existing graphics object, and I'm attempting to add a JRadioButton on top of it. Once the program is run, the button does not show up, and I think it's because there isn't a way to add a JPanel to a Graphics object. I add the JRadiobutton to its appropriate ButtonGroup and then I add the button to a JPanel, but I haven't seen any way to add a button on top of my graphics object.
Is there a way to add a radio button to a graphics object? It's important that I continue using this graphics object. Let me know if seeing the code will help, I think I just need a better way to approach this.
private void redrawTitle(Graphics gc) {
gc.setColor(Color.yellow);
gc.fillRect(0, 0, view_width, view_height);
gc.setFont(largeBannerFont);
FontMetrics fm = gc.getFontMetrics();
gc.setColor(Color.red);
centerString(gc, fm, "Start", 100);
gc.setColor(Color.blue);
gc.setFont(smallBannerFont);
fm = gc.getFontMetrics();
centerString(gc, fm, "by DavidVee", 160);
centerString(gc, fm, "a;lskdf", 190);
gc.setColor(Color.black);
centerString(gc, fm, "To start, select a skill level.", 250);
JRadioButton kruskalButton = new JRadioButton("Kruskal");
ButtonGroup group = new ButtonGroup();
group.add(kruskalButton);
JPanel panel = new JPanel();
panel.add(kruskalButton);
centerString(gc, fm, "(Press a number from 0 to 9,", 300);
centerString(gc, fm, "or a letter from A to F)", 320);
centerString(gc, fm, "v1.2", 350);
}