I have several different classes and they have graphics in them. I told java to repaint in a class class called LongitudinalWaveGraphics, but it repaints a class called ResistorCCGraphics. Why is this? Thanks for the help. if you need any codes then I can post them.

Can you post the code you are describing?
How did you call repaint()?

Have you added debug println statements to verify which repaint() calls are being made and which paint methods are called and in what order?

the code it should print

import java.awt.*;
import java.awt.event.*;
import javax.swing.*;


public class LongitudinalWaveGraphics extends JPanel{

	int [] x = new int [50];
	int [] y = new int [4];
	
	public void LongDraw (){
		
		for (int i = 0; i < 50; i++){
			x [i] = (15 * i);
		}
		for (int i = 0; i < 4; i++){
			if (i % 4 == 0){
				y[i] = 50;
			}
			else if (i % 3 == 0){
				y[i] = 60;
			}
			else if (i % 2 == 0){
				y[i] = 70;
			}
			else if (i % 1 == 0){
				y[i] = 80;
			}
		}
		
		
		repaint();
	}
	
	
	public void graphicsComponent (Graphics g){
		for (int i = 0; i< 50; i++){
			for (int z = 0; z < 4; z++){
				g.fillOval(x[i], y[z], 10, 10);
			}
		}
		
	}
	
	
}

The ResistorCCGraphics that it prints

import java.awt.Container;
import java.awt.Graphics;
import java.awt.event.*;
import java.awt.*;
import javax.swing.*;


public class ResistorColorCodeGraphics extends JPanel{

	Image base, black, brown, red, orange, yellow, green, blue, violet, gray, white, click;
	int ring1Col, ring2Col, ring3Col;
	Image ring1, ring2, ring3;
	
	public void ColorCodeDraw (){
		base = getToolkit().getImage("ResistorCCImages\\Resistor Base.gif");
		black = getToolkit().getImage("ResistorCCImages\\Black Ring.gif");
		brown = getToolkit().getImage("ResistorCCImages\\Brown Ring.gif");
		red = getToolkit().getImage("ResistorCCImages\\Red Ring.gif");
		orange = getToolkit().getImage("ResistorCCImages\\Orange Ring.gif");
		yellow = getToolkit().getImage("ResistorCCImages\\Yellow Ring.gif");
		green = getToolkit().getImage("ResistorCCImages\\Green Ring.gif");
		blue = getToolkit().getImage("ResistorCCImages\\Blue Ring.gif");
		violet = getToolkit().getImage("ResistorCCImages\\Violet Ring.gif");
		gray = getToolkit().getImage("ResistorCCImages\\Gray Ring.gif");
		white = getToolkit().getImage("ResistorCCImages\\White Ring.gif");
		click = getToolkit().getImage("ResistorCCImages\\ClickRing.gif");
		
		repaint();
	}
	
	public void paintComponent (Graphics g){
	
		
		g.drawImage (base, 0, 50, 500, 350, this);
		g.drawImage (click, 125, 129, 166, 175, this);
		g.drawImage (click, 165, 129, 166, 175, this);
		g.drawImage (click, 205, 129, 166, 175, this);
		g.drawImage (ring1 , 50,50,50,50,this);
		}
	
	
	
	public void firstRing (int col){
		if (col == 0){
			ring1 = black;
		}
		System.out.println ("First ring: " + col);
	}
	public void secondRing (int col){
		System.out.println ("Second ring: " + col);
		
	}
	public void thirdRing (int col){
		System.out.println ("Third ring: " + col);
		
	}

	public void printRings(int ringsel, int col) {
		if (ringsel == 1){
			
		}
		
	}
}

Thanks for your help.

by any chance you're using jGRASP? I know that using jGRASP this happens frequently. If so, look for a Run menu on your menu bar, and there you have 'Make this main project' or something... this is of course assuming you are sure you're not adding Resistor... instead of Longitude... panel to your frame.

Can you post the code you are describing?

What you posted is not the code that calls repaint. It is the code that is called after a call to repaint.
How did you call repaint()?

Have you added debug println statements to verify which repaint() calls are being made and which paint methods are called and in what order?

Did you try debugging your code? What was printed out?

Edited 5 Years Ago by NormR1: n/a

When I run the longitudinal wave code it prints out the resistor code. Here are all the codes involved.

this is the code that calls the longitudinal wave graphics

import java.awt.*;
import javax.swing.*;
import java.awt.event.*;



