How To Insert Background Music Managed By JButton

Apr 16, 2014

I'm doing a little game in Java and I would like to insert a background music managed by a JButton. When the button is pressed, the music starts and then, to stop it, the button is pressed again. If you don't press the button to stop the music remains in the loop until the player plays.

View Replies


ADVERTISEMENT

Playing And Stopping Music File With Same JButton

Oct 8, 2014

This is my whole Code

import java.awt.*;
import javax.sound.sampled.AudioInputStream;
import javax.sound.sampled.AudioSystem;
import javax.sound.sampled.Clip;
import javax.sound.sampled.LineUnavailableException;
import javax.sound.sampled.UnsupportedAudioFileException;

[Code] .....

I'm not getting any errors, just i can't seem to stop the music from playing after clicking the jbutton "Sound On" / "Sound Off" again. I've tried a few methods but it just isn't working for me.

View Replies View Related

Playing And Stopping A Music File With Same JButton

Oct 8, 2014

This is my whole Code

import java.awt.*;
import javax.sound.sampled.AudioInputStream;
import javax.sound.sampled.AudioSystem;
import javax.sound.sampled.Clip;
import javax.sound.sampled.LineUnavailableException;
import javax.sound.sampled.UnsupportedAudioFileException;

[Code] ....

I'm not getting any errors, just i can't seem to stop the music from playing after clicking the jbutton "Sound On" / "Sound Off" again. I've tried a few methods but it just isn't working for me.

View Replies View Related

How To Set Background Image Of JLayeredPane And Then Add Jbutton

Apr 10, 2014

Actually i want to develop a game for that i need a background with a image and over this background i want to move some objects (which are images) and also want to add some button.

Here is my Code.

The Main Class

