Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 24 of 24

Thread: Help some graphic java problem

  1. #1
    Junior Member
    Join Date
    Sep 2011
    Posts
    13
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Default Help some graphic java problem

    Hey, im new here.. obviously still a newbie.. i got a few question..
    This 4 file, when i try to run them it works, but then they become funny when u click 1 of the color at the bottom, i need to minimize and maximize it to fix it.. any idea wads wrg? i cant find out the reason.
    And also at the end of the game.. i get this Exception in thread error.. , oh and also since this is not the whole thing, need to close it with terminate
    Exception in thread "AWT-EventQueue-0" java.lang.ArrayIndexOutOfBoundsException: 10
    	at MastermindFrame.fillBoard(MastermindFrame.java:77)
    	at MastermindFrame.paint(MastermindFrame.java:60)
    	at javax.swing.JComponent.paintChildren(Unknown Source)
    	at javax.swing.JComponent.paint(Unknown Source)
    	at javax.swing.JComponent.paintChildren(Unknown Source)
    	at javax.swing.JComponent.paint(Unknown Source)
    	at javax.swing.JLayeredPane.paint(Unknown Source)
    	at javax.swing.JComponent.paintChildren(Unknown Source)
    	at javax.swing.JComponent.paintToOffscreen(Unknown Source)
    	at javax.swing.RepaintManager$PaintManager.paintDoubleBuffered(Unknown Source)
    	at javax.swing.RepaintManager$PaintManager.paint(Unknown Source)
    	at javax.swing.RepaintManager.paint(Unknown Source)
    	at javax.swing.JComponent.paint(Unknown Source)
    	at java.awt.GraphicsCallback$PaintCallback.run(Unknown Source)
    	at sun.awt.SunGraphicsCallback.runOneComponent(Unknown Source)
    	at sun.awt.SunGraphicsCallback.runComponents(Unknown Source)
    	at java.awt.Container.paint(Unknown Source)
    	at java.awt.Window.paint(Unknown Source)
    	at javax.swing.RepaintManager.paintDirtyRegions(Unknown Source)
    	at javax.swing.RepaintManager.paintDirtyRegions(Unknown Source)
    	at javax.swing.RepaintManager.seqPaintDirtyRegions(Unknown Source)
    	at javax.swing.SystemEventQueueUtilities$ComponentWorkRequest.run(Unknown Source)
    	at java.awt.event.InvocationEvent.dispatch(Unknown Source)
    	at java.awt.EventQueue.dispatchEvent(Unknown Source)
    	at java.awt.EventDispatchThread.pumpOneEventForFilters(Unknown Source)
    	at java.awt.EventDispatchThread.pumpEventsForFilter(Unknown Source)
    	at java.awt.EventDispatchThread.pumpEventsForHierarchy(Unknown Source)
    	at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
    	at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
    	at java.awt.EventDispatchThread.run(Unknown Source)

     
    import java.awt.BorderLayout;
    import java.awt.Color;
    import java.awt.Dimension;
    import java.awt.event.WindowAdapter;
    import java.awt.event.WindowEvent;
     
    import javax.swing.Action;
    import javax.swing.JButton;
    import javax.swing.JFrame;
    import javax.swing.JMenu;
    import javax.swing.JMenuBar;
    import javax.swing.JMenuItem;
     
     
    @SuppressWarnings("serial")
    public class Frame extends JFrame {
     
     
    	// Game control actions
    	private Action newAction;
    	private Action quitAction;
     
    	// User account control actions
    	private Action loginAction;
    	private Action registerAction;
    	private Action logoffAction;
     
     
    	private MastermindFrame mastermindframe;
     
     
    	// Window listener
    	private class FrameWindowListener extends WindowAdapter {
     
    		/** Invokes quit action when closing window */
    		@Override
    		public void windowClosing(WindowEvent we) {
    			quitAction.actionPerformed(null);
    		}
    	}
     
    	/** Create a new frame. */
    	public Frame() {
     
    		mastermindframe = new MastermindFrame();
    		mastermindframe.reset();
    		mastermindframe.setVisible(true);
     
    		setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    		addWindowListener(new FrameWindowListener());
     
    		// Create menu bar
    		JMenuBar menuBar = new JMenuBar();
    		add(menuBar, BorderLayout.NORTH);
     
    		JMenu gameMenu = new JMenu("Game");
    		gameMenu.add(new JMenuItem(newAction));
    		gameMenu.add(new JMenuItem(quitAction));
     
    		JMenu userMenu = new JMenu("User");
    		userMenu.add(new JMenuItem(registerAction));
     
    		menuBar.add(gameMenu);
    		menuBar.add(userMenu);
     
    		JButton submit = new JButton( "Submit guess" );
            submit.addActionListener(mastermindframe);
            addMouseListener(mastermindframe);
     
    		setLayout(new BorderLayout());
            setBackground( Color.white );
            add(menuBar, BorderLayout.NORTH);
            getContentPane().add(mastermindframe, BorderLayout.CENTER);
            getContentPane().add(submit, BorderLayout.SOUTH);
            //setSize( new Dimension( 220, 450 ) );
            setVisible( true );
    		this.setMinimumSize(new Dimension(400, 360));
     
    		// Create the playing board.
    		//PlayBoard playBoard = new PlayBoard(null);
    		//getContentPane().add(playBoard);
     
    		setTitle("Mastermind");
     
    		pack();
    	}
     
     
    }

    /** Game client entry point, where the game client start */
    public class StartClient {
     
    	/** Client entry point with no argument. */
    	public static void main(String[] args) {
    		Frame frame = new Frame();
    		frame.setVisible(true);
    	}
     
    }


    import java.awt.Color;
    import java.awt.Graphics;
    import java.awt.GridLayout;
    import java.awt.event.ActionEvent;
    import java.awt.event.ActionListener;
    import java.awt.event.MouseEvent;
    import java.awt.event.MouseListener;
    import java.util.ArrayList;
     
    import javax.swing.JButton;
    import javax.swing.JPanel;
     
    public class MastermindFrame extends JPanel implements MouseListener, ActionListener{
    	private static MastermindFrame instance = new MastermindFrame();
    	private static final int ROWS = 10;
    	private int dw, dh, currentColor, currentRow, turn;
    	private Color guesses[][] = new Color[ROWS][4];
    	private Color responses[][] = new Color[10][4];
    	private Color colors[] = { Color.blue,  Color.green, Color.yellow, Color.red, Color.black, Color.LIGHT_GRAY };
    	private int[] input = new int[4], bw = new int[2];
     
    	private Game Model = new Game();
    	//public JPanel Pane = new JPanel();
     
     
    	private boolean displayAnswer;
     
    	public static MastermindFrame getInstance()
    	{
    		return instance;
    	}
     
    	/*public void addMouseListener(MouseListener m1)
    	{
    		Pane.addMouseListener(m1);
    	}*/
    	/*public MastermindFrame()
    	{
    		this.setVisible(true);
    	}*/
     
    	public void reset() {
    	    for (int i=0; i < ROWS; i++)
    	      for (int j=0; j < 4; j++) {
    	        guesses[i][j] = Color.white;
    	        responses[i][j] = Color.gray;
    	      }
    	    turn = 0;
    	    currentRow = 0;
    	    currentColor = 0;
    	    displayAnswer = false;
    	  }
     
     
    	 public void paint( Graphics g ) 
    	 {
    		    dw = (int) getSize().width / 7;
    		    dh = (int) getSize().height / (ROWS+3);
    		    fillBoard( g );
    		    drawBoard( g );
    	 }
     
    		  private void fillBoard( Graphics g ) 
    		  {
    		    if (displayAnswer) 
    		    {
    		      int[] answer = Model.getanswer();
    		      for (int j=0; j < 4; j++) 
    		      {
    		        g.setColor( colors[answer[j]] );
    		        g.fillRect( dw*j+dw, 0, dw, dh );
    		      } 
    		    }
    		    for (int i=0; i <= currentRow; i++)
    		      for (int j=0; j < 4; j++) {
    		        g.setColor( guesses[i][j] );
    		        g.fillRect( dw*(j+1), dh*(i+1), dw, dh );
    		      }
    		    for (int i=0; i < currentRow; i++)
    		      for (int j=0; j < 4; j++) {
    		        g.setColor( responses[i][j] );
    		        g.fillRect( 5*dw+j%2*dw/2, dh*(i+1)+j/2*dh/2, dw/2, dh/2 );
    		      }   
    		  }
     
    		  private void drawBoard( Graphics g ) {
    		    g.setColor( Color.black );
    		    // draw rows
    		    for (int i=0; i < ROWS+1; i++)
    		      g.drawLine( dw, dh*(i+1), 6*dw, dh*(i+1) );
    		    // draw col
    		    for (int i=0; i <  6; i++)
    		      g.drawLine( dw*(i+1), dh, dw*(i+1), (ROWS+1)*dh );
    		    // draw the peg line
    		    for (int i=0; i < ROWS; i++)
    		      g.drawLine( dw*5, (i+1)*dh+dh/2, dw*6, (i+1)*dh+dh/2 );  
    		    // draw the peg line
    		    g.drawLine( dw*5+dw/2, dh, dw*5+dw/2, dh*(ROWS+1) );  
    		    // draw the color 
    		    for (int i=0; i < 6; i++) {
    		      g.setColor( colors[i] );
    		      g.fillRect( i*dw+dw/2, dh*(ROWS+1)+dh/2, dw, dh );  
    		  } }
     
    		@Override
    		public void mouseClicked(MouseEvent e) {
    			// TODO Auto-generated method stub
     
    		}
     
    		@Override
    		public void mouseEntered(MouseEvent e) {
    			// TODO Auto-generated method stub
     
    		}
     
    		@Override
    		public void mouseExited(MouseEvent e) {
    			// TODO Auto-generated method stub
     
    		}
     
    		@Override
    		public void mousePressed(MouseEvent e) {
    			// TODO Auto-generated method stub
    			int x = e.getX(), y = e.getY();
    		    // click above the board
    		    if (y < dh) 
    		    {                        
    		      displayAnswer = ! displayAnswer;    
    		      repaint();
    		    } 
    		    else if (y < dh*(ROWS+1)+dh/2) 
    		    {    // place a color
    		      x = (x - dw) / dw;                  
    		      input[x] = currentColor;
    		      guesses[currentRow][x] = colors[currentColor];
    		      repaint(); 
    		    } 
    		    else 
    		    {                              // click below the board
    		      currentColor = (x - dw/2) / dw;     // to select a color
    		      System.out.println( "color is " + currentColor );
    		      int[] j = Model.getanswer();
    		      for(int i=0; i<j.length; i++)
    		      {
    		    	  System.out.print(j[i]);
    		      }
    		    }
    		}
     
    		@Override
    		public void mouseReleased(MouseEvent e) {
    			// TODO Auto-generated method stub
     
    		}
     
    		@Override
    		public void actionPerformed(ActionEvent e) {
    			// TODO Auto-generated method stub
    			 if (e.getActionCommand().equals("Submit guess")) {
    			      Model.guess( input, bw );
    			      for (int i=0; i < bw[0]; i++)
    			        responses[currentRow][i] = Color.black;
    			      for (int i=bw[0]; i < bw[0]+bw[1]; i++)
    			        responses[currentRow][i] = Color.white;
    			      currentRow++;
    			      turn++;
    			      if (bw[0] == 4)
    			      {
    			    	  if(turn >= 0 && turn <=3)
    			    	  {
    			    		  if(turn == 0)
    			    		  {
    			    			  //10 point
    			    		  }else if (turn == 1)
    			    		  {
    			    			  //9
    			    		  }else if (turn == 2)
    			    		  {
    			    			  //8
    			    		  }else if (turn == 3)
    			    		  {
    			    			  //7
    			    		  }
     
    			    		  System.out.println("You are genius");
    			    	  }
    			    	  else if(turn >=4 && turn <=7)
    			    	  {
    			    		  System.out.println("You are good");
    			    		  if(turn == 4)
    			    		  {
    			    			  //6
    			    		  }else if (turn == 5)
    			    		  {
    			    			  //5
    			    		  }else if (turn == 6)
    			    		  {
    			    			  //4
    			    		  }else if (turn == 7)
    			    		  {
    			    			  //3
    			    		  }
    			    	  }else if (turn <= 9)
    			    	  {
    			    		  System.out.println("You are not bad");
    			    		  if(turn == 8)
    			    		  {
    			    			  //score = 2
    			    		  }else if (turn == 9)
    			    		  {
    			    			  //score = 1
    			    		  }
    			    	  }
     
    			        ((JButton)e.getSource()).setText( "Go again?" );
    			        Model.reset();
    			      }
    			    } else {
     
    			      ((JButton)e.getSource()).setText( "Submit guess" );
    			      reset();
    			    }
    			    repaint();
    		}
    }

    import java.io.Serializable;
    import java.util.ArrayList;
    import java.util.Random;
     
    /**
     * Game object describe a game, the object can be serialized and save to file
     * for resuming.
     * 
     * @author Lin
     */
    @SuppressWarnings("serial")
    public class Game implements Serializable {
    	//static final + random no generator
    	private Random rn     = new Random();
    	public static final int NUMBER_OF_POSITIONS = 4;
    	public static final int MAXIMUM_VALUE = 5;
     
    	/** The secret code for the game */
    	//private final String secretCode;
     
    	/** Guesses from user for this game */
    	private ArrayList<String> guesses;
     
    	private boolean finished;
     
    	//answer n stuff
    	private static int[]  answer = new int[NUMBER_OF_POSITIONS];
    	private int answerSums[] = new int[MAXIMUM_VALUE+1];
     
    	/** Creates a new game. */
    	public Game()//(String secretCode) 
    	{
    		/*assert secretCode.length() == 4;
     
    		this.secretCode = secretCode;
    		this.guesses = new ArrayList<String>();
     
    		this.finished = false;*/
     
    		//random number generator
    		 for (int i=0; i < answer.length; i++)
    			    answer[i] = rn.nextInt( answerSums.length );
     
    			  // Initialize the answer housekeeping array
    			  for (int i=0; i < answer.length; i++)
    			    answerSums[ answer[i] ]++;
    	}
     
    	/**
    	 * Add the attempt to guess history, and return the game state.
    	 * 
    	 * @param guess
    	 * @return true if game is finished, false if not
    	 */
    	/*public boolean newGuess(String guess) {
    		assert guess.length() == 4 && finished == false;
     
    		guesses.add(guess);
    		return finished = guess.equalsIgnoreCase(secretCode)
    				|| guesses.size() == 10;
    	}*/
     
    	/** Accessor for secret code. */
    	public int[] getanswer()
    	{
    		return answer;
    	}
    	/*public String getSecretCode() {
    		return this.secretCode;
    	}*/
     
    	/** Accessor for attempts, return {@code null} if no attempt made. */
    	/*public String[] getGuesses() {
    		if (guesses.isEmpty())
    			return null;
     
    		return guesses.toArray(new String[0]);
    	}*/
     
    	/**
    	 * Gets the feedback for a user attempt.
    	 * 
    	 * @param guess
    	 * @return the feedback for the guess
    	 */
    	/*public String getFeedback(String guess) {
    		assert guess.length() == 4;
    		// TODO method uncompleted
     
    		return "BBBB";
    	}*/
    	public void guess( int[] input, int[] bw ) 
    	  {
    		  bw[0] = bw[1] = 0;
     
    		  // Initialize the input housekeeping array
    		  int[] inputSums = new int[answerSums.length];
    		  for (int i=0; i < answer.length; i++)
    		    inputSums[ input[i] ]++;
     
    		  // Compute the total
    		  for (int i=0; i < answerSums.length; i++)
    		    bw[1] += (inputSums[i] < answerSums[i]) ? inputSums[i] : answerSums[i];
     
    		  // Compute the black response
    		  for (int i=0; i < answer.length; i++)
    		    if (input[i] == answer[i])
    		      bw[0]++;
     
    		  // Now, derive the white response
    		  bw[1] = bw[1] - bw[0];
    	  }
     
    	//reset code for new game
    	public void reset() {
    		for (int i=0; i < answer.length; i++)
    		    answer[i] = rn.nextInt( answerSums.length );
     
    		  // Initialize the answer housekeeping array
    		  for (int i=0; i < answer.length; i++)
    		    answerSums[ answer[i] ]++;
    		// TODO Auto-generated method stub
     
    	} 
     
    }


  2. #2
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    20,992
    Thanks
    52
    Thanked 2,274 Times in 2,245 Posts

    Default Re: Help some graphic java problem

    java.lang.ArrayIndexOutOfBoundsException: 10
    at MastermindFrame.fillBoard(MastermindFrame.java:77)
    Look at the code at line 77 and see how the index can be past the end of the array.
    Add a println before line 77 to show the value of the index if you don't see how it can be OOB.

  3. #3
    Junior Member
    Join Date
    Sep 2011
    Posts
    13
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Default Re: Help some graphic java problem

    Ah i think i see where the problem is now, but how can i fix it? any tips?

  4. #4
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    20,992
    Thanks
    52
    Thanked 2,274 Times in 2,245 Posts

    Default Re: Help some graphic java problem

    I don't know where line 77 is so I can't suggest any fixes.
    What values printed out when you added the println to show the value of the indexes being used on that line?
    The basic fix is to check the value of an index and NOT use it if its value is not in bounds for the array.

  5. #5
    Junior Member
    Join Date
    Sep 2011
    Posts
    13
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Default Re: Help some graphic java problem

    it's the g.setColor(guesses[i][j]); From MastermindFrame.java . I tried everything i could but still cant find out how to fix it T.T

      private void fillBoard( Graphics g ) 
    		  {
    		    if (displayAnswer) 
    		    {
    		      int[] answer = Model.getanswer();
    		      for (int j=0; j < 4; j++) 
    		      {
    		        g.setColor( colors[answer[j]] );
    		        g.fillRect( dw*j+dw, 0, dw, dh );
    		      } 
    		    }
    		    for (int i=0; i <= currentRow; i++)
    		      for (int j=0; j < 4; j++) {
    //Line 77 is here	  g.setColor( guesses[i][j] );
    		        g.fillRect( dw*(j+1), dh*(i+1), dw, dh );
    		      }
    		    for (int i=0; i < currentRow; i++)
    		      for (int j=0; j < 4; j++) {
    		        g.setColor( responses[i][j] );
    		        g.fillRect( 5*dw+j%2*dw/2, dh*(i+1)+j/2*dh/2, dw/2, dh/2 );
    		      }   
    		  }

  6. #6
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    20,992
    Thanks
    52
    Thanked 2,274 Times in 2,245 Posts

    Default Re: Help some graphic java problem

    What are the values of i and j and currentRow when the OOBE occurs?
    What are the dimensions of the guesses array?

  7. #7
    Junior Member
    Join Date
    Sep 2011
    Posts
    13
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Default Re: Help some graphic java problem

    the dimensions of the guesses array is Color guesses[][] = new Color[ROWS][4];
    Oh and ROWS is set to static final int 10;

    it's probably easier for u to c if u try running it


    below r the print out.. lol
    java.awt.Color[r=0,g=0,b=255]
    java.awt.Color[r=0,g=255,b=0]
    java.awt.Color[r=255,g=255,b=0]
    java.awt.Color[r=255,g=0,b=0]
    java.awt.Color[r=255,g=255,b=255]
    java.awt.Color[r=255,g=255,b=255]
    java.awt.Color[r=255,g=255,b=255]
    java.awt.Color[r=255,g=255,b=255]
    java.awt.Color[r=255,g=255,b=255]
    java.awt.Color[r=255,g=255,b=255]
    java.awt.Color[r=255,g=255,b=255]
    java.awt.Color[r=255,g=255,b=255]
    java.awt.Color[r=255,g=255,b=255]
    java.awt.Color[r=255,g=255,b=255]
    java.awt.Color[r=255,g=255,b=255]
    java.awt.Color[r=255,g=255,b=255]
    java.awt.Color[r=255,g=255,b=255]
    java.awt.Color[r=255,g=255,b=255]
    java.awt.Color[r=255,g=255,b=255]
    java.awt.Color[r=255,g=255,b=255]
    java.awt.Color[r=255,g=255,b=255]
    java.awt.Color[r=255,g=255,b=255]
    java.awt.Color[r=255,g=255,b=255]
    java.awt.Color[r=255,g=255,b=255]
    java.awt.Color[r=255,g=255,b=255]
    java.awt.Color[r=255,g=255,b=255]
    java.awt.Color[r=255,g=255,b=255]
    java.awt.Color[r=255,g=255,b=255]
    java.awt.Color[r=255,g=255,b=255]
    java.awt.Color[r=255,g=255,b=255]
    java.awt.Color[r=255,g=255,b=255]
    java.awt.Color[r=255,g=255,b=255]
    java.awt.Color[r=255,g=255,b=255]
    java.awt.Color[r=255,g=255,b=255]
    java.awt.Color[r=255,g=255,b=255]
    java.awt.Color[r=255,g=255,b=255]
    java.awt.Color[r=255,g=255,b=255]
    java.awt.Color[r=255,g=255,b=255]
    java.awt.Color[r=255,g=255,b=255]
    java.awt.Color[r=255,g=255,b=255]
    Last edited by Nick0920; September 3rd, 2011 at 09:38 AM.

  8. #8
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    20,992
    Thanks
    52
    Thanked 2,274 Times in 2,245 Posts

    Default Re: Help some graphic java problem

    Your print out does not show anything useful to help find the problem.

    What are the values of i and j and currentRow when the OOBE occurs?

  9. #9
    Junior Member
    Join Date
    Sep 2011
    Posts
    13
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Default Re: Help some graphic java problem

    hmm when it occur, i :10 and j :0

  10. #10
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    20,992
    Thanks
    52
    Thanked 2,274 Times in 2,245 Posts

    Default Re: Help some graphic java problem

    The value of i=10 is past the end of the array. The valid indexes are 0-9.
    Check your logic to see how i can be > 9

  11. #11
    Junior Member
    Join Date
    Sep 2011
    Posts
    13
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Default Re: Help some graphic java problem

    ah found the problem.. thanks alot Norm.. haha great help. 1 more question tho, when i run that as app, the graphic will become something like this
    BuggedApp.jpg

    After i minimize and maximize the screen it go back to normal.

    afterminmax.jpg

  12. #12
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    20,992
    Thanks
    52
    Thanked 2,274 Times in 2,245 Posts

    Default Re: Help some graphic java problem

    Can you explain what the difference is between those two images?
    One thing I noticed: you call setVisible BEFORE you are finished getting all of the GUI ready to be viewed. Do setVisible after everything is ready.

  13. #13
    Junior Member
    Join Date
    Sep 2011
    Posts
    13
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Default Re: Help some graphic java problem

    ah ok thank bout that, will change it. Oh and about the image, in the 1st image u can see alot of line, the row r suppose to be 10 and 5(4 + 1*for the feedback*), but in the 1st image it gets blurry after i mouse left click the app screen, and i need to resize it *minimize the app and maximize it again* to fix it and make it look like normal which is image 2.

  14. #14
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    20,992
    Thanks
    52
    Thanked 2,274 Times in 2,245 Posts

    Default Re: Help some graphic java problem

    in the 1st image it gets blurry
    Are you talking about where the fillRect methods puts the colors?
    Look at the parameters passed to those methods to see why they aren't what they should be.

  15. #15
    Junior Member
    Join Date
    Sep 2011
    Posts
    13
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Default Re: Help some graphic java problem

    hmm not those fillRect, it's those line, if u look closely to those line u can see double line in pic 1 and pic 2 *which is after i minimize and maximize the screen* looks normal.

  16. #16
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    20,992
    Thanks
    52
    Thanked 2,274 Times in 2,245 Posts

    Default Re: Help some graphic java problem

    Where are the lines begin drawn? What variables control where the lines are drawn?

  17. #17
    Junior Member
    Join Date
    Sep 2011
    Posts
    13
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Default Re: Help some graphic java problem

    ah got a clearer pic for u
    pic 1 wad it suppose to look like, but after i click the frame screen it become pic 2, then i need to resize the window for it to become like pic 1 again
    pic 1 - ImageShack&#174; - Online Photo and Video Hosting

    pic 2 - ImageShack&#174; - Online Photo and Video Hosting

  18. #18
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    20,992
    Thanks
    52
    Thanked 2,274 Times in 2,245 Posts

    Default Re: Help some graphic java problem

    Have you looked at the code that draws the lines that are the problem?
    What variables controls where the lines are drawn?
    How do those variables get their values?

  19. The Following User Says Thank You to Norm For This Useful Post:

    Nick0920 (September 3rd, 2011)

  20. #19
    Junior Member
    Join Date
    Sep 2011
    Posts
    13
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Default Re: Help some graphic java problem

    hmm the line drawing looks fine i think, i mean cause in pic 2 , even the menubar on top gets the blurry effect too. Not only the line and colors.
    dw = (int) getSize().width / 7;
    dh = (int) getSize().height / (ROWS+3);
    // draw rows
    for (int i=0; i < ROWS+1; i++)
    g.drawLine( dw, dh*(i+1), 6*dw, dh*(i+1) );
    // draw col
    for (int i=0; i < 6; i++)
    g.drawLine( dw*(i+1), dh, dw*(i+1), (ROWS+1)*dh );
    // draw the peg line
    for (int i=0; i < ROWS; i++)
    g.drawLine( dw*5, (i+1)*dh+dh/2, dw*6, (i+1)*dh+dh/2 );
    // draw the peg line
    g.drawLine( dw*5+dw/2, dh, dw*5+dw/2, dh*(ROWS+1) );

  21. #20
    Junior Member
    Join Date
    Sep 2011
    Posts
    13
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Default Re: Help some graphic java problem

    Anyway, im gonna try to find out wads the problem with the graphic tomorrow well .. later lol cause 2.30 am here already. Thanks alot for you help just now Norm.

  22. #21
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    20,992
    Thanks
    52
    Thanked 2,274 Times in 2,245 Posts

    Default Re: Help some graphic java problem

    even the menubar on top gets the blurry effect
    I have no idea what can cause that. I don't see it on my PC.
    What versions of OS, JDK, IDE are you using?

  23. #22
    Junior Member
    Join Date
    Sep 2011
    Posts
    13
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Default Re: Help some graphic java problem

    hmm u tried the code and u didnt c it? , that's funny.. using window 7 64bit atm.
    my eclipse platform version 3.6.2.r362_v20110210-9gF78Gs1FrIGnHDHWkEcopoN8AmxeZflGDGKQi

    java version "1.7.0"

  24. #23
    Junior Member
    Join Date
    Sep 2011
    Posts
    13
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Default Re: Help some graphic java problem

    even the menubar on top gets the blurry effect

    I have no idea what can cause that. I don't see it on my PC.
    What versions of OS, JDK, IDE are you using?
    hmm , the blurry effect as in after i click the screen i can see double menubar on top and double submit at the bottom, and my middle line graph.. well double as well.

  25. #24
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    20,992
    Thanks
    52
    Thanked 2,274 Times in 2,245 Posts

    Default Re: Help some graphic java problem

    I'm on XP and java 1.6

Similar Threads

  1. Help in making an output for this Graphic (newbie)
    By javarum in forum AWT / Java Swing
    Replies: 49
    Last Post: June 27th, 2011, 06:22 PM
  2. Java graphic coordinates out of bounds?
    By jnmcneel in forum What's Wrong With My Code?
    Replies: 4
    Last Post: May 24th, 2011, 03:28 PM
  3. how to adjust the size on a graphic component
    By Khoatic in forum AWT / Java Swing
    Replies: 8
    Last Post: November 19th, 2010, 10:28 PM
  4. Graphic angle
    By CoffeeBeans in forum Java Theory & Questions
    Replies: 1
    Last Post: August 22nd, 2010, 11:28 AM
  5. Graphic Environment Abstract Methods
    By striko_514 in forum Java Theory & Questions
    Replies: 2
    Last Post: July 5th, 2010, 01:01 AM