Help with barchart program

Whenever I run this, it compiles, but I get a black screen, what can I do to get the barchart to show up?

import java.awt.;
import java.awt.event.
;
import net.java.games.jogl.;
import net.java.games.jogl.util.
;

public class BarChart2 {

public static void main(String[] args)

{

Frame frame = new Frame("Bar Chart");

GLCanvas canvas = GLDrawableFactory.getFactory().createGLCanvas(new GLCapabilities());

canvas.addGLEventListener(new Renderer());
//frame.display(); 
frame.add(canvas);

frame.setSize(500, 600);



  

frame.addWindowListener(new WindowAdapter()

{

  public void windowClosing(WindowEvent e)

  {

    

    System.exit(0);

  }

});

frame.show();

canvas.requestFocus();

}
static class Renderer implements GLEventListener, KeyListener

{

public void init(GLDrawable gLDrawable)

{

final GL gl = gLDrawable.getGL();
final GLU glu = gLDrawable.getGLU();
gl.glColor3f (0.0f, 0.0f, 0.75f);
gl.glMatrixMode (GL.GL_PROJECTION);
gl.glLoadIdentity();

  //lineSegment(gLDrawable.getGL());

 

}

public void display(GLDrawable gLDrawable)//, int winWidth, int winHeight)

{

 final GL gl = gLDrawable.getGL();
 final GLU glu = gLDrawable.getGLU();


  gl.glClear (GL.GL_COLOR_BUFFER_BIT);// Set display to color.

        //gl.glColor3f (0.0f, 0.0f, 0.75f);  

           

  gl.glMatrixMode (GL.GL_MODELVIEW);

  gl.glLoadIdentity();

int winWidth = 600;
int winHeight = 500; //Initial display window size
//setSize (600,500);
//gl.GLint xRaster = 25;
//gl.GLint yRaster = 150; //Initialize raster position
int xRaster = 25;
int yRaster = 150;
/gl.GLubyte/ char[] label /[36]/ = { ‘J’,‘a’,‘n’, ‘F’,‘e’,‘b’, ‘M’,‘a’,‘r’,
‘A’,‘p’,‘r’, ‘M’,‘a’,‘y’, ‘J’,‘u’,‘n’,
‘J’,‘u’,‘l’, ‘A’,‘u’,‘g’, ‘S’,‘e’,‘p’,
‘O’,‘c’,‘t’, ‘N’,‘o’,‘v’, ‘D’,‘e’,‘c’ };

int[] dataValue /[12]/ = {420, 342, 324, 310, 262, 185,
190, 196, 217, 240, 312, 438 };

gl.glClearColor (1.0f, 1.0f, 0.0f, 0.0f); //White display window
gl.glMatrixMode (GL.GL_PROJECTION);
}

public void displayChanged(GLDrawable gLDrawable, boolean modeChanged, boolean deviceChanged)

{

}

public void reshape(GLDrawable gLDrawable, int x, int y, int width, int height)

{

  

}

public void BarChart2 (GL gl, GLUT glut, int xRaster, int yRaster, int[] dataValue, char[] label, char h)
{
// char[] label;
int month;
int k;
// char h;
gl.glClear (GL.GL_COLOR_BUFFER_BIT); //Clear display window

  gl.glColor3f (1.0f, 1.0f,0.0f); // Set bar color to red
  for (k = 0; k < 12; k++) 
  
  gl.glRecti (20 + k*50, 165, 40 + k*50, dataValue [k]);

// gl.glColor4f (1.0f, 1.0f, 1.0f, 1.0f); // Set test color to black
xRaster = 20; // Display chart labels
for (month = 0; month < 12; month++) {
gl.glRasterPos2i (xRaster, yRaster);
for (k = 3*month; k <3 * month + 3; k++)
//glut.glutBitmapCharacter(GLUT.BITMAP_HELVETICA_12, label [h]); //glut.glutBitmapCharacter //(GLUT.BITMAP_HELVETICA_12,//label[h]);
xRaster +=50;

  }

gl.glFlush ();

}

public void winReshapeFcn (GL gl, GLU glu, int newWidth, int newHeight, GLU gluOrtho2D, GL glClear, GL GL_COLOR_BUFFER_BIT)
{
gl.glMatrixMode (GL.GL_PROJECTION);
gl.glLoadIdentity ();
glu.gluOrtho2D (0.0, (double) newWidth, 0.0, (double) newHeight);
gl.glClear (GL.GL_COLOR_BUFFER_BIT);

  }





public void keyPressed(KeyEvent e)

{

  if (e.getKeyCode() == KeyEvent.VK_ESCAPE)

    System.exit(0);

}


public void keyReleased(KeyEvent e) {}



public void keyTyped(KeyEvent e) {}

}

}

I don’t think that you are ever constructing a BarChart2 object. i.e. the code in

 public void BarChart2 (GL gl, GLUT glut, int xRaster, int yRaster, int[] dataValue,  char[] label, char h) 

is never being called.

Rob

whenever I try anything.BarChart2() I get a cannot resolve symbol error

did you try (nothing) BarChart2(…) ?

BarChart2 is a public method of a static class, so you can call it with BarChart2(…) from within your display() method, or Renderer.BarChart2(…) from your package

Strange that you named this method the same as your class… looks like a constructor but it isn’t.

compiles fine for me

Lilian