package last;
import java.awt.*;
import javax.swing.*;
public class Last extends JFrame{
public static void main(String[] args) {
Last l =new Last();
l.setSize(900, 600);

[Code] .....

When i execute the above program only the background image is shown.

View Replies View Related

Draw JButton Over Background Image

Aug 3, 2014

I've tried multiple things but I can't seem to figure out how to get my JButton over the background graphics. On lines 104-108 I create the JButton I need to put on the screen, though I have no clue how to draw it. How I can paint over this background and have my button stay there?

public static final int WIDTH = 1024;
public static final int HEIGHT = 640;
private Thread thread;
private boolean running;
private BufferedImage image;
private Graphics2D g;

[Code] .....

View Replies View Related

How To Insert JButton Or JCheckbox In JTable

Jun 21, 2014

I'm a beginner in java. I would like to ask, how to insert JButton on JTable..

View Replies View Related

JButton Image Does Not Show On Background Image

Feb 23, 2014

I successfully added a background image on the Panel but I can't create my JButton image on top of my background image.

ImageIcon piano = new ImageIcon("src/img/piano_backgrd.png");
JLabel backlabel = new JLabel(piano);
panel.add(backlabel, new Integer(Integer.MIN_VALUE));
backlabel.setBounds(0, 0, piano.getIconWidth(), piano.getIconHeight()); 
JButton volup = new JButton(new ImageIcon("src/img/volup.png"));
volup.setLocation(10, 0);
panel.add(volup);

View Replies View Related

Jbutton Act Like A Wall That Will Not Allow A Moving Jbutton To Pass Through

Apr 7, 2014

I am trying to have a Jbutton (blocker02) act like a wall that will not allow a moving Jbutton to pass through. I tried using " if (blocker02. getBounds (). intersects(r_wall)) but it hasn't been successful.

import java.awt.*;
import javax.swing.*;
import java.awt.event.*;
import java.awt.geom.Rectangle2D;

[code]....

View Replies View Related

Streaming Music Over Network

Apr 16, 2015

I want to make a service like Spotify, where I can stream music that I have stored on my computer (in this case server) to my laptop or phone.

* What would be a suitable format for this?
* How would I actually stream it? I want to stream, not download and then play, I want to play the music while downloading.

View Replies View Related

Music In Java ComboBox Not Playing

May 29, 2014

I am trying to create a program that plays music with a java combo box. For some reason when I hit play the music does not play.

import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import java.applet.AudioClip;
import java.net.URL;
public class JukeBoxControls extends JPanel

[Code] .....

View Replies View Related

Changing Pitch Of Music File

Dec 23, 2014

I'm making a karaoke/DJ program for a DJ friend and one of the features she wants is the ability to change the pitch of a song (some singers ask for this).

View Replies View Related

Syncing Music With Photo Transitions?

Nov 17, 2014

Web based program, basically a slide show template where the user uploads a series of photos, they are dumped into the pre-fabbed template of a predetermined set of transitions in sync with music. I will set the templates to transition based on the time stamp of the beat of the music at certain intervals. The end users will be able to then create their own slide show "movie" based on the templates.

Problems I see are the syncing between the music and the images loading. Wondering if it's doable client side or if I need to have it rendered server-side.

View Replies View Related

Java Music Player - Volume Control

Dec 5, 2014

I am currently building a java music player and need getting the volume control to work. I want to be able to set the computers volume directly using an integer. I've created a slider and put the value into an integer. The part that I am having trouble with is getting the volume to work.

View Replies View Related

Array Of Objects To Create 3 CDs (music) - Moving Songs?

Oct 17, 2014

Do I need to use inheritance for this type of program? How to move my song list in main to songs and from songs to cd to make 3 separate cd's.

I have 3 classes: main, Cd, and Song. I am having trouble moving the songs from main to the song class and from the song class to Cd.

package p2;
public class Main {
public static void main(String[] args) {
String tempStr;
//array for song names
String [] songNames={

[Code] ....

View Replies View Related

Count Down Timer To Ultimately Play A Music File

Nov 1, 2014

I have to write a program that allows the user to enter a number in a text field and starts a count down in seconds to ultimately play a music file. I am having a problem getting my text from the text field parsed into an integer so my count down can use it.

import java.util.Scanner;
import javafx.application.Application;
import javafx.geometry.Insets;
import javafx.geometry.Pos;
import javafx.scene.Scene;
import javafx.scene.control.Label;

[Code] ....

I tried to use the following:

int seconds = Integer.parseInt(tf.getText());

eclipse says simple solution remove???

View Replies View Related

JSF :: Viewscoped Managed Beans

Nov 24, 2014

I have a primefaces editable datatable with column filtering feature.The datatable has live scrolling feature.The problem that i am facing here is that both filtering and scrolling are happening correctly with Request scoped managed bean but when the scope of the same bean is changed to view scope(javax.faces.bean.ViewScoped) then the filtering happens but on removing the keyed in key word from filter box the table content is not reset to original state and also i am not able to scroll down to next set of records on reaching the end of scrolling.Cell editing feature is working perfectly.

One thing that i observed is ,currently i am querying 5000 odd records to load into datatable.But if the number of records is limited below 5000 scrolling is happening correctly but problem with filtering remains same.I even tested by upgrading to Primefaces 5.1 from 3.Code snippet of xhtml page

<h:form id="form">
<div id="content">

<p:dataTable id="workSpaceList" var="data"
value="#{workSpaceBean.list}" widgetVar="multiSelection"
selection="#{workSpaceBean.selectedRows}" resizableColumns="true"
liveScroll="true" scrollRows="10" scrollWidth="90%"
scrollHeight="70%" styleClass="datatable"
tableStyle="table-layout:auto;width:auto important!;height:auto important!;padding-left:15px;"
scrollable="true" editable="true" editMode="cell"
filteredValue="#{workSpaceBean.filteredWorkSpaceItems}"
rowKey="#{data.lpID}" >

[code]....

View Replies View Related

JSF :: Using Generic Templates For Managed Beans

Aug 5, 2014

I'm wondering if there's a way to build a template for managed beans which could be extended by a constructor instead of re-writing beans for each entity. I can do that quite easily for Dao objects by creating facades and using those facades to create Dao implementations for specific entities. Not sure if the same concept works for managed beans and haven't really come accross any searches.

I wrote the following but I'm not sure how to implement or even if the concept of generics and templating can be applied to managed beans in the same way it can be applied to Dao classes:

public class BeanTemplate<T> {
private ListDataModel<T> listModel;
@EJB
private GenDao dao;
private Class<T> entityClass;

[Code] .....

The above assumes there's only one method needed in the bean. I thought of extending like this:

public class EmployeeBean extends BeanTemplate<Employee> {
public EmployeeBean() {
super(Employee.class);
}

// how can the methods be called??

Is the same concept for creating dao templates possible for managed beans?

View Replies View Related

JSF :: Managed Bean Is Not Getting Instantiated Intermittently

Jun 5, 2014

I have a JSF bean which is request scope and corresponding JSF UI page. when user tries to open this page, we are getting exception 'Cannot instantiate user.java class <default constructor>'. This does not come always. It comes very rarely. JSF version is 1.2

View Replies View Related

JSF :: Create A Managed Bean Per View

Jun 11, 2014

About creating views,

1. When we have a view and this uses two or three managed beans and not only one, is this ok? is a good design?

2 If we have two views and both of them only share one functionality (they need to display datatable with clients) , for the second view and for the shared functionality, should I in the managed bean for the second view create the same method that gets the clients or reuse the method in the managed bean created for the first view?

View Replies View Related

JSF :: Get Data From Managed Bean Method After Servlet Filter

Feb 15, 2015

I have a situation to load data while JSF page loads. Also have a filter which populates user information from http request.

I was expecting the filter first to populate the user information and in the managed bean get method to verify the user information and get the data (from database). But in this case i see the managed bean get method is invoked before filter populates user information and i get null pointer exception because the user information is null.

I had to work around to get the user information from FacesContext in the managed bean get method because the user information wasn't available. Is there a way to make sure the filter is invoked first?

View Replies View Related

Enterprise JavaBeans :: How To Use Application Managed Entity Manager In EJB

May 9, 2014

I finish reading The EntityManager Interface in JEE tutorial. I know I can use container manager entity manager in EJB, but I want to explore how to use application managed entity manager in EJB.
 
Can I use application managed entity manager in EJB (container management JTA transaction is used)? Where do I should close entity manager if can?
 
The following is an example from JEE tutorial, but didn't find where to calose entity manager. and can I create mutiple EntityManagerFactory objects and Entity Manager objects to use them in a JTA transaction?
 
@PersistenceUnit
EntityManagerFactory emf;
EntityManager em;
@Resource
UserTransaction utx;

[Code] .....

View Replies View Related

JSF :: Primefaces In-cell Editing Not Working With Viewscoped Managed Beans?

Nov 17, 2014

I have an in-cell editable data table with a viewscoped managed bean.I found that the control never goes to the ajax event method onCellEdit when the scope of the bean is @Viewscoped but it works when the scope is changed to request scope.how to get this feature work with viewscope.Below is my code snippet

xhtml snippet

<p:dataTable id="workSpaceList" var="data"
value="#{workSpaceBean.lpInfoList}" widgetVar="multiSelection"
selection="#{workSpaceBean.selectedRows}"
scrollable="true" rowIndexVar="index" editable="true"
editMode="cell".......>

[code]....

View Replies View Related

JSF :: Count Number Of Views Created In A Session While Using Managed Bean With View Scope

Jan 30, 2014

I am trying to restrict the number of views in JSF 2.0.2 using

<context-param>
<param-name>org.apache.myfaces.NUMBER_OF_VIEWS_IN_SESSION</param-name>
<param-value>5</param-value>
</context-param>

In my case my managed bean is View Scoped and it supports a UI page which has multiple forms and each form is submitted as AJAX POST request.

As per the statndard, setting restriction to 5 should create 5 views and after that based on LRU algorithm the oldest views should get deleted if 6th views is created.

Therefore any action on the oldest view will throw the ViewExpiredException and i simply redirect the user to view expired page.

1) When i set the restriction to 5 views, i open 4 tabs with 3 forms each.
2) I submit the 3 forms on first tab everything works fine.
3) As soon as I go to 2nd tab and submit the first form thr, i get view expired exception
4) It seems I am exceeding the number of views I mentioned in web.xml

I want to know :

1) Does every AJAX POST submit itself creates a view ?
2) How I can count the number of views created in a session ?
3)Can i force expiry of a view in JSF 2.0.2 while the session is still alive ?
4) Normally JSF 2.0.2 session cachces the views. Lets assume session is alive the entire day but a view was created in morning at 9:00 AM and is not used again the entire day. Assuming that session doesn't reaches the max number of views it can save in entire day, will the view created in morning expire on its own after certain interval of time ? If not , can we still force its expiry while keeping the session alive ?

