成人免费xxxxx在线视频软件_久久精品久久久_亚洲国产精品久久久_天天色天天色_亚洲人成一区_欧美一级欧美三级在线观看

Java程序設計:圖形與多媒體處理

開發 后端
本文主要介紹了Java的圖形設計以及多媒體處理,源碼作者也做了詳細的注釋,對于初學者應該不難。詳細請看下文

同心圓效果圖:

  1. /**  
  2.  *程序要求:新建一個600*600像素的應用程序窗口,并在窗口中繪制5個不同顏色的同心圓,  
  3.  *所有圓心都是屏幕的中心點,相鄰兩個圓直接的半徑相差50像素  
  4.  *效果圖如下圖所示(顏色隨機設置),源程序保存為Ex7_1.java。  
  5.  *作者:wwj  
  6.  *日期:2012/4/25  
  7.  *功能:顯示一個有5個不同顏色的同心圓  
  8.  **/ 
  9.  
  10.  import javax.swing.*;  
  11.  import java.awt.*;  
  12.  import java.awt.Color;  
  13.  public class Ex7_1 extends JFrame  
  14.  {  
  15.      int red,green,blue;  
  16.      Color color;  
  17.  
  18.      public Ex7_1()  
  19.      {  
  20.          super("一個有5個不同顏色的同心圓");    //顯示窗口名稱  
  21.          setSize(600,600);                      //設置窗口大小  
  22.          setVisible(true);                      //設置為可見  
  23.          setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);//設置窗口關閉動作  
  24.       
  25.      }  
  26.  
  27.       
  28.      public void paint(Graphics g)  
  29.      {  
  30.          //第一個圓  
  31.         red=(int)(Math.random()*255);  
  32.         green=(int)(Math.random()*255);  
  33.         blue=(int)(Math.random()*255);  
  34.         color=new Color(red,green,blue);  
  35.         g.setColor(color);  
  36.         g.fillOval(175,175,250,250);  
  37.         //第二個圓  
  38.         red=(int)(Math.random()*255);  
  39.         green=(int)(Math.random()*255);  
  40.         blue=(int)(Math.random()*255);  
  41.         color=new Color(red,green,blue);  
  42.         g.setColor(color);  
  43.         g.fillOval(200,200,200,200);  
  44.         //第三個圓  
  45.         red=(int)(Math.random()*255);  
  46.         green=(int)(Math.random()*255);  
  47.         blue=(int)(Math.random()*255);  
  48.         color=new Color(red,green,blue);  
  49.         g.setColor(color);  
  50.         g.fillOval(225,225,150,150);  
  51.         //第四個圓  
  52.         red=(int)(Math.random()*255);  
  53.         green=(int)(Math.random()*255);  
  54.         blue=(int)(Math.random()*255);  
  55.         color=new Color(red,green,blue);  
  56.         g.setColor(color);  
  57.         g.fillOval(250,250,100,100);  
  58.         //第五個圓  
  59.         red=(int)(Math.random()*255);  
  60.         green=(int)(Math.random()*255);  
  61.         blue=(int)(Math.random()*255);  
  62.         color=new Color(red,green,blue);  
  63.         g.setColor(color);  
  64.         g.fillOval(275,275,50,50);  
  65.  
  66.      }         
  67.       
  68.      public static void main(String[] args)  
  69.      {  
  70.          Ex7_1 e = new Ex7_1();       
  71.      }  
  72.  
  73.  } 

#p#

