Sorry for the very noob question, but I'm having a tremendously difficult time understanding Swing graphics and how to just, well, draw something for goodness sake.
First question is just a snippet question.
When we do this standard code in particular...
public static void main(String[] args) {
Jframe frame= new JFrame();
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setContentPane(new MyCustomJPanel());
frame.setSize(500,500);
frame.setVisible(true);
}
...we set the frame pane as a new JPanel object (of class MyCustomJPanel in this case), but we don't directly name that new MyCustomJPanel object...why don't we name it? And without naming it, how can we possibly ever reference that object again?
Second question...as I mentioned, I've been studying swing graphics now for a bit but I simply can't get my mind wrapped around it. Try as I might, I simply cannot conjure up a way to draw a line at runtime on my JPanel in my JFrame. Is there no way to do this? It seems unless the line is hard-coded at compile time in my JPanel's overridden paint(g) method, runtime addition simply can't be done (without resorting to BufferedDrawings or other more advanced topics)...as there's no way to dynamically throw new code into paint(g).
Thanks, and sorry for the noobness. Trying to (re)learn OOP and Java and having a roaringly difficult time of it.