/** constructor */ public DanceQueuePanel() { // flow layout setLayout(new FlowLayout()); // uses buffer to draw arrows based on queues in an array myImage = new BufferedImage(600, 600, BufferedImage.TYPE_INT_RGB); myBuffer = myImage.getGraphics(); // uses timer to queue buffer changes time = 0; timer = new Timer(5, new Listener()); timer.start(); setFocusable(true); // picks instructions based on song & level if (Danceoff.getSong() == -1 && Danceoff.getDifficulty() == 0) { arrows = new Arrow[] {new UpArrow(1000), new DownArrow(2000), new LeftArrow(3000)}; } // setBorder(BorderFactory.createTitledBorder(BorderFactory.createLineBorder(Color.BLACK, 3), // "DanceQueuePanel")); // load images for arrows rightArrowImg = null; leftArrowImg = null; upArrowImg = null; downArrowImg = null; try { rightArrowImg = ImageIO.read(new File("arrowB right.png")); leftArrowImg = ImageIO.read(new File("arrowB left.png")); upArrowImg = ImageIO.read(new File("arrowB up copy.png")); downArrowImg = ImageIO.read(new File("arrowB down.png")); } catch (IOException e) { warn("YOU FAIL", e); System.exit(2); } }
/** * Redraw all the images so that changes in options can take effect CAUTION: setupNestedStates * will hog up some of CPU's time but, it has to be performed to keep nesting upto date */ void Refresh() { waitCursor(); blink = false; blFlag = true; if (timer.isRunning()) timer.stop(); int prevH = getPrev(currImg.imgIdH); int nextH = getNext(currImg.imgIdH); waitCursor(); all_states.visible.SetupNestedStates(); normalCursor(); img[prevH].drawStuff(); img[nextH].drawStuff(); currImg.drawStuff(); if (blink) timer.start(); repaint(); parent.vcanvas1.repaint(); parent.vcanvas2.repaint(); parent.vport.setViewPosition(new Point(panePosX, 0)); debug.println("Refresh() : .parent.vport.setViewPosition(" + panePosX + ", 0)"); normalCursor(); }
public void paintComponent(Graphics g) { // We request keyboard focus out here so that we can catch events for locking zoom, etc. requestFocus(); // 3 Images are painted each time. The reason we use images rather than directly drawing // onto the graphics context is that the drawings of one image can be taking place // concurrently with the other using threads into offscreen graphic contexts assoc. // with the respective images. While printing we do the opposite if (setupComplete && currImg != null) { int prevH = getPrev(currImg.imgIdH); int nextH = getNext(currImg.imgIdH); if (blFlag || !timer.isRunning()) { img[prevH].paintStuff1(0, g, this); currImg.paintStuff1(_xPix, g, this); img[nextH].paintStuff1(_xPix + _xPix, g, this); /*g.drawImage (img [prevH].img, 0, 0, this); g.drawImage (img [prevH].timeimg, 0, _yPix, this); g.drawImage (currImg.img, _xPix, 0, this); g.drawImage (currImg.timeimg, _xPix, _yPix, this); g.drawImage (img [nextH].img, _xPix + _xPix, 0, this); g.drawImage (img [nextH].timeimg, _xPix + _xPix, _yPix, this);*/ } else { img[prevH].paintStuff2(0, g, this); currImg.paintStuff2(_xPix, g, this); img[nextH].paintStuff2(_xPix + _xPix, g, this); /*g.drawImage (img [prevH].img1, 0, 0, this); g.drawImage (img [prevH].timeimg, 0, _yPix, this); g.drawImage (currImg.img1, _xPix, 0, this); g.drawImage (currImg.timeimg, _xPix, _yPix, this); g.drawImage (img [nextH].img1, _xPix + _xPix, 0, this); g.drawImage (img [nextH].timeimg, _xPix + _xPix, _yPix, this);*/ } } if (zoomLkLineDispStatus && zXTime >= begTime && zXTime <= endTime) { int xcord = panePosX + getEvtXCord(zXTime - begTime); g.setColor(Color.white); g.drawLine(xcord, 0, xcord, _yPix); g.fillRect(xcord, _yPix - lineSize, zLockStrW + 2, lineSize); g.setColor(Color.black); g.drawRect(xcord, _yPix - lineSize, zLockStrW + 1, lineSize - 1); g.setColor(Color.red); g.drawString("Zoom Lock", xcord + 1, _yPix - fDescent); } if (elTLineDispStatus && elapsedPoint >= begTime && elapsedPoint <= endTime) { int xcord = panePosX + getEvtXCord(elapsedPoint - begTime); g.setColor(Color.white); g.drawLine(xcord, 0, xcord, _yPix); g.fillRect(xcord, _yPix - lineSize, elTimeStrW + 2, lineSize); g.setColor(Color.black); g.drawRect(xcord, _yPix - lineSize, elTimeStrW + 1, lineSize - 1); g.setColor(Color.red); g.drawString("Elapsed Time", xcord + 1, _yPix - fDescent); } }
public LJ3MDApp() { tNum.setHorizontalAlignment(JTextField.CENTER); tTemp.setHorizontalAlignment(JTextField.CENTER); tRho.setHorizontalAlignment(JTextField.CENTER); tSpeed.setHorizontalAlignment(JTextField.CENTER); tAvK.setHorizontalAlignment(JTextField.RIGHT); tAvU.setHorizontalAlignment(JTextField.RIGHT); tAvp.setHorizontalAlignment(JTextField.RIGHT); float[] aveKing = new float[501]; float[] avePot = new float[501]; float[] aveEn = new float[501]; JFrame box = new JFrame(); box.setLayout(new BorderLayout()); box.setSize(1000, 1000); box.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); cpnl = new JPanel(); // create a panel for controls cpnl.setLayout(new GridLayout(18, 2)); box.add(cpnl, BorderLayout.EAST); // add controls cpnl.add(bStart); bStart.addActionListener(this); cpnl.add(bReset); bReset.addActionListener(this); cpnl.add(new JLabel(" N:")); tNum.addActionListener(this); cpnl.add(tNum); cpnl.add(new JLabel(" Density (\u03c1):")); tRho.addActionListener(this); cpnl.add(tRho); cpnl.add(new JLabel(" Steps/frame:")); tSpeed.addActionListener(this); cpnl.add(tSpeed); cpnl.add(bTstat); bTstat.addActionListener(this); cpnl.add(bPot); bPot.addActionListener(this); cpnl.add(new JLabel(" < K/N > :")); tAvK.setEditable(false); cpnl.add(tAvK); cpnl.add(new JLabel(" Temperature:")); tTemp.setEditable(false); cpnl.add(tTemp); cpnl.add(new JLabel(" < U/N > :")); tAvU.setEditable(false); cpnl.add(tAvU); cpnl.add(new JLabel(" < pressure > :")); tAvp.setEditable(false); cpnl.add(tAvp); cpnl.add(bRetime); bRetime.addActionListener(this); spnl = new JPanel(); // create a panel for status box.add(spnl, BorderLayout.SOUTH); lStatus.setFont(new Font("Courier", 0, 12)); spnl.add(lStatus); canvas = new XYZCanvas(); box.add(canvas, BorderLayout.CENTER); timer = new Timer(delay, this); timer.start(); // timer.stop(); box.setVisible(true); }
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(); }