播放音樂和切換圖片的小程序效果圖:

 

  1. /**  
  2.  *程序要求:編寫一個Applet的小程序,準備5幅圖片和三個音樂文件,繪制到Applet中,  
  3.  *并增加幾個按鈕,控制圖片的切換、放大、縮小和音樂文件的播放。  
  4.  *作者:wwj  
  5.  *日期:2012/4/29  
  6.  *參考:neicole  
  7.  *功能:能進行圖片和歌曲的選擇變換的applet小程序  
  8.  **/ 
  9.  
  10.  import javax.swing.*;  
  11.  import java.awt.*;  
  12.  import java.awt.event.*;  
  13.  import java.applet.Applet;  
  14.  import java.applet.AudioClip;  
  15.  
  16.    
  17.  public class Ex7_2 extends Applet implements ActionListener,ItemListener  
  18.  {  
  19.  
  20.      //創建兩個面板  
  21.      JPanel p1=new JPanel();  
  22.      JPanel p2=new JPanel();  
  23.      JPanel p3=new JPanel();  
  24.      //聲音對象  
  25.      AudioClip[] sound=new AudioClip[3];  
  26.      int playingSong=0;  
  27.      //切換圖片的按鈕  
  28.      JButton lastPic=new JButton("上一張");  
  29.      JButton setLarge=new JButton("放大");  
  30.      JButton setLittle=new JButton("縮小");  
  31.      JButton nextPic=new JButton("下一張");  
  32.      //切換歌曲的按鈕  
  33.      JButton lastSound=new JButton("上一首");  
  34.      JButton play=new JButton("播放");  
  35.      JButton loop=new JButton("連續");  
  36.      JButton stop=new JButton("停止");  
  37.      JButton nextSound=new JButton("下一首");  
  38.      //曲目下拉列表  
  39.      JComboBox xx;  
  40.      String names[]={ "曲目1.wav","曲目2.wav","曲目3.wav"};  
  41.       
  42.     //創建畫布對象  
  43.     MyCanvasl showPhotos;  
  44.  
  45.        
  46.  
  47.      public void init()  
  48.      {  
  49.          //窗口布局  
  50.          this.setLayout(new BorderLayout());  
  51.  
  52.          //為圖片控制按鈕注冊監聽器  
  53.          lastPic.addActionListener(this);  
  54.          setLarge.addActionListener(this);  
  55.          setLittle.addActionListener(this);  
  56.          nextPic.addActionListener(this);  
  57.  
  58.          //向面板p1添加組件  
  59.          p1.add(lastPic);  
  60.          p1.add(setLarge);  
  61.          p1.add(setLittle);  
  62.          p1.add(nextPic);  
  63.          p1.repaint();  
  64.       
  65.         //實例化下拉列表對象  
  66.         xx = new JComboBox(names);  
  67.         xx.addItemListener(this);  
  68.  
  69.         //為控制播放音樂按鈕注冊監聽器  
  70.         lastSound.addActionListener(this);  
  71.         play.addActionListener(this);  
  72.         loop.addActionListener(this);  
  73.         stop.addActionListener(this);  
  74.         nextSound.addActionListener(this);  
  75.  
  76.         for(int i=0;i<3;i++)  
  77.          {  
  78.             sound[i]=getAudioClip(getCodeBase(),"music/"+"曲目" 
  79.                     +Integer.toString(i+1)+".wav");  
  80.          }  
  81.           
  82.  
  83.           
  84.         //向面板p2添加組件  
  85.          p2.add(xx);  
  86.          p2.add(lastSound);  
  87.          p2.add(play);  
  88.          p2.add(loop);  
  89.          p2.add(stop);  
  90.          p2.add(nextSound);  
  91.          p2.repaint();  
  92.           
  93.         showPhotos = new MyCanvasl();  
  94.         p3.add(showPhotos);  
  95.          p3.repaint();  
  96.  
  97.         //把面板p1和p2分別布置到窗口的北部和南部   
  98.          add(p1,BorderLayout.NORTH);  
  99.          add(p2,BorderLayout.SOUTH);  
  100.          add(p3,BorderLayout.CENTER);  
  101.  
  102.          this.repaint();  
  103.  
  104.      }  
  105.  
  106.  
  107.      //按鈕的事件處理  
  108.      public void actionPerformed(ActionEvent e)  
  109.      {  
  110.  
  111.           
  112.         if(e.getSource() == lastPic){  
  113.             showPhotos.changePhotoShow('P');  
  114.         }  
  115.         else if(e.getSource() == nextPic){  
  116.             showPhotos.changePhotoShow('N');  
  117.         }  
  118.         else if(e.getSource() == setLarge){  
  119.             showPhotos.changePhotoSize('B');  
  120.         }  
  121.         else if(e.getSource() == setLittle){  
  122.             showPhotos.changePhotoSize('S');  
  123.         }  
  124.       
  125.         else if(e.getSource()==lastSound){  //上一首  
  126.             sound[playingSong].stop();  
  127.             playingSong=(playingSong-1+3)%3;  
  128.             xx.setSelectedIndex(playingSong);  
  129.             sound[playingSong].play();  
  130.  
  131.         }  
  132.         else if(e.getSource()==play){       //按下播放按鈕  
  133.             sound[playingSong].play();  
  134.         }  
  135.         else if(e.getSource()==loop){       //按下循環按鈕  
  136.             sound[playingSong].loop();  
  137.         }  
  138.         else if(e.getSource()==stop){       //按下停止按鈕  
  139.             sound[playingSong].stop();  
  140.         }  
  141.         else{                               //下一首  
  142.             sound[playingSong].stop();  
  143.             playingSong=(playingSong+1)%3;  
  144.             xx.setSelectedIndex(playingSong);  
  145.             sound[playingSong].play();  
  146.  
  147.         }     
  148.      }  
  149.  
  150.  
  151.      //下拉列表的事件處理  
  152.      public void itemStateChanged(ItemEvent e)  
  153.      {  
  154.            
  155.          sound[playingSong].stop();  
  156.          sound[playingSong]=getAudioClip(getCodeBase(),"music/"+xx.getSelectedItem());  
  157.      }  
  158.  
  159.     class MyCanvasl extends Canvas  
  160.     {  
  161.           
  162.         public Image[] img=new Image[5];  
  163.  
  164.         int MaxWidth = 600;  
  165.         int MaxHeight = 500;  
  166.         int nowImageIndex = 0;  
  167.         int coordinateX = 0;  
  168.         int coordinateY = 0;  
  169.         int currentWidth = MaxWidth;  
  170.         int currentHeight = MaxHeight;  
  171.  
  172.           
  173.         MyCanvasl(){  
  174.          setSize(MaxWidth,MaxHeight);  
  175.          //獲取當前目錄下的圖片  
  176.          for(int i=0;i<5;i++){  
  177.              img[i]=getImage(getCodeBase(),"image/"+Integer.toString(i+1)+".jpg");  
  178.          }  
  179.         }  
  180.  
  181.  
  182.         private void changePhotoIndex(int index){  
  183.             nowImageIndex = index;  
  184.             changePhotoSize('M');  
  185.         }  
  186.  
  187.  
  188.  
  189.         public void changePhotoShow(char command){  
  190.             if('P' == command){  
  191.                 changePhotoIndex((nowImageIndex + 5 - 1 ) % 5);  
  192.             }  
  193.             else if('N' == command){  
  194.                 changePhotoIndex((nowImageIndex + 1) % 5);  
  195.             }  
  196.         }  
  197.           
  198.  
  199.  
  200.          public void changePhotoSize(char command){  
  201.             if ('M' == command){  
  202.                 currentWidth = MaxWidth;  
  203.                 currentHeight = MaxHeight;  
  204.             }  
  205.             else if ('B' == command){  
  206.                 if(MaxWidth >= (currentWidth + 100) && MaxHeight >= (currentHeight + 100)){  
  207.                     currentWidth += 100;  
  208.                     currentHeight += 100;  
  209.                 }  
  210.             }  
  211.             else if('S' == command){  
  212.                 if((0 < (currentWidth - 100)) && (0 < (currentHeight - 100))){  
  213.                     currentWidth = currentWidth - 100;  
  214.                     currentHeight = currentHeight - 100;  
  215.                 }  
  216.             }  
  217.             coordinateX = (MaxWidth - currentWidth) / 2;  
  218.             coordinateY = (MaxHeight - currentHeight) / 2;  
  219.             repaint();  
  220.         }  
  221.             //paint方法用來在窗口顯示圖片  
  222.      public void paint(Graphics g){  
  223.            g.drawImage(img[nowImageIndex],coordinateX,coordinateY,currentWidth,currentHeight,this);  
  224.  
  225.      }  
  226.     }  
  227.  }  

