Java design graphics and multimedia processing _java

Source: Internet
Author: User

This article has achieved two effects:

The first, concentric circle effect diagram:

/** * Program requirements: Create a new 600*600 pixel application window, and in the window to draw 5 different colors of concentric circles, * All centers are the center of the screen, the adjacent two Circle direct radius of 50 pixels * effect Diagram as shown below (color randomly set), the source program saved as Ex7_1. 
 Java. 
 * Author: WWJ * Date: 2012/4/25 * Function: Display a concentric round **/import javax.swing.* with 5 different colors; 
 Import java.awt.*; 
 Import Java.awt.Color; 
   public class Ex7_1 extends JFrame {int red,green,blue; 
 
   Color color;  Public Ex7_1 () {super ("a concentric circle with 5 different colors");           Display window name SetSize (600,600);           Sets the window size setvisible (TRUE); 
   Set to Visible setdefaultcloseoperation (jframe.exit_on_close);/Set window close action} public void Paint (Graphics g) 
    {///First round red= (int) (Math.random () *255); 
    green= (int) (Math.random () *255); 
    blue= (int) (Math.random () *255); 
    Color=new Color (Red,green,blue); 
    G.setcolor (color); 
    G.filloval (175,175,250,250); 
    The second circular red= (int) (Math.random () *255); 
    green= (int) (Math.random () *255); 
    blue= (int) (Math.random () *255); 
    Color=new Color (Red,green,blue); G.setcolor (color); 
    G.filloval (200,200,200,200); 
    The third circular red= (int) (Math.random () *255); 
    green= (int) (Math.random () *255); 
    blue= (int) (Math.random () *255); 
    Color=new Color (Red,green,blue); 
    G.setcolor (color); 
    G.filloval (225,225,150,150); 
    Fourth round red= (int) (Math.random () *255); 
    green= (int) (Math.random () *255); 
    blue= (int) (Math.random () *255); 
    Color=new Color (Red,green,blue); 
    G.setcolor (color); 
    G.filloval (250,250,100,100); 
    Fifth round red= (int) (Math.random () *255); 
    green= (int) (Math.random () *255); 
    blue= (int) (Math.random () *255); 
    Color=new Color (Red,green,blue); 
    G.setcolor (color); 
 
   G.filloval (275,275,50,50);    
   public static void Main (string[] args) {ex7_1 e = new Ex7_1 ();  } 
 
 }

Second, the small program effect chart that plays music and toggles pictures:

/** * Program Requirements: Write a small applet program, prepare 5 pictures and three music files, draw into the applet, * and add a few buttons to control the image of the switch, zoom in, zoom out and music file playback. 
 * Author: WWJ * Date: 2012/4/29 * Reference: Neicole * Function: can carry out pictures and songs of the selection of Small applet program **/import javax.swing.*; 
 Import java.awt.*; 
 Import java.awt.event.*; 
 Import Java.applet.Applet; 
 
  
 Import Java.applet.AudioClip; 
   public class Ex7_2 extends Applet implements Actionlistener,itemlistener {//Create two Panels JPanel p1=new (); 
   JPanel p2=new JPanel (); 
   JPanel p3=new JPanel (); 
   Sound Object audioclip[] sound=new audioclip[3]; 
   int playingsong=0; 
   Toggle the picture button JButton lastpic=new JButton ("previous"); 
   JButton setlarge=new JButton ("enlarge"); 
   JButton setlittle=new JButton ("shrink"); 
   JButton nextpic=new JButton ("next sheet"); 
   Toggle the song button JButton lastsound=new JButton ("previous"); 
   JButton play=new JButton ("Play"); 
   JButton loop=new JButton ("continuous"); 
   JButton stop=new JButton ("Stop"); 
   JButton nextsound=new JButton ("next song"); 
   Track dropdown list JComboBox xx; String names[]={"Track 1.wav", "Track 2.wav ", Track 3.wav"}; 
 
    
 
   Create Canvas object MYCANVASL Showphotos; 
 
     public void init () {//Window layout this.setlayout (new BorderLayout ()); 
     Register the Listener Lastpic.addactionlistener for the Picture control button (this); 
     Setlarge.addactionlistener (this); 
     Setlittle.addactionlistener (this); 
 
     Nextpic.addactionlistener (this); 
     Add components to the Panel P1 P1.add (lastpic); 
     P1.add (Setlarge); 
     P1.add (Setlittle); 
     P1.add (Nextpic); 
   
    P1.repaint (); 
    Instantiate the Drop-down List object xx = new JComboBox (names); 
 
    Xx.additemlistener (this); 
    Register listener Lastsound.addactionlistener for control play Music button (this); 
    Play.addactionlistener (this); 
    Loop.addactionlistener (this); 
    Stop.addactionlistener (this); 
 
    Nextsound.addactionlistener (this); for (int i=0;i<3;i++) {sound[i]=getaudioclip (GetCodeBase (), music/+ tracks +integer.tostring (i+1) 
     + ". wav"); 
     ////Add component to panel P2 p2.add (XX); 
     P2.add (Lastsound); P2.add (PLay); 
     P2.add (loop); 
     P2.add (stop); 
     P2.add (Nextsound); 
     
    P2.repaint (); 
    Showphotos = new MYCANVASL (); 
     P3.add (Showphotos); 
 
    P3.repaint (); 
     The panel p1 and P2 are respectively arranged to the north and south of the window Add (P1,borderlayout.north); 
     Add (P2,borderlayout.south); 
 
     Add (P3,borderlayout.center); 
 
   This.repaint (); 
      }//button event handling public void actionperformed (ActionEvent e) {if (e.getsource () = = Lastpic) { 
    Showphotos.changephotoshow (' P '); 
    else if (e.getsource () = = Nextpic) {showphotos.changephotoshow (' N '); 
    else if (e.getsource () = = Setlarge) {showphotos.changephotosize (' B '); 
    else if (e.getsource () = = Setlittle) {showphotos.changephotosize (' S '); 
      else if (E.getsource () ==lastsound) {//previous sound[playingsong].stop (); 
      playingsong= (playingsong-1+3)%3; 
      Xx.setselectedindex (Playingsong); 
 
    Sound[playingsong].play (); else if (E.GETSOURCE () ==play) {//Press the play button Sound[playingsong].play (); 
    else if (E.getsource () ==loop) {//press the Loop button Sound[playingsong].loop (); 
    else if (E.getsource () ==stop) {//Press stop button sound[playingsong].stop (); 
      } else{//Next sound[playingsong].stop (); 
      playingsong= (playingsong+1)%3; 
      Xx.setselectedindex (Playingsong); 
 
    Sound[playingsong].play (); 
     The event handling of the//dropdown list is public void itemstatechanged (ItemEvent e) {sound[playingsong].stop (); 
   Sound[playingsong]=getaudioclip (GetCodeBase (), "music/" +xx.getselecteditem ()); 
 
    Class MYCANVASL extends Canvas {public image[] img=new image[5]; 
    int maxwidth = 600; 
    int maxheight = 500; 
    int nowimageindex = 0; 
    int Coordinatex = 0; 
    int coordinatey = 0; 
    int currentwidth = MaxWidth; 
 
     
    int currentheight = MaxHeight; 
     MYCANVASL () {setSize (maxwidth,maxheight); Gets the currentPicture for (int i=0;i<5;i++) {img[i]=getimage (GetCodeBase (), "image/" +integer.tostring (i+1) + ". jpg") in the directory 
      } private void Changephotoindex (int index) {nowimageindex = index; 
    Changephotosize (' M '); The public void changephotoshow (char command) {if (' P ' = = command) {changephotoindex (Nowimageinde 
      x + 5-1)% 5); 
      else if (' N ' = command) {changephotoindex (Nowimageindex + 1)% 5); } public void Changephotosize (char command) {if (' M ' = = command) {currentwidth = Ma 
        Xwidth; 
      Currentheight = MaxHeight; else if (' B ' = command) {if (MaxWidth >= (currentwidth +) && maxheight >= (Currentheig 
          HT +) {currentwidth + + 100; 
        Currentheight + 100; ' Else if ' (' S ' = command) {if ((0 < (currentWidth-100)) && (0 < CurrentHeight-1 
   00))) {       Currentwidth = currentWidth-100; 
        Currentheight = currentHeight-100; 
      } Coordinatex = (maxwidth-currentwidth)/2; 
      Coordinatey = (maxheight-currentheight)/2; 
    Repaint (); The//paint method is used to display the picture in the window public void paint (Graphics g) {G.drawimage (Img[nowimageindex],coordinatex,coordinat 
 
   Ey,currentwidth,currentheight,this);  } 
  } 
 }

  above is about Java graphics design and multimedia processing of all the content, I hope to help you learn.

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.