Results 1 to 2 of 2
  1. #1
    keaton1ao is offline Member
    Join Date
    Nov 2010
    Posts
    8
    Rep Power
    0

    Default Please Help! : Java Graphics

    Ok so I have an assignment for my class, I'm very new to Java and I'm stumped. I need to use the .drawString method at the end of this file to print out an array that I have the user input information for but I cannot for the life of me get it to work. My line of code ff.drawLine(numPlay[i], 10, 10); doesnt read the numPlay array in the for statement at the top of the code. How do i get it to recognize this array and draw the information I need? Thank you so much for the help!

    P.S. I am a VERY new beginner, I know that my code may not be very efficient and could be done better, just need this one question answered. Here is the code:

    //Michael Keaton
    //File NFLGameday6.java
    import jpb.*;
    import java.awt.*;

    public class NFLGameDay6 {
    public static void main (String [] args){

    //Construct Team
    SimpleIO.prompt("How many players are on the team: ");
    String userInputA = SimpleIO.readLine().trim();
    int numberOfPlayersA = Integer.parseInt(userInputA);

    //Prompt user to enter players into the Team
    String[] numPlay = new String[numberOfPlayersA];
    for (int i=0; i < numberOfPlayersA; i++){
    SimpleIO.prompt("Enter the name of Player #" + (i +1) + ": ");
    numPlay[i] = SimpleIO.readLine().trim();
    }
    DrawableFrame df = new DrawableFrame ("NFL Gameday 6");
    df.show();
    df.setSize(200*5,100*5);

    Graphics ff = df.getGraphicsContext();
    ff.setColor(Color.white);
    ff.setColor(Color.green);
    ff.fillRect(10,10,140*5,80*5);

    ff.setColor(Color.white);
    ff.drawRect(20,20*5,135*5,40*5);

    ff.drawLine(20*5,100,20*5,300);
    ff.drawLine(120*5,100,120*5,300);
    ff.drawLine(30*5,100,30*5,300);
    ff.drawLine(40*5,100,40*5,300);
    ff.drawLine(50*5,100,50*5,300);
    ff.drawLine(60*5,100,60*5,300);
    ff.drawLine(70*5,100,70*5,300);
    ff.drawLine(80*5,100,80*5,300);
    ff.drawLine(90*5,100,90*5,300);
    ff.drawLine(100*5,100,100*5,300);
    ff.drawLine(110*5,100,110*5,300);

    ff.drawString("Goal",90,90);
    ff.drawString("Goal",90,320);

    ff.drawString("10",29*5,90);
    ff.drawString("10",29*5,320);

    ff.drawString("20",39*5,90);
    ff.drawString("20",39*5,320);

    ff.drawString("30",49*5,90);
    ff.drawString("30",49*5,320);

    ff.drawString("40",59*5,90);
    ff.drawString("40",59*5,320);

    ff.drawString("50",69*5,90);
    ff.drawString("50",69*5,320);

    ff.drawString("40",79*5,90);
    ff.drawString("40",79*5,320);

    ff.drawString("30",89*5,90);
    ff.drawString("30",89*5,320);

    ff.drawString("20",99*5,90);
    ff.drawString("20",99*5,320);

    ff.drawString("10",109*5,90);
    ff.drawString("10",109*5,320);

    ff.drawString("Goal",118*5,90);
    ff.drawString("Goal",118*5,320);

    ff.drawString("ENDZONE",29,23*5);
    ff.drawString("ENDZONE",29,59*5);
    ff.drawString("ENDZONE",123*5,23*5);
    ff.drawString("ENDZONE",123*5,59*5);

    int[] xOuter = {800,851,902,902,851,800,749,749};
    int[] yOuter = {10,10,61,112,163,163,112,61};
    int[] xInner = {805,846,897,897,846,805,754,754};
    int[] yInner = {15,15,66,107,158,158,107,66};
    ff.setColor(Color.black);
    ff.drawPolygon (xOuter, yOuter, xOuter.length);

    ff.setColor(Color.red);
    ff.fillPolygon(xInner, yInner, xInner.length);

    ff.setColor(Color.white);
    ff.setFont (new Font ("SansSerif", Font.BOLD, 80));

    ff.drawString(numPlay[i],10,10);

    df.repaint();

    }
    }

  2. #2
    Horcrux7 is offline Member
    Join Date
    Sep 2010
    Posts
    33
    Rep Power
    0

    Default

    How look your DrawableFrame? Do you use this code http://knking.com/books/java/jpb/DrawableFrame.java ?

    It is a very bad sample. Every resize will be clear your painting. Better is you write it directly in the paint method. Or you write it if the image is recreated.
    Volker Berlin
    www.inetsoftware.de

Similar Threads

  1. Java Graphics
    By keaton1ao in forum New To Java
    Replies: 12
    Last Post: 11-16-2010, 09:19 PM
  2. Replies: 2
    Last Post: 01-16-2010, 05:50 PM
  3. java graphics question
    By bobCallahan24 in forum AWT / Swing
    Replies: 1
    Last Post: 01-15-2010, 07:04 AM
  4. Java Graphics
    By svaidya in forum New To Java
    Replies: 8
    Last Post: 12-07-2009, 06:11 PM
  5. Want to learn Java Graphics
    By loggen in forum New To Java
    Replies: 7
    Last Post: 01-03-2009, 05:15 PM

Posting Permissions

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