Results 1 to 3 of 3
  1. #1
    tenkoo is offline Member
    Join Date
    Jan 2010
    Posts
    2
    Rep Power
    0

    Default Help me eveyone...

    Could someone please help me…I’ve problem to make a java code so that the code will generate the applet as shown below. I manage to build a code to plot binary graph using g.drawString without receive any input from user. But I need to build an applet such like a given pix which receive input from user and graph plotted by click plot button. Basically,I’ve two problems, I don’t know how to receive/invoke any values from user to the graphics g method and how to place graphics on the layout,panel or whatever that related together within jbutton,jtextarea, etc. Here is my simple code to draw the graph. I hope I could get any similar code with the applet. Sorry for my broken english…Thanks..
    import java.awt.*;
    import java.applet.*;

    public class lolo extends Applet {
    public void init() {

    }
    public void paint(Graphics g) {

    g.drawLine(30, 50, 30, 250);
    g.drawLine(30, 150, 500, 150);
    g.setColor(Color.RED);

    int[] bin ={1,0,1,0,1,1,0,0,0,1,0,1,0,0,1,0,1};
    int[] x1 = new int[bin.length];
    int[] y1 = new int[bin.length];
    int[] x2 = new int[bin.length];
    int[] y2 = new int[bin.length];

    for (int i=0, count=30;i<bin.length;i++,count+=30){
    if(bin[i]==1){
    x1[i]=0+count;
    y1[i]=100;
    x2[i]=30+count;
    y2[i]=100;
    }
    else if(bin[i]==0){
    x1[i]=0+count;
    y1[i]=200;
    x2[i]=30+count;
    y2[i]=200;
    }
    }

    for(int i=0; i<bin.length;i++){
    g.drawLine(x1[i], y1[i], x2[i], y2[i]);
    g.drawLine(x2[i], y2[i], x1[i+1], y1[i+1]);
    }
    }
    }


  2. #2
    mrmatt1111's Avatar
    mrmatt1111 is offline Senior Member
    Join Date
    Aug 2009
    Location
    San Jose, CA, USA
    Posts
    320
    Rep Power
    6

    Default

    Your chart should be in it's own jpanel which you attach to the applet. You can pass your data, when you click on the plot button, to that jpanel and then repaint it.
    My Hobby Project: LegacyClone

  3. #3
    tenkoo is offline Member
    Join Date
    Jan 2010
    Posts
    2
    Rep Power
    0

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •