java - How to stop the audio when open new JFrame -


i doing security warning if user enter wrong password more 5 time, pop out frame asking user unlock , frame keep on looping warning sound. after user unlock it, jump login frame. problem after unlock it, system jump login frame sound still running. why?

this button code jump login frame

staff s = new staff();        string id = m_id.gettext();        string pass = m_pass.gettext();         string position = "manager";         try{             string sql = "select * staff position='"+position+"'";             pst=conn.preparestatement(sql);             rs=pst.executequery();              while(rs.next()){                 string add = rs.getstring("staff_id");                s.setstaff_id(add);                  string add2 = rs.getstring("password");                 s.setpassword(add2);              }              if((s.getstaff_id().equals(id)) && (s.getpassword().equals(pass))){                     warning(clip);                 dispose();                 new login().setvisible(true);              }          }catch(exception e){             joptionpane.showmessagedialog(null,e.getmessage());         } 

and use loop sound

private void warning(){         try {           url url = this.getclass().getclassloader().getresource("sound/aleart.wav");          audioinputstream audioin = audiosystem.getaudioinputstream(url);           clip clip = audiosystem.getclip();           clip.open(audioin);          clip.loop(clip.loop_continuously);                          }catch(exception ex){             joptionpane.showmessagedialog(null, ex.getmessage());         }     } 

my gui name warninglogin , call warning() here.

public warninglogin() {               initcomponents();                 warning(); } 

first clip needs instance field of class...

public class ... {     private clip clip; 

then when create it, need reference value...

//clip clip = audiosystem.getclip(); clip = audiosystem.getclip(); 

now, i'd using windowlistener , when windowclosing event raised, try calling clip.stop() , because i'm pedantic, clip.close()


Comments

Popular posts from this blog

html5 - What is breaking my page when printing? -

c# - must be a non-abstract type with a public parameterless constructor in redis -

ajax - PHP/JSON Login script (Twitter style) not setting sessions -