Results 1 to 3 of 3
  1. #1
    Miljan is offline Member
    Join Date
    May 2016
    Posts
    3
    Rep Power
    0

    Smile Applet Viewer and Graphics Program are not displaying the right size;

    Hi guys,
    I am new to Java programming so I apologize up front for sometimes wrong terminology or similar mistakes :) That is why I am here, to learn.
    So, I need to do this assignment Applet Viewer and Graphics Program are not displaying the right size;-checkerboard.png
    Here is my code, which works well by the way.


    import acm.graphics.*;
    import acm.graphics.*;

    public class Checkerboard extends GraphicsProgram {
    private static final int NROWS = 8;
    private static final int NCOLUMNS = 8;

    public void run() {

    int sqSize = getHeight() / NROWS;

    for (int i = 0; i < NROWS; i++){
    for (int j = 0; j < NCOLUMNS; j++){
    int x = j * sqSize;
    int y = i * sqSize;
    GRect sq = new GRect(x, y, sqSize, sqSize);
    GOval oval = new GOval(x + 8, y + 8, sqSize - 15, sqSize - 15);
    if((i+j)%2 != 0 ){
    add(oval);
    }
    add(sq);
    }
    }

    When I hit run button in Applet Viewer I am getting too small Checkerboard Applet Viewer and Graphics Program are not displaying the right size;-applet.png, I thought that if I use this getHeight() method and divide it with NROWS I will have 8 rows across whole graphics (applet viewer) screen.

    If someone can explain to me what are the rolls of getHeight() and getWidth() methods ?

  2. #2
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    Eastern Florida
    Posts
    20,001
    Rep Power
    33

    Default Re: Applet Viewer and Graphics Program are not displaying the right size;

    Can you post a complete program that compiles, executes and shows the problem?
    Be sure to wrap the code in code tags.

    what are the rolls of getHeight() and getWidth() methods ?
    Have you tried printing out the values returned by those methods so you can see what they are?

    Note: Not many people here use the acm packages and there might not be anyone that is familiar with them.
    If you don't understand my response, don't ignore it, ask a question.

  3. #3
    Miljan is offline Member
    Join Date
    May 2016
    Posts
    3
    Rep Power
    0

    Default Re: Applet Viewer and Graphics Program are not displaying the right size;

    XML Code:
    import acm.program.*;
    import acm.graphics.*;
    
    public class Checkerboard extends GraphicsProgram {
    	private static final int NROWS = 8;
    	private static final int NCOLUMNS = 8;
    	
    	public void run() {
    		
    		int sqSize = getHeight() / NROWS;
    		
    		for (int i = 0; i < NROWS; i++){
    			for (int j = 0; j < NCOLUMNS; j++){
    				int x = j * sqSize;
    				int y = i * sqSize;
    				GRect sq = new GRect(x, y, sqSize, sqSize);
    				GOval oval = new GOval(x + 8, y + 8, sqSize - 15, sqSize - 15);
    				if((i+j)%2 != 0 ){
    				add(oval);
    				}
    				add(sq);
    			}
    		}
    I dont know how exactly to print out those values since I am working in Console Program, I can just put object (like GRect, GOval...) on canvas (graphics window). If I am not mistaken.

Similar Threads

  1. Need help with Eclipse Applet Viewer
    By karln in forum Eclipse
    Replies: 2
    Last Post: 08-22-2012, 09:08 AM
  2. cant change the size of the applet viewer
    By nabil in forum Java Applets
    Replies: 7
    Last Post: 02-13-2012, 03:49 PM
  3. applet working in applet viewer, not browser
    By plasticfood in forum Java Applets
    Replies: 4
    Last Post: 06-24-2011, 06:47 PM
  4. Changing default Applet Viewer Size?
    By dsym@comcast.net in forum Java Applets
    Replies: 6
    Last Post: 08-27-2010, 06:42 PM
  5. Eclipse Applet Viewer not showing graphics?
    By sjchase in forum Java Applets
    Replies: 1
    Last Post: 04-17-2008, 04:16 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
  •