Java Fifth time job

Source: Internet
Author: User

import javax.media.; import java.awt.; import java.awt.event.; class mediaplayer extends frame implements actionlistener,controllerlistener,  itemlistener{player player; component vc, cc;boolean first = true, loop = false; string currentdirectory; mediaplayer  (String title) {super  (title); Addwindowlistener (new windowadapter  () { public void windowclosing  (windowevent e)  {//  users click the Close button of the Windows system menu//  Call Dispose to execute windowclosed dispose  ();}  public void windowClosed  (windowevent e)  {if  (player != null)  player.close  (); system.exit  (0);}); menu m = new menu  ("file"); menuitem mi = new menuitem  ("Open");mi.addactionlistener  (This);m.add  (MI); m.addseparator  (); checkboxmenuitem cbmi = new checkboxmenuitem  ("Loop", &Nbsp;false);cbmi.additemlistener  (this);m.add  (CBMI);m.addseparator  ();mi = new  menuitem  ("Exit");mi.addactionlistener  (This);m.add  (MI); menubar mb = new menubar  ();mb.add  (m);setmenubar  (MB);setSize  (200,  200);setvisible  (true);} public void actionperformed  (actionevent e) {if  (e.getactioncommand  (). equals   ("Exit")) {//  call Dispose to execute windowcloseddispose  (); return;} filedialog fd = new filedialog  (this,  "Open media file", filedialog.load); fd.setDirectory   (CurrentDirectory);fd.show  ();//  returns if  (fd.getfile  ()  == null) if the user discards the selection file  return;currentDirectory = fd.getDirectory  (;if ) (Player != null) player.close  ();try{player = manager.createplayer  (new medialocator  ("File:"  + fd.getDirectory  ()  + fd.getFile  ()));} Catch  (JAVA.IO.IOEXCEPTION E2) {system.out.println  (E2); return;} catch  (noplayerexception e2) {system.out.println  ("Player cannot be found."); return;} if  (player == null) {system.out.println  ("Unable to create player."); return;} first = false;settitle  (fd.getfile  ());p layer.addcontrollerlistener  (this); player.prefetch  ();} public void controllerupdate  (controllerevent e) {//  call Player.close () When the Controllerclosedevent event occurs.   If a visual part is present, the part should be removed (,//  we do the same for the Control Panel assembly for the sake of consistency) if  (e instanceof  controllerclosedevent) {if  (vc != null) {remove  (VC); vc = null;} if  (Cc != null) {remove  (cc); cc = null;} return;} if  (e instanceof endofmediaevent) {if  (Loop) {player.setmediatime  (new Time  ( 0));p layer.start  ();} return;} if  (e instanceof prefetchcompleteevent) {player.start  (); return;} if  (E instanceof&nbsP realizecompleteevent) {vc = player.getvisualcomponent  ();if  (vc != null) add  (VC);cc = player.getcontrolpanelcomponent  ();if  (cc != null) add  (cc,  Borderlayout.south);p ack  ();}} public void itemstatechanged  (itemevent e) {loop = !loop;} public void paint  (GRAPHICS G) {if  (first) {int w = getsize  (). width;int h = getsize  () .height;g.setcolor  (Color.Blue);g.fillRect  (0, 0,  W, H); font f = new font  ("Dialoginput",  font.bold, 16);g.setFont  (f); fontmetrics fm = g.getfontmetrics  ();int swidth = fm.stringwidth  ("* *   Welcome   ");g.setcolor  (Color.White);g.drawstring  ("   Welcome  *** ", (w - swidth)  / 2, (h + getinsets  (). top)  / 2);}   Call the Paint () method of the super-class frame, the paint () partyThe method calls the paint () method of each container//  and parts (including control Panel parts) contained in the frame. super.paint  (g);}   Do not perform background cleanup to prevent the control Panel part from flashing public void update  (graphics g) {paint  (g);} public static void main  (String [] args)  {new MediaPlayer  (" Media Player 1.0 ");}  }

Java Fifth job

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.