Hi there,
I’m a beginner in JOGL and I’m not all that familiar with it’s terminology and syntax. I’m trying to build a bar graph program using JOGL and I want to use GUI/Swing components within it.
The whole basis of how this program is to work is that the user selects an amount of bars they want displayed using a textfield, choose a color for each bar and the x and y points using textfields using Radio buttons , then it is diplayed on the canvas.
Now this what I have here:
import java.awt.;
import java.awt.event.;
import net.java.games.jogl.;
import java.io.;
import cs1.Keyboard;
public class Experiment extends JFrame implements ActionListener
{
private JPanel panel, colorBox, barArea, pointArea, buttonArea,screen;
private JLabel enterBar, enterP1,enterP2,/*howMany,*/blank1, blank2, blank3;
private JTextField barNum, point1, point2;
private JRadioButton red, blue, green, yellow, magenta, black, cyan;
private JButton readFile, display, /*showColor,*/clear1;
public static void main( String args[])
{
JFrame frame = new JFrame ();//frame
GLCanvas canvas = GLDrawableFactory.getFactory().createGLCanvas(new GLCapabilities());
canvas.addGLEventListener(new Renderer ());
frame.add("Center", canvas);
frame.setSize(800,800);
frame.addWindowListener(new WindowAdapter()
{
public void windowClosing(WindowEvent e)
{
System.exit(0);
}
});
frame.show();
canvas.requestFocus();
Experiment ()
{
super ("Bar Selection Window");
setSize (320, 300);
panel = new JPanel ();
panel.setBackground (Color.white);
//Buttons
readFile = new JButton (" Read");
display = new JButton ("Display Bar Chart");
//showColor = new JButton ("Add Color");
clear1 = new JButton ("Clear Screen");
clear2 = new JButton ("Clear Canvas");
//Labels
enterBar = new JLabel ("Enter Bar Amount To Display: ");
enterP1 = new JLabel ("Enter First point value:");
enterP2= new JLabel ("Enter Second point value:");
//howMany = new JLabel (" You can show up to 6 bars..No more, No less:");
blank1 = new JLabel (" ");
blank2 = new JLabel (" ");
blank3 = new JLabel (" ");
//TextFields
barNum = new JTextField (5);
point1 = new JTextField (10);
point2 = new JTextField (10);
//Choice Menu
//Choice languageMenu = new Choice();
//Radio Buttons
red = new JRadioButton (" Red",true);
blue = new JRadioButton (" Blue", false);
green = new JRadioButton ("Green", false);
yellow = new JRadioButton ("Yellow", false);
magenta = new JRadioButton (" Magenta", false);
black = new JRadioButton (" Black", false);
cyan = new JRadioButton (" Cyan", false);
//*Adding Components*//
//Bar Chart Main Label
//panel.add (howMany);
panel.add( new Label("Show up to six bars on Graphic Screen:",Label.CENTER));
//Bar Area
barArea = new JPanel ();
barArea.setLayout (new BoxLayout (barArea, BoxLayout.Y_AXIS));
barArea.add (enterBar);
barArea.add (barNum);
//Point Area
pointArea = new JPanel ();
pointArea.setLayout (new BoxLayout (pointArea, BoxLayout.Y_AXIS));
pointArea.add (enterP1);
pointArea.add (point1);
pointArea.add (blank1);
pointArea.add (enterP2);
pointArea.add (point2);
//Button Area
buttonArea = new JPanel ();
buttonArea.setLayout (new BoxLayout (buttonArea, BoxLayout.Y_AXIS));
buttonArea.add (readFile);
buttonArea.add (display);
buttonArea.add (blank2);
buttonArea.add (clear1);
buttonArea.add (clear2);
//RadioButton Area
colorBox = new JPanel ();
colorBox.setLayout (new BoxLayout (colorBox, BoxLayout.Y_AXIS));
colorBox.add (red);
colorBox.add (blue);
colorBox.add (green);
colorBox.add (yellow);
colorBox.add (cyan);
colorBox.add (magenta);
//Panel Set-Up
screen = new JPanel ();
screen.setLayout (new BorderLayout(25, 20));
screen.add (barArea, BorderLayout.NORTH);
screen.add (colorBox, BorderLayout.WEST);
screen.add (pointArea, BorderLayout.CENTER);
screen.add (buttonArea, BorderLayout.EAST);
setContentPane (screen);
//Button Listeners
readFile.addActionListener (new ReadListener ());
//showColor.addActionListener (new ShowColorListener ());
clear1.addActionListener (new ClearOneListener ());
//Color Listeners
red.addActionListener (new RedListener());
blue.addActionListener (new BlueListener ());
green.addActionListener (new GreenListener ());
yellow.addActionListener (new YellowListener ());
cyan.addActionListener (new CyanListener ());
magenta.addActionListener (new MagentaListener ());
black.addActionListener (new BlackListener ());
}//init
} //void main
static class Renderer implements GLEventListener, KeyListener
{ //static class start
public void barGraph (GL gl)
{
gl.glClear (GL.GL_COLOR_BUFFER_BIT); // Set display window to color.
class ReadListener implements ActionListener
{
public void actionPerformed (ActionEvent e)
{
int counter = 0;
int x1, x2;
x1 = Integer.parseInt(point1.getText());
x1.setText((gl.glRecti(x1,0,x2,0)));
x2 = Integer.parseInt (point2.getText ());
x2.setText((gl.glRecti(x1,0,x2,0)));
int numOFbar = Integer.parseInt (barNum.getText());
numOFbar.setText (counter = counter + numOFbar);
}
} // class ReadListener
(Continued)