回覆列表
  • 1 # mpslg12443

    這是簡單的初步實現,你可以借鑑一下哈packagev01;importjavax.swing.*;importjava.awt.*;publicclassColorPextendsJFrame{publicColorP(){this.add(newNewPanel());}publicstaticvoidmain(String[]args){ColorPframe=newColorP();frame.setTitle("Content");frame.setSize(300,150);frame.setLocationRelativeTo(null);frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);frame.setVisible(true);}classNewPanelextendsJPanel{//擴充套件JPanelpublicNewPanel(){}protectedvoidpaintComponent(Graphicsg){//運用畫筆Graphics繪製super.paintComponent(g);//新增畫筆int[]x=newint[4];int[]y=newint[4];for(inti=0;i<10;i++){x[0]=i*40;y[0]=0;x[1]=x[0]+40;y[1]=0;x[2]=0;y[2]=(i+1)*40;x[3]=0;y[3]=y[2]-40;if(i%2==0)g.setColor(Color.black);elseg.setColor(Color.yellow);g.fillPolygon(x,y,x.length);}}}}

  • 中秋節和大豐收的關聯?
  • 汽車上有這麼多燈各有什麼用途呢?