将图形(绘画)添加到预先存在的JPanel

时间:2018-04-30 18:58:57

标签: java paint

我正在尝试将图形(绘图)添加到位于JFrame上的JPanel。这些(面板和框架)都已准备好在一个单独的类中创建。我无法让paint方法正常工作。有什么想法吗?

public class SeeProgressHandleClass extends JPanel implements MouseListener{

  JFrame window;
  JPanel panel;
  Graph graph;

  public SeeProgressHandleClass(JFrame window) {
    this.window = window;
  }

  public void mouseClicked(MouseEvent e) {
    panel = new JPanel();

    fillPanel();

    window.add(panel);
    panel.setBackground(Color.white);       
    panel.setBounds(50, 40, 1100, 660);     
  }

  public static void fillPanel() {
    //These three methods just add Labels and other panels to the panel
    addExitBox();
    addTitle();
    addLabels();        

    graph = new Graph(panel);
  }
}

public class Graph extends JPanel{

  public Graph(JPanel panel){
    panel.repaint();
  }

  public void paint(Graphics g){
    g.setColor(Color.green);
    g.fillOval(100,100,100,100);
  }
}

0 个答案:

没有答案