public class sagum2 {

private static int n1;
private static int[] apw1;

public static void main(String[] args) {
    try{
        Scanner console = new Scanner(System.in);
        sagum2 s = new sagum2();
        Graphics g= getGraphics();

        char c,c1 = 0,c2=0,c3=0;
        int apw1[];
        int p[];
        int n,n1,ch;

        String  input;
        char ans1, ans, input1;
        boolean retry = true;

        BufferedReader obj=new
        BufferedReader(new InputStreamReader (System.in));
        System.out.println("ENTER no. of processes:");
        n=Integer.parseInt(obj.readLine());

        int bt[]=new int[n];
        System.out.println("MENU FOR CPU SCHEDULING");
        ch=Integer.parseInt(obj.readLine());
        switch(ch) {

        case 1:

        .....

        case 2:
        ....
        case 3:
        ....

        }
    } catch (Exception e) {

    }

}

    private String[] p;
    public void paint(Graphics g)
    {
        for(int j=1;j<=n1;j++)
        {
            g.drawRect(50,50,(apw1[j]*20),30);
            g.drawString("p"+p[j-1],(55+(apw1[j-1]*20)),70);
            g.drawString(""+apw1[j-1],50+(apw1[j-1]*20),100);
        }
        g.drawString(""+apw1[n1],50+(apw1[n1]*20),100);
    }
}

我在有一个错误
 Graphics g= getGraphics();

说找不到符号“getGraphics”,我已经将其更改为
   private static Graphics getGraphics() { throw new UnsupportedOperationException("Not supported yet.");
}

我叫它执行一个扩展的小程序来显示甘特图。
请帮我这个项目

最佳答案

你在哪画您的类(class)应该花费JPanel吗?您是否需要缓冲图像?

您需要在某处绘制:

尝试:

Graphics g = (new BufferedImage(100, 100, BufferedImage.TYPE_INT_ARGB)).getGraphics();

10-06 16:20