Bugzilla – Attachment 33 Details for
Bug 128
Two Animator threads controlling two GLCanvas objects deadlock, or one of the threads starve.
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Help
|
Log In
[x]
|
Forgot Password
Login:
[x]
Example program which renders two rotating squares in two JFrames contained in a JSplitPane.
Main.java (text/plain), 5.57 KB, created by
Sven Gothel
on 2005-01-07 19:48:00 CET
(
hide
)
Description:
Example program which renders two rotating squares in two JFrames contained in a JSplitPane.
Filename:
MIME Type:
Creator:
Sven Gothel
Created:
2005-01-07 19:48:00 CET
Size:
5.57 KB
patch
obsolete
>package joglswingtest5; > >import net.java.games.jogl.*; >import java.awt.*; >import java.awt.event.*; >import java.beans.*; > >import javax.swing.*; >import javax.swing.event.*; > >public class Main extends javax.swing.JFrame { > private JMenuBar menubar; > private JMenu fileMenu; > private JMenuItem fileExit, fileOpen, fileClose, fileSave, fileSaveAs; > private JPanel leftPanel, rightPanel; > private JSplitPane splitPane; > private TestPanel panel1, panel2; > > public static void main(String args[]) { > EventQueue.invokeLater(new Runnable() { > public void run() { > new Main().setVisible(true); > } > }); > } > > public Main() { > //GLCapabilities cap=new GLCapabilities(); > //cap.setHardwareAccelerated(true); > //cap.setDoubleBuffered(false); > > // This call ensures that the JMenuBar will render over the GLCanvas. > JPopupMenu.setDefaultLightWeightPopupEnabled(false); > > // Create components. > splitPane = new JSplitPane(); > leftPanel = new JPanel(); > rightPanel = new JPanel(); > menubar = new JMenuBar(); > fileMenu = new JMenu(); > fileExit = new JMenuItem(); > //fileOpen = new JMenuItem(); > //fileClose = new JMenuItem(); > //fileSave = new JMenuItem(); > //fileSaveAs = new JMenuItem(); > > setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE); > leftPanel.setLayout(new BorderLayout()); > leftPanel.setPreferredSize(new Dimension(400, 600)); > splitPane.setLeftComponent(leftPanel); > rightPanel.setLayout(new BorderLayout()); > splitPane.setRightComponent(rightPanel); > > getContentPane().add(splitPane, BorderLayout.CENTER); > > fileMenu.setText("File"); > fileExit.setText("Exit"); > fileExit.addActionListener(new ActionListener() { > public void actionPerformed(ActionEvent evt) { > fileExitActionPerformed(evt); > } > }); > //fileOpen.setText("Open"); > //fileClose.setText("Close"); > //fileSave.setText("Save"); > //fileSaveAs.setText("Save As"); > > //fileMenu.add(fileOpen); > //fileMenu.add(fileClose); > //fileMenu.add(fileSave); > //fileMenu.add(fileSaveAs); > fileMenu.add(fileExit); > menubar.add(fileMenu); > setJMenuBar(menubar); > > panel1 = new TestPanel(); > panel2 = new TestPanel(); > leftPanel.add(panel1, BorderLayout.CENTER); > rightPanel.add(panel2, BorderLayout.CENTER); > > pack(); > > setSize(800, 600); > > // Start the animation on panel 1. > panel1.start(); > >/****************************************************** >// When we attempt to start the animation on panel 2, the >// program will either lock up or the program will run but >// panel2 won't render. It's clear that the two animator >// threads are competing for some resource, causing a >// deadlock or causing the second thread to starve. > ******************************************************/ > panel2.start(); > } > > private void fileExitActionPerformed(ActionEvent evt) { > System.exit(0); > } > > public class TestPanel extends JPanel { > GLCanvas canvas; > Animator animator; > > public TestPanel() { > // The JPanel must use the Border layout manager. > setLayout(new java.awt.BorderLayout()); > > // Create the GLCanvas. > canvas = GLDrawableFactory.getFactory().createGLCanvas(new GLCapabilities()); > canvas.addGLEventListener(new TestRenderer()); > > // Create an animator thread for the canvas. > animator = new Animator(canvas); > > // Add the canvas to the center of the JPanel. > add(canvas); > > // We need to create a Dimension object for the JPanel minimum size to fix a GLCanvas resize bug. > // The GLCanvas normally won't recieve resize events that shrink a JPanel controled by a JSplitPane. > setMinimumSize(new Dimension()); > } > > public void start(){ > animator.start(); > } > > public void stop(){ > animator.stop(); > } > > class TestRenderer implements GLEventListener { > private GL gl; > private GLDrawable gldrawable; > float angle = 0; > > public void init(GLDrawable drawable) { > gl = drawable.getGL(); > this.gldrawable = drawable; > } > > public void reshape(GLDrawable drawable, int x, int y, int width, int height) { > gl. glViewport(0, 0, width, height); > } > > public void display(GLDrawable drawable) { > gl.glClear(GL.GL_COLOR_BUFFER_BIT | GL.GL_DEPTH_BUFFER_BIT); > > gl.glRotatef(.1f, 0f, 0f, 1f); > > gl.glBegin(GL.GL_POLYGON); > gl.glVertex2f(-0.5f, -0.5f); > gl.glVertex2f(-0.5f, 0.5f); > gl.glVertex2f(0.5f, 0.5f); > gl.glVertex2f(0.5f, -0.5f); > gl.glEnd(); > } > > public void displayChanged(GLDrawable drawable, boolean modeChanged, boolean deviceChanged) {} > } > } >}
You cannot view the attachment while viewing its details because your browser does not support IFRAMEs.
View the attachment on a separate page
.
View Attachment As Raw
Actions:
View
Attachments on
bug 128
: 33 |
34
|
35