public class LongitudinalWaveProgram extends JFrame{

	public LongitudinalWaveProgram (){
		JFrame frame = new JFrame ("Longitudinal Wave - Adam");
		JPanel pane = new JPanel ();
		
		
		LongitudinalWaveGraphics lwg = new LongitudinalWaveGraphics ();
		frame.add (pane);
		frame.setVisible (true);
		lwg.LongDraw();
	}
	
	public void LongitudinalWave (){
		LongitudinalWaveProgram lwp = new LongitudinalWaveProgram ();
		
	}
	
}

and this is the graphics that is should print out

import java.awt.*;
import java.awt.event.*;
import javax.swing.*;


public class LongitudinalWaveGraphics extends JPanel{

	int [] x = new int [50];
	int [] y = new int [4];
	
	public void LongDraw (){
		
		for (int i = 0; i < 50; i++){
			x [i] = (15 * i);
		}
		for (int i = 0; i < 4; i++){
			if (i % 4 == 0){
				y[i] = 50;
			}
			else if (i % 3 == 0){
				y[i] = 60;
			}
			else if (i % 2 == 0){
				y[i] = 70;
			}
			else if (i % 1 == 0){
				y[i] = 80;
			}
		}
		
		
		repaint();
	}
	
	
	public void graphicsComponent (Graphics g){
		for (int i = 0; i< 50; i++){
			for (int z = 0; z < 4; z++){
				g.fillOval(x[i], y[z], 10, 10);
			}
		}
		System.out.print("Ovals");
	}
	
	
}

Then this is the program that calls the resistor graphics

import java.awt.*;
import java.awt.event.*;

import javax.swing.*;


public class ResistorColorCodeProgram implements ActionListener{

	JButton bl,br,red,or,ye,gr,blu,vi,gray,wh;
	int mx, my;
	int ringC1, ringC2, ringC3;
	int col;    // 0 = black, 1 = brown, ... gray = 8, white = 9
	int ringsel = 1; // selects a ring1 = ring 1, 2 = ring2, 3 = ring3
	int lastRing;
	int lastCol;
	
	public ResistorColorCodeProgram (){
		JFrame resistorCCFrame = new JFrame ("Resistor Color Code");
		
		
		resistorCCFrame.setBackground (Color.white);
		resistorCCFrame.setBounds(100,100, 100,100);
		resistorCCFrame.setSize(600,500);
		
		resistorCCFrame.setLayout(new BorderLayout ());
		
		ImageIcon bls = new ImageIcon ("ResistorCCImages\\BlackC.gif");
		ImageIcon brs = new ImageIcon ("ResistorCCImages\\BrownC.gif");
		ImageIcon reds = new ImageIcon ("ResistorCCImages\\RedC.gif");
		ImageIcon ors = new ImageIcon ("ResistorCCImages\\OrangeC.gif");
		ImageIcon yes = new ImageIcon ("ResistorCCImages\\YellowC.gif");
		ImageIcon grs = new ImageIcon ("ResistorCCImages\\GreenC.gif");
		ImageIcon blus = new ImageIcon ("ResistorCCImages\\BlueC.gif");
		ImageIcon vis = new ImageIcon ("ResistorCCImages\\VioletC.gif");
		ImageIcon grays = new ImageIcon ("ResistorCCImages\\GrayC.gif");
		ImageIcon whs = new ImageIcon ("ResistorCCImages\\WhiteC.gif");
		JButton check = new JButton ("Check");
		
		bl = new JButton (bls); bl.setActionCommand("Black"); bl.addActionListener(this);
		br = new JButton (brs); br.setActionCommand ("Brown"); br.addActionListener (this);
		red = new JButton (reds); red.setActionCommand("Red"); red.addActionListener(this);
		or = new JButton (ors); or.setActionCommand("Orange"); or.addActionListener(this);
		ye = new JButton (yes); ye.setActionCommand ("Yellow"); ye.addActionListener(this);
		gr = new JButton (grs); gr.setActionCommand ("Green"); gr.addActionListener (this);
		blu = new JButton (blus); blu.setActionCommand("Blue"); blu.addActionListener(this);
		vi = new JButton (vis); vi.setActionCommand("Violet"); vi.addActionListener(this);
		gray = new JButton (grays); gray.setActionCommand ("Gray"); gray.addActionListener (this);
		wh = new JButton (whs); wh.setActionCommand("White"); wh.addActionListener (this);
		
		
		JPanel ringPanel = new JPanel ();
		
		JButton ring1B = new JButton ("Ring 1"); ring1B.setActionCommand("ring1"); ring1B.addActionListener(this);
		JButton ring2B = new JButton ("Ring 2"); ring2B.setActionCommand("ring2"); ring2B.addActionListener(this);
		JButton ring3B = new JButton ("Ring 3"); ring3B.setActionCommand("ring3"); ring3B.addActionListener(this);
		
		ringPanel.add(ring3B, JButton.CENTER);
		ringPanel.add(ring2B, JButton.CENTER);
		ringPanel.add(ring1B, JButton.CENTER);
		
		JPanel buttonPanel = new JPanel ();
		buttonPanel.setLayout(new GridLayout (11,1));
		buttonPanel.add(bl);
		buttonPanel.add(br);
		buttonPanel.add(red);
		buttonPanel.add(or);
		buttonPanel.add(ye);
		buttonPanel.add(gr);
		buttonPanel.add(blu);
		buttonPanel.add(vi);
		buttonPanel.add(gray);
		buttonPanel.add(wh);
		buttonPanel.add(check);
		resistorCCFrame.add(buttonPanel, BorderLayout.EAST);
		resistorCCFrame.add(ringPanel, BorderLayout.NORTH);
		resistorCCFrame.setVisible(true);
		
		ResistorColorCodeGraphics rCCG = new ResistorColorCodeGraphics ();
		rCCG.ColorCodeDraw ();
		resistorCCFrame.add(rCCG, BorderLayout.CENTER);
		
	}
	
	
	
	
	public static void main(String[] args) {
		// TODO Auto-generated method stub
		ResistorColorCodeProgram rccp = new ResistorColorCodeProgram ();
	}

	
	
