如何在按钮点击时重新绘制jPanel

时间:2015-03-04 16:28:51

标签: java paint

我在这个课程中有类Map我有这个方法

public void vykresliGraf(Graphics g){

    Set set = graf.getUzly().entrySet();
    g.setColor(Color.BLUE);

    Iterator it = set.iterator();
    while(it.hasNext()){
        Map.Entry entry = (Map.Entry) it.next();
        Uzel u = (Uzel)entry.getValue();
        Obec o = (Obec)u.getValue();
        g.drawOval(o.getSouradnice().x - 3, o.getSouradnice().y - 3, 6, 6);
        g.fillOval(o.getSouradnice().x - 3, o.getSouradnice().y - 3, 6, 6);
    }
    it = set.iterator();
    List<Hrana> pomList = new ArrayList<>();
    while(it.hasNext()){
        Map.Entry entry = (Map.Entry) it.next();
        Uzel u = (Uzel)entry.getValue();
        for (int i = 0; i < u.getHranyUzlu().size(); i++) {
            Hrana h = (Hrana)u.getHranyUzlu().get(i);

            if(!pomList.contains(h)){

                pomList.add(h); 
                Obec o1 = (Obec)h.getZdroj().getValue();
                Obec o2 = (Obec)h.getCil().getValue();
                g.drawLine(o1.getSouradnice().x, o1.getSouradnice().y, o2.getSouradnice().x, o2.getSouradnice().y);
            }

        }
    }
}

在我的MainFrame类中,我有buttonClick上的方法 map.vykresliGraf(jPanel1.getGraphics());它在jPanel上绘制我的地图但是什么时候 删除一些顶点(按钮单击)并调用相同的map.vykresliGraf(jPanel1.getGraphics());什么都没发生我尝试重绘();还有什么可以帮助我吗?

0 个答案:

没有答案