View Replies View Related

JSF :: How To Read CSV File From User Defined Directory Path For Loading To Managed Bean

Jan 10, 2015

I'm using a PrimeFaces UploadedFile xhtml page to select a csv file to read and write using a managed bean (SuperCSVParser.java). The file is read and written to an entity class which then persists the data to a database. The application works fine if I specify a file path on the physical server and select a csv file on that file path. But for the production version I want the user to select ANY file name from ANY directory on their local system.

I know about the FacesContext methods and I've looked at some methods from the java.io File class. Most of these methods are about getting the path from the server, where I want to 'pass' the path String from the client machine to allow the uploaded file to go through. When I try with the below code I get:

java.io.FileNotFoundException: data.csv (The system cannot find the file specified)

I'd like to know what I'm doing as I prefer not to explicitly declare a path in the final app. I'm almost sure that's possible.

<h:form enctype="multipart/form-data">
<p:fileUpload value="#{SuperCsvParser.file}"
mode="simple"
auto="true"

[Code].....

View Replies View Related

JSF :: Unable To Set Prime-faces Data Table Column FilterMatchMode In Managed Bean

Nov 13, 2014

I have a requirement where in my primefaces datatable ,the filterMatchMode attribute(like any part of field,whole field) needs to be selected by the user by select menu .

To achieve this i have declared a variable in my viewscoped managed bean as filterCriteria and set the filterMatchMode attribute as filterMatchMode="#{beanName.filterCriteria}".The bean variable is getting set in the managed bean on submit but the filtering is not happening,i am getting empty message.

Also when i remove the keyed in value from filter box the data table is not restored which otherwise must be restored in normal situations. I have used and modified the example code given in primefaces showcase here.The code snippet is as below

<h:form id="tblFrm">
<h:selectOneMenu id="filterOptions"
value="#{dtFilterView.filterOption}" required="true"
requiredMessage="You must select an option!">
<f:selectItem id="hd1" itemLabel="Select" itemValue="#{null}" />

[code]....

View Replies View Related

JSF :: Null Pointer Exception While Creating File From Resources In Managed Bean Class

Feb 7, 2014

i want to list files from resources folder like this:

@ManagedBean
public class galley implements Serializable {
private List<String> list;
@PostConstruct
public void init() {
list = new ArrayList<String>();

[Code] ....

but it give me a null pointer exception on fList .... The directory of resources is :

How is this caused and how can I solve it?

View Replies View Related







Copyrights 2005-15 www.BigResource.com, All rights reserved