public GLDemo() { super(VNMRFrame.getVNMRFrame(), "Jogl Demo", false); DisplayOptions.addChangeListener(this); contentPane = getContentPane(); contentPane.setLayout(new BorderLayout()); gradientPanel = createGradientPanel(); contentPane.add(gradientPanel, BorderLayout.CENTER); checkBox = new JCheckBox("Transparent", true); checkBox.setActionCommand("transparancy"); checkBox.addActionListener(this); optionsPan = new JPanel(); optionsPan.setLayout(new SimpleH2Layout(SimpleH2Layout.LEFT, 5, 0, true, false)); optionsPan.setBorder(new EtchedBorder(EtchedBorder.LOWERED)); optionsPan.add(checkBox); runButton = new JToggleButton("Run"); runButton.setActionCommand("run"); runButton.setSelected(false); runButton.addActionListener(this); optionsPan.add(runButton); getContentPane().add(optionsPan, BorderLayout.SOUTH); setSize(300, 300); setLocation(300, 300); addWindowListener( new WindowAdapter() { public void windowClosing(WindowEvent e) { // Run this on another thread than the AWT event queue to // make sure the call to Animator.stop() completes before // exiting new Thread( new Runnable() { public void run() { stop(); } }) .start(); } }); setVisible(false); }
public void stop() { runButton.setSelected(false); runButton.repaint(); animator.stop(); }
public void start() { runButton.setSelected(true); runButton.repaint(); animator.start(); }
public void actionPerformed(ActionEvent e) { Object src = e.getSource(); if (src == timer) { for (int i = 0; i < speed; i++) // integrate a few steps md.vv(); repaint(); return; } boolean adjCanvasScale = false; if (src == bTstat) md.thermostat = !md.thermostat; if (src == bPot) { md.ljPotential = !md.ljPotential; md.clearData(); if (timer.isRunning()) timer.stop(); bStart.setSelected(false); bStart.setText("Start"); md.init(md.rho); } if (src == tTemp || src == bReset) { double kT = Double.parseDouble(tTemp.getText().trim()); if (kT < 1e-8) { kT = 1e-8; tTemp.setText(" " + kT); } md.kT = kT; md.clearData(); } if (src == tRho || src == bReset) { double rho = Double.parseDouble(tRho.getText().trim()); if (rho < 1e-3) { rho = 1e-3; tRho.setText(" " + rho); } if (rho > 1.2) { rho = 1.2; tRho.setText(" " + rho); } md.setDensity(rho); md.clearData(); adjCanvasScale = true; } if (src == tSpeed || src == bReset) { speed = Integer.parseInt(tSpeed.getText().trim()); if (speed < 1) { speed = 1; tSpeed.setText(" " + speed); } } if (src == bRetime) md.clearData(); if (src == bStart) { boolean on = bStart.isSelected(); if (on) { timer.restart(); bStart.setText("Pause"); } else { timer.stop(); bStart.setText("Resume"); } } if (src == tNum) { int n = Integer.parseInt(tNum.getText().trim()); if (n < 2) { n = 2; tNum.setText(" " + n); } md.N = n; md.init(md.rho); adjCanvasScale = true; } if (src == bReset) { if (timer.isRunning()) timer.stop(); bStart.setSelected(false); bStart.setText("Start"); md.init(md.rho); } canvas.refresh(md.getXWrap(), md.N, true, adjCanvasScale); repaint(); }