如何处理JPanel?

时间:2017-01-17 12:56:43

标签: java netbeans jpanel

单击其他课程中的按钮后,将执行以下代码。如何在任何按钮上放置此JPanel?

public class Final_Class extends JPanel {



public void paintComponent(Graphics g){
    super.paintComponent(g);
    this.setBackground(Color.WHITE);


    g.setFont(new Font("TimesRoman", Font.PLAIN, 10));
    for(int a=0;a<upto;a++){
        if(a==7) g.setColor(Color.GRAY);
        if(a==8) g.setColor(Color.DARK_GRAY);
        if(a==9) g.setColor(Color.LIGHT_GRAY);
        if(a==0) {g.fillRect(40, 110+x,Integer.parseInt(Burst[a])*5, 30);
                 g.setColor(Color.BLACK);
                 g.drawString("J".concat(Integer.toString(Jobs[a]+1)),40,105+x);
                 g.drawString(Burst[a], 35+CT[a]*5, 155+x);}
        if(a>0){ g.fillRect(40+CT[a-1]*5, 110+x,Integer.parseInt(Burst[a])*5, 30);
                g.setColor(Color.BLACK);
                g.drawString("J".concat(Integer.toString(Jobs[a]+1)),40+CT[a-1]*5,105+x);
                g.drawString(Integer.toString(CT[a]), 35+CT[a]*5, 155+x);}
    }


}

1 个答案:

答案 0 :(得分:0)

可以使用Container.remove(Component)从容器中删除组件。您只需要保留对组件的引用。

相关问题