I\'m looking for the most basic description of how to draw text within a JPanel. I know there are a billion tutorials out there but none of them are clicking with me and I h
Create an inner class that extends JPanel inside your Main class:
class MyPanel extends JPanel {
@Override
protected void paintComponent(Graphics g) {
super.paintComponent(g);
g.drawString(Integer.toString(avg), 75, 75);
}
}
Then you need to call repaint on that panel after calling computeAverage() in actionPerformed:
//event handling
public void actionPerformed(ActionEvent e) {
if (e.getSource() == avgBtn) {
computeAverage();
panel.repaint();
}
}