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) {}
}
}