	public void actionPerformed(ActionEvent e) {
		// TODO Auto-generated method stub
		if ("Black".equals (e.getActionCommand())){
			col = 0;
		}
		if ("Brown".equals(e.getActionCommand ())){
			col = 1;
		}
		if ("Red".equals(e.getActionCommand())){
			col = 2;
		}
		if ("Orange".equals(e.getActionCommand())){
			col = 3;
		}
		if ("Yellow".equals(e.getActionCommand())){
			col = 4;
		}
		if ("Green".equals(e.getActionCommand())){
			col = 5;
		}
		if ("Blue".equals(e.getActionCommand())){
			col = 6;
		}
		if ("Violet".equals(e.getActionCommand())){
			col = 7;
		}
		if ("Gray".equals(e.getActionCommand())){
			col = 8;
		}
		if ("White".equals(e.getActionCommand())){
			col = 9;
		}		
		if ("ring1".equals(e.getActionCommand ())){
			ringsel = 1;
		}
		if ("ring2".equals(e.getActionCommand ())){
			ringsel = 2;
		}
		if ("ring3".equals(e.getActionCommand ())){
			ringsel = 3;
		}
		if (lastRing != ringsel || lastCol != col){
		paintColors(ringsel, col);
		}
	}

	public void paintColors (int ringsel, int col){
		ResistorColorCodeGraphics rCCG = new ResistorColorCodeGraphics ();
		rCCG.printRings(ringsel, col);
		lastCol = col; lastRing = ringsel;
		rCCG.repaint();
	}
	
}

and this is the code that it calls

import java.awt.Container;
import java.awt.Graphics;
import java.awt.event.*;
import java.awt.*;
import javax.swing.*;


public class ResistorColorCodeGraphics extends JPanel{

	Image base, black, brown, red, orange, yellow, green, blue, violet, gray, white, click;
	int ring1Col, ring2Col, ring3Col;
	Image ring1, ring2, ring3;
	
	public void ColorCodeDraw (){
		base = getToolkit().getImage("ResistorCCImages\\Resistor Base.gif");
		black = getToolkit().getImage("ResistorCCImages\\Black Ring.gif");
		brown = getToolkit().getImage("ResistorCCImages\\Brown Ring.gif");
		red = getToolkit().getImage("ResistorCCImages\\Red Ring.gif");
		orange = getToolkit().getImage("ResistorCCImages\\Orange Ring.gif");
		yellow = getToolkit().getImage("ResistorCCImages\\Yellow Ring.gif");
		green = getToolkit().getImage("ResistorCCImages\\Green Ring.gif");
		blue = getToolkit().getImage("ResistorCCImages\\Blue Ring.gif");
		violet = getToolkit().getImage("ResistorCCImages\\Violet Ring.gif");
		gray = getToolkit().getImage("ResistorCCImages\\Gray Ring.gif");
		white = getToolkit().getImage("ResistorCCImages\\White Ring.gif");
		click = getToolkit().getImage("ResistorCCImages\\ClickRing.gif");
		
		repaint();
	}
	
