Skip to content

Instantly share code, notes, and snippets.

@brandonborkholder
Created October 18, 2012 01:40
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save brandonborkholder/3909397 to your computer and use it in GitHub Desktop.
Save brandonborkholder/3909397 to your computer and use it in GitHub Desktop.
Using GLG2D in an existing application
// all painting is done to this single JComponent (or subclass)
JComponent paintingCanvas = new JComponent() {
public void paintComponent(Graphics g) {
super.paintComponent(g);
// paint the scene to the Graphics object
}
};
JFrame frame = // ...
frame.setContentPane(paintingCanvas);
// add an animator to paintingCanvas
// ...
JComponent paintingCanvas = new JComponent() {
public void paintComponent(Graphics g) {
super.paintComponent(g);
// paint the scene to the Graphics object
}
};
// if all painting is done to the single JComponent above
// then
paintingCanvas = new G2DGLCanvas(paintingCanvas);
// else if paintingCanvas has a hierarchy of Swing components added to it
// then
paintingCanvas = new G2DGLPanel(paintingCanvas);
// this handles the RepaintManager issues of subcomponents, but is not as stable or as fast
JFrame frame = // ...
frame.setContentPane(paintingCanvas);
// add an animator to the new paintingCanvas
// ...
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment