private JButton getMixerDefaultButton() { if (mixerDefaultButton == null) { mixerDefaultButton = new JButton("Default"); mixerDefaultButton.setMnemonic('u'); mixerDefaultButton.setDisplayedMnemonicIndex(4); mixerDefaultButton.addActionListener(eventHandler); } return mixerDefaultButton; }
private JButton getDisableAllSoundsButton() { if (disableAllSoundsButton == null) { disableAllSoundsButton = new JButton("Disable all"); disableAllSoundsButton.setMnemonic('i'); disableAllSoundsButton.setDisplayedMnemonicIndex(1); disableAllSoundsButton.addActionListener(eventHandler); } return disableAllSoundsButton; }
private JButton getEnableAllSoundsButton() { if (enableAllSoundsButton == null) { enableAllSoundsButton = new JButton("Enable all"); enableAllSoundsButton.setMnemonic('a'); enableAllSoundsButton.setDisplayedMnemonicIndex(7); enableAllSoundsButton.addActionListener(eventHandler); } return enableAllSoundsButton; }
public HotSMain() { // General setPreferredSize(new Dimension(800, 600)); canvas.add(this); setBackground(Color.GRAY); frame.setResizable(false); frame.setTitle("Heroes of the Forest"); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); // Overworld menuScreen.setPreferredSize(new Dimension(800, 150)); menuScreen.setBackground(Color.DARK_GRAY); menuScreen.setVisible(false); menuButtons.add(itemsButton); menuButtons.add(equipButton); menuButtons.add(skillsButton); menuButtons.add(statusButton); menuButtons.add(settingsButton); menuButtons.add(dataButton); for (JButton button : menuButtons) { menuScreen.add(button); button.addActionListener(this); } canvas.add(menuScreen, BorderLayout.SOUTH); ImageIcon bg = new ImageIcon("OverworldBG.jpg"); background = bg.getImage(); frame.pack(); frame.setVisible(true); player = new Player(); enemies.add(new Stalker(375, 200)); player.defaultPlayer(); frame.addKeyListener(this); frame.addMouseListener(this); frame.addMouseMotionListener(this); moveTimer.start(); }
/** * Method to handle the line event update * * @param e the line event */ public void update(LineEvent e) { if (e.getType().equals(LineEvent.Type.CLOSE)) { playBtn.setEnabled(true); stopBtn.setEnabled(false); pauseBtn.setEnabled(false); if (wavePanel.moreZoomInScope()) { playSelectionBtn.setEnabled(true); zoomInBtn.setEnabled(true); } if (wavePanel.moreZoomOutScope()) zoomOutBtn.setEnabled(true); isPlaying = false; playSelClicked = 0; } }
////////////// methods to create the interactive visualizer //////////////////////// private void createMainFrame() { mainFrame = new JFrame(); mainFrame.setDefaultCloseOperation(JFrame.HIDE_ON_CLOSE); Container contentPane = mainFrame.getContentPane(); // contentPane.setLayout(new BorderLayout()); // creates the control panel controlPanel = new JPanel(null); controlPanel.setLayout(new FlowLayout()); makeSoundVis(); mainFrame.addComponentListener(new ResizeHandler()); // setting up the play sound button playBtn = new JButton("Play"); playBtn.setEnabled(true); playBtn.setToolTipText("Play the sound"); playBtn.addActionListener( new ActionListener() { public void actionPerformed(ActionEvent event) { stopBtn.setEnabled(true); pauseBtn.setEnabled(true); playBtn.setEnabled(false); playSelectionBtn.setEnabled(false); zoomInBtn.setEnabled(false); zoomOutBtn.setEnabled(false); isPlaying = true; myHelper.play(); } }); controlPanel.add(playBtn); // setting up the play selection button playSelectionBtn = new JButton("Play Selection"); playSelectionBtn.setEnabled(false); playSelectionBtn.setToolTipText("Play sound between start and stop index"); playSelectionBtn.addActionListener( new ActionListener() { public void actionPerformed(ActionEvent event) { playSelClicked++; stopBtn.setEnabled(true); pauseBtn.setEnabled(true); playSelectionBtn.setEnabled(false); playBtn.setEnabled(false); zoomInBtn.setEnabled(false); zoomOutBtn.setEnabled(false); isPlaying = false; if (playSelClicked == 1) { myHelper.playInRange( wavePanel.getSelectionStartSample(), wavePanel.getSelectionEndSample()); } else { myHelper.play(); } } }); controlPanel.add(playSelectionBtn); // setting up the stop button stopBtn = new JButton("Stop"); stopBtn.setEnabled(false); stopBtn.setToolTipText("Stop playing the sound"); stopBtn.addActionListener( new ActionListener() { public void actionPerformed(ActionEvent event) { myHelper.stop(); stopBtn.setEnabled(false); pauseBtn.setEnabled(false); playBtn.setEnabled(true); if (wavePanel.moreZoomInScope()) { zoomInBtn.setEnabled(true); playSelectionBtn.setEnabled(true); } if (wavePanel.moreZoomOutScope()) { zoomOutBtn.setEnabled(true); } playSelClicked = 0; isPlaying = false; } }); controlPanel.add(stopBtn); // setting up the stop button pauseBtn = new JButton("Pause"); pauseBtn.setEnabled(false); pauseBtn.setToolTipText("Pause the sound"); pauseBtn.addActionListener( new ActionListener() { public void actionPerformed(ActionEvent event) { myHelper.pause(); if (isPlaying) { playBtn.setEnabled(true); } else { playSelectionBtn.setEnabled(true); } } }); controlPanel.add(pauseBtn); // setting up the zoom button zoomInBtn = new JButton("Zoom In"); zoomInBtn.setEnabled(false); zoomInBtn.setToolTipText("Click to see the samples within your selection"); zoomInBtn.addActionListener( new ActionListener() { public void actionPerformed(ActionEvent event) { handleZoomIn(); } }); controlPanel.add(zoomInBtn); // setting up the zoom button zoomOutBtn = new JButton("Zoom Out"); zoomOutBtn.setEnabled(false); zoomOutBtn.setToolTipText("Click to zoom out"); zoomOutBtn.addActionListener( new ActionListener() { public void actionPerformed(ActionEvent event) { handleZoomOut(); } }); controlPanel.add(zoomOutBtn); controlPanel.setBounds(0, controlLocY, frameWidth, controlHeight); contentPane.add(controlPanel); contentPane.add(wavePanel); contentPane.add(overViewPanel); wavePanel.setBounds(0, waveLocY, frameWidth, waveHeight); // controlPanel.removeAll(); // controlPanel.setBackground(Color.CYAN); mainFrame.setSize(frameWidth, frameHeight); overViewPanel.init(); wavePanel.init(); // // mainFrame.pack(); // mainFrame.setResizable(false); // mainFrame.validate(); mainFrame.setVisible(true); overViewPanel.setBounds(0, 0, frameWidth, overViewHeight); // mainFrame.validate(); }
public void actionPerformed(ActionEvent a) { Object source = a.getSource(); if (scene == OVERWORLD) { if (source == moveTimer) { if (moveUp && !moveDown) player.moveUp(); else if (!moveUp && moveDown) player.moveDown(); if (moveLeft && !moveRight) player.moveLeft(); else if (!moveLeft && moveRight) player.moveRight(); } if (source == itemsButton) itemsButton.setText("ITEMS!"); else if (source == equipButton) equipButton.setText("EQUIPMENT!"); else if (source == skillsButton) skillsButton.setText("SKILLS"); else if (source == settingsButton) settingsButton.setText("SETTINGS"); else if (source == statusButton) statusButton.setText("STATUS"); else if (source == dataButton) dataButton.setText("DATA"); } if (scene == BATTLE) { if (source == moveTimer) { // Spell Movement for (int spellNum = 0; spellNum < spellsThrown.size(); spellNum++) { Spell spell = spellsThrown.get(spellNum); spell.move(); if (spell.spellHit()) { enemies.get(spell.getTarget()).takeDamage(spell.getDamage()); enemies.get(spell.getTarget()).statusPresent(spell.getEffect()); spellsThrown.remove(spellNum); checkEnemyPresence(); } } for (int enemyLoop = 0; enemyLoop < enemies.size(); enemyLoop++) { Enemy enemy = enemies.get(enemyLoop); for (int spellNum = 0; spellNum < enemy.spellsThrown.size(); spellNum++) { Spell spell = enemy.spellsThrown.get(spellNum); spell.move(); if (spell.spellHit()) { player.takeDamage(spell.getDamage()); enemy.spellsThrown.remove(spellNum); checkAllyPresence(); } } } } if (source == staminaTimer) { // Stamina Regeneration player.staminaGain(16); // Enemy Attacks int enemyLoop; for (enemyLoop = 0; enemyLoop < enemies.size(); enemyLoop++) { enemies.get(enemyLoop).attack(player.centerX(), player.centerY(), 12); } } } repaint(); // To check collision if (scene == OVERWORLD) { for (int loop = 0; loop < enemies.size(); loop++) { Enemy enemy = enemies.get(loop); if (enemy.hitbox().intersects(player.hitbox())) { player.combatChange(true); enemy.combatChange(true); battleBegin(); } } } }
// Public constructor public ElectronicOrganFrame(String title) { // Call parent constructor to give title to frame super(title); // Make this frame its own window listener addWindowListener(windowListener); // Panel components: waveformPanel waveformPanel.setBorder( new TitledBorder(new BevelBorder(BevelBorder.RAISED), "Waveform Options")); GridBagLayout waveformPanelGridBag = new GridBagLayout(); GridBagConstraints waveformPanelConstr = new GridBagConstraints(); waveformPanel.setLayout(waveformPanelGridBag); waveformPanelConstr.anchor = GridBagConstraints.CENTER; waveformPanelConstr.weightx = 1.0; waveformPanelConstr.weighty = 1.0; waveformPanelConstr.fill = GridBagConstraints.BOTH; waveformPanelConstr.gridx = 0; waveformPanelConstr.gridy = 0; waveformPanelConstr.gridwidth = 1; waveformPanelConstr.gridheight = 1; waveformPanelGridBag.setConstraints(sineButton, waveformPanelConstr); waveformPanel.add(sineButton); waveformPanelRadio.add(sineButton); sineButton.addActionListener(actionListener); waveformPanelConstr.gridx = 1; waveformPanelConstr.gridy = 0; waveformPanelConstr.gridwidth = 1; waveformPanelConstr.gridheight = 1; waveformPanelGridBag.setConstraints(squareButton, waveformPanelConstr); waveformPanel.add(squareButton); waveformPanelRadio.add(squareButton); squareButton.addActionListener(actionListener); waveformPanelConstr.gridx = 2; waveformPanelConstr.gridy = 0; waveformPanelConstr.gridwidth = 1; waveformPanelConstr.gridheight = 1; waveformPanelGridBag.setConstraints(sawtoothButton, waveformPanelConstr); waveformPanel.add(sawtoothButton); waveformPanelRadio.add(sawtoothButton); sawtoothButton.addActionListener(actionListener); waveformPanelConstr.gridx = 3; waveformPanelConstr.gridy = 0; waveformPanelConstr.gridwidth = 1; waveformPanelConstr.gridheight = 1; waveformPanelGridBag.setConstraints(triangleButton, waveformPanelConstr); waveformPanel.add(triangleButton); waveformPanelRadio.add(triangleButton); triangleButton.addActionListener(actionListener); // Panel components: exitPanel exitPanel.setLayout(new GridLayout(1, 5)); exitPanel.add(label1); exitPanel.add(label2); exitPanel.add(exitButton); exitButton.addActionListener(actionListener); exitPanel.add(label3); exitPanel.add(label4); GridBagLayout thisGridBag = new GridBagLayout(); GridBagConstraints thisConstr = new GridBagConstraints(); this.getContentPane().setLayout(thisGridBag); thisConstr.anchor = GridBagConstraints.CENTER; thisConstr.weightx = 1.0; thisConstr.weighty = 1.0; thisConstr.fill = GridBagConstraints.BOTH; thisConstr.gridx = 0; thisConstr.gridy = 0; thisConstr.gridwidth = 3; thisConstr.gridheight = 1; thisGridBag.setConstraints(label5, thisConstr); this.getContentPane().add(label5); thisConstr.gridx = 0; thisConstr.gridy = 1; thisConstr.gridwidth = 1; thisConstr.gridheight = 1; thisGridBag.setConstraints(label6, thisConstr); this.getContentPane().add(label6); thisConstr.gridx = 1; thisConstr.gridy = 1; thisConstr.gridwidth = 1; thisConstr.gridheight = 1; thisGridBag.setConstraints(waveformPanel, thisConstr); this.getContentPane().add(waveformPanel); thisConstr.gridx = 2; thisConstr.gridy = 1; thisConstr.gridwidth = 1; thisConstr.gridheight = 1; thisGridBag.setConstraints(label7, thisConstr); this.getContentPane().add(label7); thisConstr.gridx = 1; thisConstr.gridy = 2; thisConstr.gridwidth = 1; thisConstr.gridheight = 1; thisGridBag.setConstraints(exitPanel, thisConstr); this.getContentPane().add(exitPanel); // Set frame size and show it setSize(500, 200); setVisible(true); } // Frame constructor ElectronicOrganFrame ()