You don’t ever call your winReshapeFcn either. You need to inorder for the projection matrix to be set up correctly. What symbol is unsatisfied?

I have made some changes to the program and called the BarChart2 and winReshapeFcn inside the display. It compiles ok and has no errors, but I still get that blank black screen at execution(BarChart screen) and no display of the barchart.

import java.awt.;
import java.awt.event.
;
import net.java.games.jogl.;
import net.java.games.jogl.util.
;

public class BarChart2 {

public static void main(String[] args)

{

Frame frame = new Frame("Bar Chart");

GLCanvas canvas = GLDrawableFactory.getFactory().createGLCanvas(new GLCapabilities());

canvas.addGLEventListener(new Renderer());

frame.add(canvas);

frame.setSize(500, 600);

frame.addWindowListener(new WindowAdapter()

{

  public void windowClosing(WindowEvent e)

  {

    

    System.exit(0);

  }

});

frame.show();

canvas.requestFocus();

}

static class Renderer implements GLEventListener, KeyListener

{

public void init(GLDrawable gLDrawable)

{

final GL gl = gLDrawable.getGL();
final GLU glu = gLDrawable.getGLU();
gl.glColor3f (0.0f, 0.0f, 0.75f);
gl.glMatrixMode (GL.GL_PROJECTION);
gl.glLoadIdentity();

  //lineSegment(gLDrawable.getGL());

}

public void display(GLDrawable gLDrawable)//, int winWidth, int winHeight)

{

 final GL gl = gLDrawable.getGL();
 final GLU glu = gLDrawable.getGLU();
 final GLUT glut = new GLUT();
 

 


  gl.glClear (GL.GL_COLOR_BUFFER_BIT);// Set display to color.

  gl.glColor3f (0.0f, 0.0f, 0.75f);  

           
  winReshapeFcn (gl, glu);//, gluOrtho2D, glClear); //, //GL_COLOR_BUFFER_BIT);    

  BarChart2(gl, glut);
  gl.glMatrixMode (GL.GL_MODELVIEW);

  gl.glLoadIdentity();

int winWidth = 600;
int winHeight = 500; //Initial display window size
int xRaster = 25;
int yRaster = 150;
/gl.GLubyte/ char[] label /[36]/ = { ‘J’,‘a’,‘n’, ‘F’,‘e’,‘b’, ‘M’,‘a’,‘r’,
‘A’,‘p’,‘r’, ‘M’,‘a’,‘y’, ‘J’,‘u’,‘n’,
‘J’,‘u’,‘l’, ‘A’,‘u’,‘g’, ‘S’,‘e’,‘p’,
‘O’,‘c’,‘t’, ‘N’,‘o’,‘v’, ‘D’,‘e’,‘c’ };

int[] dataValue /[12]/ = {420, 342, 324, 310, 262, 185,
190, 196, 217, 240, 312, 438 };

gl.glClearColor (1.0f, 1.0f, 0.0f, 0.0f); //White display window
gl.glMatrixMode (GL.GL_PROJECTION);
}

public void displayChanged(GLDrawable gLDrawable, boolean modeChanged, boolean deviceChanged)

{

}

public void reshape(GLDrawable gLDrawable, int x, int y, int width, int height)

{

  

}

public void BarChart2 (GL gl, GLUT glut)//, int xRaster, int yRaster, int[] dataValue)//, //char[] label, char h)
{

  int xRaster;
  int yRaster;
  int month;

// int[] dataValue;
char[] label;
int k;
char h;

int[] dataValue = {420, 342, 324, 310, 262, 185,
190, 196, 217, 240, 312, 438 };

  //gl.glClear (GL.GL_COLOR_BUFFER_BIT); //Clear display window
  
  gl.glColor3f (1.0f, 1.0f,0.0f); // Set bar color to red
  for (k = 0; k < 12; k++) 
  
  gl.glRecti (20 + k*50, 165, 40 + k*50, dataValue [k]);

// gl.glColor4f (1.0f, 1.0f, 1.0f, 1.0f); // Set test color to black
xRaster = 25; //20; // Display chart labels
yRaster = 150;
for (month = 0; month < 12; month++) {
gl.glRasterPos2i (xRaster, yRaster);
for (k = 3*month; k <3 * month + 3; k++)
//glut.glutBitmapCharacter(GLUT.BITMAP_HELVETICA_12, label [h]); //glut.glutBitmapCharacter //(GLUT.BITMAP_HELVETICA_12,//label[h]);
xRaster +=50;

  }

gl.glFlush ();
}

public void winReshapeFcn (GL gl, GLU glu)//, GLU gluOrtho2D, GL glClear)//, GL GL_COLOR_BUFFER_BIT)
{

  double newWidth =0.0;
  double newHeight= 0.0;
  GL GL_COLOR_BUFFER_BIT;
  GLU gluOrtho2D;
  GL glClear;
  gl.glMatrixMode (GL.GL_PROJECTION);
  gl.glLoadIdentity ();
  glu.gluOrtho2D (0.0, (double) newWidth, 0.0, (double) newHeight);
  gl.glClear (GL.GL_COLOR_BUFFER_BIT);

  

  }






public void keyPressed(KeyEvent e)

{

  if (e.getKeyCode() == KeyEvent.VK_ESCAPE)

    System.exit(0);

}


public void keyReleased(KeyEvent e) {}



public void keyTyped(KeyEvent e) {}

}

}