java - I made a function that uses graphics and I wanted to call it in the main it did not work -


the main:

public class appmain {  public static void main(string[] args) {     // todo auto-generated method stub      app a1 = new app();      jframe f2 = new jframe();       f2.getcontentpane().add(a1);      f2.addwindowlistener(new windowadapter() {         public void windowclosing(windowevent we) {             a1.stop();             a1.destroy();             system.exit(0);         }     });      f2.setvisible(true);      f2.setsize(200, 200);      a1.setbackground(color.white);      //the function     //a1.drawbow(null, 40, 40, color.black);     a1.drawbow(a1.getgraphics(), 40, 40, color.black);    } 

the app class:

public class app extends applet{   int x1,y1,x2,y2;  public void paint(graphics g1) {           g1.setpaintmode();          g1.setcolor(color.blue);          g1.drawstring("hello!", 50, 50);          g1.setcolor(color.red);          g1.drawstring("hello!", 51, 51);          g1.setcolor(color.red);          g1.draw3drect(80, 70, 20, 20, true);          g1.setcolor(color.black);          g1.fill3drect(81, 71, 19, 19, true);          g1.setcolor(color.blue);          g1.fill3drect(82, 72, 17, 17, true);   }  public void init() {      setsize(200, 200);      setvisible(true);      repaint();   }  //the function public void drawbow(graphics g1,int x , int y,color c){      g1.setcolor(c);     x1=x;     y1=y;     x2=x1+10;     y2=y1+10;     g1.drawline(x1,y1,x2,x2);     x1=x2+10;     y1=y2+35;     g1.drawline(x2,y2,x1,y1);     x2=x1-10;     y2=y1+35;     g1.drawline(x1,y1,x2,y2);     x1=x2-10;     y1=y2+10;     g1.drawline(x2,y2,x1,y1);     x2=x1;     y2=y1-90;     g1.drawline(x1,y1,x2,y2);  } 

if move function paint work, can not receive color x , y, , can not call function how many times want in main. tried lot of ways , not, please help.

try passing graphics object drawbow in main:

//the function a1.drawbow(a1.getgraphics(), 40, 40, color.black); 

Comments

Popular posts from this blog

javascript - oscilloscope of speaker input stops rendering after a few seconds -

javascript - gulp-nodemon - nodejs restart after file change - Error: listen EADDRINUSE events.js:85 -

Fatal Python error: Py_Initialize: unable to load the file system codec. ImportError: No module named 'encodings' -