	public void paintComponent (Graphics g){
	
		
		g.drawImage (base, 0, 50, 500, 350, this);
		g.drawImage (click, 125, 129, 166, 175, this);
		g.drawImage (click, 165, 129, 166, 175, this);
		g.drawImage (click, 205, 129, 166, 175, this);
		g.drawImage (ring1 , 50,50,50,50,this);
		System.out.print("Resistor");
		}
	
	
	
	public void firstRing (int col){
		if (col == 0){
			ring1 = black;
		}
		System.out.println ("First ring: " + col);
	}
	public void secondRing (int col){
		System.out.println ("Second ring: " + col);
		
	}
	public void thirdRing (int col){
		System.out.println ("Third ring: " + col);
		
	}

	public void printRings(int ringsel, int col) {
		if (ringsel == 1){
			
		}
		
	}
}

Thanks for your help

When I run the longitudinal wave code it prints out the resistor code

How do you run the longitudinal wave code?
Could you put a comment in your code where you do that? Something that is easy to see, like:
//******************* HERE I CALL THE .....***************

public class LongitudinalWaveProgram extends JFrame{

	public LongitudinalWaveProgram (){
		JFrame frame = new JFrame ("Longitudinal Wave - Adam");

Why extend JFrame and then create a new one in the constructor?

public void graphicsComponent (Graphics g){

What code calls this method?


Please add some comments to the code describing what each method is to do and who is supposed to call it. For example who calls: LongitudinalWave
Don't explain here, explain in your code.

Edited 5 Years Ago by NormR1: n/a

public void graphicsComponent (Graphics g){

looks odd to me, are you sure you don't mean

public void paintComponent (Graphics g){

I did mean paintComponent, but that still doesn't fix the problem.

And

import java.awt.*;
import javax.swing.*;
import java.awt.event.*;



public class LongitudinalWaveProgram extends JFrame{

	public LongitudinalWaveProgram (){
		JFrame frame = new JFrame ("Longitudinal Wave - Adam");
		JPanel pane = new JPanel ();
		
		
		LongitudinalWaveGraphics lwg = new LongitudinalWaveGraphics ();
		frame.add (pane);
		frame.setVisible (true);
		lwg.LongDraw();         //HERE I CALL THE LongDraw METHOD WHICH THEN REPAINTS
	}
	
	public void LongitudinalWave (){
		LongitudinalWaveProgram lwp = new LongitudinalWaveProgram ();
		
	}
	
}

And the graphics code

import java.awt.*;
import java.awt.event.*;
import javax.swing.*;


public class LongitudinalWaveGraphics extends JPanel{

	int [] x = new int [50];
	int [] y = new int [4];
	
	public void LongDraw (){
		
		for (int i = 0; i < 50; i++){
			x [i] = (15 * i);
		}
		for (int i = 0; i < 4; i++){
			if (i % 4 == 0){
				y[i] = 50;
			}
			else if (i % 3 == 0){
				y[i] = 60;
			}
			else if (i % 2 == 0){
				y[i] = 70;
			}
			else if (i % 1 == 0){
				y[i] = 80;
			}
		}
		
		
		repaint();  //HERE I REPAINT
	}
	
	
	public void paintComponent (Graphics g){
		for (int i = 0; i< 50; i++){
			for (int z = 0; z < 4; z++){
				g.fillOval(x[i], y[z], 10, 10);
			}
		}
		System.out.print("Ovals");
	}
	
	
}

Edited 5 Years Ago by sirlink99: n/a

Where is the main method to test the code you just posted?

Where is the LongitudinalWaveGraphics object added to the GUI?

Edited 5 Years Ago by NormR1: n/a

just looking at your latest code, there's nowhere you add the LWG object to the main JFrame. Since it isn't part of any visible window, it's paintComponent won't be called

I modified the code a little bit and now it should be working. I have a main method and it should be adding onto a JPanel. here is the new code. it is still calling the old graphics code.

import java.awt.*;
import javax.swing.*;
import java.awt.event.*;



public class LongitudinalWaveProgram extends JFrame{

	public LongitudinalWaveProgram (){
		JFrame frame = new JFrame ("Longitudinal Wave - Adam");
		JPanel pane = new JPanel ();
		
		
		LongitudinalWaveGraphics lwg = new LongitudinalWaveGraphics ();
		lwg.LongDraw();
		pane.add(lwg);
		frame.add (pane);
		frame.setVisible (true);
		
		
	}
	
	public void main (String [] args){
		LongitudinalWaveProgram lwp = new LongitudinalWaveProgram ();
		
	}
	
}

You've posted many pieces of code now.
What parts do I need to compile to get a program that executes the same as the one you are executing?
What is the command line I should use to execute the program?

it is still calling the old graphics code

can you explain what should be shown when the code is executed?

Edited 5 Years Ago by NormR1: Add attachment

Attachments LWG.png 5.04 KB
public LongitudinalWaveProgram (){
JFrame frame = new JFrame ("Longitudinal Wave - Adam");//instead of this, I believe you want to reach the effect that super(Longitudinal Wave - Adam); would reach. In addition, why do you need another frame named frame when LongitudinalWaveProgram is itself a frame?
JPanel pane = new JPanel ();
 
 
LongitudinalWaveGraphics lwg = new LongitudinalWaveGraphics ();
lwg.LongDraw();
pane.add(lwg);//here, you are adding a frame onto a panel. you should add a panel onto a frame

you're constructor method is a little messy, James explained a little earlier this what I am trying to explain. fix you're constructor method, or at least write comments, instead of actual methods, explaining what you want your constructor method to doo, one step at a time

ok these are the two codes I am having trouble with. I added comments

The graphics launcher

import java.awt.*;
import javax.swing.*;
import java.awt.event.*;



public class LongitudinalWaveProgram extends JFrame{

	public LongitudinalWaveProgram (){
		super ("Longitudinal Wave - Adam"); // sets frame title
		JPanel pane = new JPanel ();          // makes panel
		
		
		LongitudinalWaveGraphics lwg = new LongitudinalWaveGraphics ();   // finds class
		lwg.LongDraw();         // calls method in class (to my knowledge this should draw my graphics)
		add (lwg);
		add (pane);        // adds the panel
		setVisible (true);   // sets frame visible
		
		
	}
	
	public static void main (String [] args){
		LongitudinalWaveProgram lwp = new LongitudinalWaveProgram ();
		
	}
	
}

and the graphics portion

import java.awt.*;
import java.awt.event.*;
import javax.swing.*;


public class LongitudinalWaveGraphics extends JPanel{

	int [] x = new int [50];
	int [] y = new int [4];
	 // method gets called from previous class
	public void LongDraw (){
		
		for (int i = 0; i < 50; i++){                     // creates x and y values for ovals
			x [i] = (15 * i);
		}
		for (int i = 0; i < 4; i++){
			if (i % 4 == 0){
				y[i] = 50;
			}
			else if (i % 3 == 0){
				y[i] = 60;
			}
			else if (i % 2 == 0){
				y[i] = 70;
			}
			else if (i % 1 == 0){
				y[i] = 80;
			}
		}
		
		
		repaint();               // calls the graphics portion
	}
	
	
	public void paintComponent (Graphics g){
		for (int i = 0; i< 50; i++){               // draws ovals
			for (int z = 0; z < 4; z++){
				g.fillOval(x[i], y[z], 10, 10);
			}
		}
		System.out.print("Ovals");        // check if it works
	}
	
	
}

Thanks for your help.

nvm that works. But then I still have the problem of my graphic not showing up. it flashes and then disappears. Could this be because I'm using Vista?

Edited 5 Years Ago by sirlink99: n/a

see, LongitudinalWaveProgram is your frame. you have this extending JFrame, right? that just means it is the frame. then, your LongitudinalWaveGraphics is your panel, because it extends JPanel, right? I don;t see why do you need line 13 in your LongitudinalWaveProgram file. And, I might be wrong, but I think you do not need to invoke repaint() inside your DrawLong(). hope this will be of any help. I don't think Vista should be a problem for the flashing.

Try removing the add(pane) statement.
You are not giving constraints to the layout manager for the frame.

thanks the removing the add(pane) worked now my graphics show up. and you do need the repaint otherwise it cant access the code in the paintComponent method.

I could be wrong, but when you add a panel onto a frame, the panels paintComponent is automatically called. the other more experienced guys should correct me if I'm wrong.

ok now I have a problem with my repaint. this is the newest version of the graphics code

import java.awt.*;
import java.awt.event.*;

import javax.swing.*;


public class LongitudinalWaveGraphics extends JPanel implements ActionListener{

	int [] x = new int [23];
	int [] y = new int [4];
	private Timer timer = new Timer (1000,this);
	 // method gets called from previous class
	public void LongDraw (){
		
		for (int i = 0; i < 23; i++){                     // creates x and y values for ovals
			x [i] = (25 * i + 10);
		}
		for (int i = 0; i < 4; i++){
			if (i % 4 == 0){
				y[i] = 50;
			}
			else if (i % 3 == 0){
				y[i] = 60;
			}
			else if (i % 2 == 0){
				y[i] = 70;
			}
			else if (i % 1 == 0){
				y[i] = 80;
			}
		}
		timer.start();
		
		repaint();               // calls the graphics portion
	}
	
	
	public void paint (Graphics g){
		super.paintComponents(g);
		
		for (int i = 0; i< 23; i++){               // draws ovals
			for (int z = 0; z < 4; z++){
				g.fillOval(x[i], y[z], 10, 10);
			}
		}
		System.out.print("Ovals");        // check if it works
	}


	
	public void actionPerformed(ActionEvent arg0) {
		if (x[0] > -10){
			for (int i = 0; i < 12; i++){
				x[i] = x[i] - (i * 2);
			}
			for (int i = 0; i > 12; i++){
				x[i] = x[i] + (i*2);
			}
		}
		else if (x[0] < -10){
			for (int i = 0; i < 12; i++){
				x[i] = x[i] + (i * 2);
			}
			for (int i = 0; i > 12; i++){
				x[i] = x[i] - (i*2);
			}
		}
		repaint ();
	}
	
	
}

instead of erasing the previous graphics and printing the new one it just paints over the old one creating 4 horizontal black lines. How can I fix this?

Thanks again.

Some times a small simple program with printlns will show what happens and when.

It may be when the container is made visible. Problem is it's asynchronous so hard to say.

painComponent(Graphics g){..} instead of paint(Graphics g){..)

and if you want to really painting something ...
then

if (SwingUtilities.isEventDispatchThread()) {
        paintImmediately(int x, int y, int w, int h) // or Rectangle r
    } else {
        Runnable doRun = new Runnable() {

            @Override
            public void run() {
                repaint(long tm, int x, int y, int width, int height) // or Rectangle r
            }
        };
        SwingUtilities.invokeLater(doRun);
    }

have you checked the args for fillOval()?
Are they correct?

Too late.

Why did you change the call to paintComponent to paint?

Edited 5 Years Ago by NormR1: n/a

before I highjack the thread:

import javax.swing.*;
   import java.awt.*;

   public class Println extends JPanel{
   
      public void paintComponent(Graphics g){
         System.out.println("It's happening");
      }
      
      public static void main(String[] args){
         JFrame frame = new JFrame();
         JPanel pan = new Println();
      
         frame.getContentPane().add(pan);
         frame.setSize(500, 500);
         frame.setVisible(true);//if I comment out this line, paintComponent is not invoked. only when this line is executed is paintComponent invoked (seems like).
      
      }
   }

anyways, sirlink, try puting as the first line in your paintComponent this line: super.paintComponent(g); this line clears everything in the pane before it draws what follows in your paintComponent.

this line clears everything in the pane

Since the OP has coded something like that and its not working, the OP should take a closer look at his code to see why it isn't working.

thanks adding the super.paintComponent(); worked. and I changed it from paintComponent to paint to see if it would make a difference.

:$ my bad. haven't looked at the code, just assumed he didn't put it in. I beg your pardon.

I get an index array out of bounds error when I run this part of the code. why is that?

I have an array that has 23 values in it.

if (x[0] < 15){
			// stretches ovals
			for (int i = 0; i < 12; i++){
				x[i] = x[i] - (12 - i);
			}
			for (int i = 13; i <= 23; i++){
				x[i] = x[i] + (-2 + (i-10));
			}
		}

Edited 5 Years Ago by sirlink99: n/a

Please copy and paste here the full text of the error message. It has info that you did not include in your post.

This question has already been answered. Start a new discussion instead.