drawing on Jframe

后端 未结 4 624
不知归路
不知归路 2020-12-12 00:42

I cannot get this oval to draw on the JFrame.

static JFrame frame = new JFrame(\"New Frame\");
public static void main(String[] args) {
  makeframe();
  pain         


        
4条回答
  •  难免孤独
    2020-12-12 01:24

    Several items come to mind:

    1. Never override paint(), do paintComponent() instead
    2. Why are you drawing on a JFrame directly? Why not extends JComponent (or JPanel) and draw on that instead? it provides more flexibility
    3. What's the purpose of that JLabel? If it sits on top of the JFrame and covers the entire thing then your painting will be hidden behind the label.
    4. The painting code shouldn't rely on the x,y values passed in paint() to determine the drawing routine's start point. paint() is used to paint a section of the component. Draw the oval on the canvas where you want it.

    Also, you're not seeing the JLabel because the paint() method is responsible for drawing the component itself as well as child components. Overriding paint() is evil =)

提交回复
热议问题