原文鏈接:http://blog.csdn.net/wwj_748/article/details/7522672

【編輯推薦】

  1. Java集合框架總結:TreeSet類的排序問題
  2. 使用JNI進行混合編程:在C/C++中調用Java代碼
  3. Java理論與實踐: Web層的狀態復制
  4. Java代碼編寫的30條建議
  5. Java Excel API及詳細教程
責任編輯:林師授 來源: wwj_748的博客
相關推薦

2014-07-16 16:17:00

2023-08-15 13:57:08

開發者

2024-06-07 14:13:39

2010-09-17 09:08:49

Java多線程

2013-08-28 16:08:19

多媒體Windows8.1

2009-02-10 09:53:41

多線程程序設計Java

2010-09-25 13:47:14

Java跨平臺

2011-05-03 09:25:39

程序設計

2011-12-01 11:24:13

2013-12-12 16:30:20

Lua腳本語言

2010-06-30 10:38:05

2011-06-09 10:07:28

Qt phonon

2011-04-18 09:22:38

多線程

2011-07-22 13:41:57

java

2011-07-04 13:31:15

2010-01-11 10:34:22

C++程序

2009-12-04 10:53:06

VS WEB

2010-12-28 10:12:39

PHP

2010-04-08 21:14:41

多媒體視頻信息通信紅杉樹網絡

2013-12-17 13:29:04

iOS開發多媒體
點贊
收藏

51CTO技術棧公眾號

主站蜘蛛池模板: 国产精品欧美日韩 | 中文字幕在线视频观看 | 久久精品免费一区二区三 | 国产精品一区二区av | 精品99在线 | 91在线综合 | 男女羞羞视频网站 | 国产激情在线 | 国产一区二区在线看 | 综合色站导航 | 欧美一级欧美一级在线播放 | 久久精品免费 | 久久精品国产v日韩v亚洲 | 国产精品美女久久久久aⅴ国产馆 | 青青草国产在线观看 | 国产成人精品久久二区二区 | 欧美性吧 | 日本不卡一区二区 | 欧美激情国产日韩精品一区18 | 久久婷婷色 | 亚州综合在线 | 亚洲国产精品一区二区久久 | 影音先锋中文字幕在线观看 | 国产一二三区在线 | 日韩手机在线看片 | 国产乱码精品一区二区三区忘忧草 | 国产精品久久久久久238 | 日韩成人一区 | 日本五月婷婷 | 精品国产第一区二区三区 | 二区三区在线观看 | 一区二区在线免费观看 | 欧美日韩国产一区二区三区 | 欧美在线观看一区二区 | 91久久精品一区二区二区 | 毛片免费观看 | 一级电影免费看 | 狠狠色综合久久婷婷 | 天天干狠狠操 | 中文字幕久久精品 | 久久狠狠 |