日韩无码专区无码一级三级片|91人人爱网站中日韩无码电影|厨房大战丰满熟妇|AV高清无码在线免费观看|另类AV日韩少妇熟女|中文日本大黄一级黄色片|色情在线视频免费|亚洲成人特黄a片|黄片wwwav色图欧美|欧亚乱色一区二区三区

RELATEED CONSULTING
相關(guān)咨詢
選擇下列產(chǎn)品馬上在線溝通
服務(wù)時間:8:30-17:00
你可能遇到了下面的問題
關(guān)閉右側(cè)工具欄

新聞中心

這里有您想知道的互聯(lián)網(wǎng)營銷解決方案
Java程序設(shè)計(jì):圖形與多媒體處理

同心圓效果圖:

創(chuàng)新互聯(lián)專業(yè)為企業(yè)提供佛山網(wǎng)站建設(shè)、佛山做網(wǎng)站、佛山網(wǎng)站設(shè)計(jì)、佛山網(wǎng)站制作等企業(yè)網(wǎng)站建設(shè)、網(wǎng)頁設(shè)計(jì)與制作、佛山企業(yè)網(wǎng)站模板建站服務(wù),十載佛山做網(wǎng)站經(jīng)驗(yàn),不只是建網(wǎng)站,更提供有價值的思路和整體網(wǎng)絡(luò)服務(wù)。

 
 
 
 
  1. /**  
  2.  *程序要求:新建一個600*600像素的應(yīng)用程序窗口,并在窗口中繪制5個不同顏色的同心圓,  
  3.  *所有圓心都是屏幕的中心點(diǎn),相鄰兩個圓直接的半徑相差50像素  
  4.  *效果圖如下圖所示(顏色隨機(jī)設(shè)置),源程序保存為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);                      //設(shè)置窗口大小  
  22.          setVisible(true);                      //設(shè)置為可見  
  23.          setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);//設(shè)置窗口關(guān)閉動作  
  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的小程序,準(zhǔn)備5幅圖片和三個音樂文件,繪制到Applet中,  
  3.  *并增加幾個按鈕,控制圖片的切換、放大、縮小和音樂文件的播放。  
  4.  *作者:wwj  
  5.  *日期:2012/4/29  
  6.  *參考:neicole  
  7.  *功能:能進(jìn)行圖片和歌曲的選擇變換的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.      //創(chuàng)建兩個面板  
  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("連續(xù)");  
  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.     //創(chuàng)建畫布對象  
  43.     MyCanvasl showPhotos;  
  44.  
  45.        
  46.  
  47.      public void init()  
  48.      {  
  49.          //窗口布局  
  50.          this.setLayout(new BorderLayout());  
  51.  
  52.          //為圖片控制按鈕注冊監(jiān)聽器  
  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.         //實(shí)例化下拉列表對象  
  66.         xx = new JComboBox(names);  
  67.         xx.addItemListener(this);  
  68.  
  69.         //為控制播放音樂按鈕注冊監(jiān)聽器  
  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){       //按下循環(huán)按鈕  
  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.          //獲取當(dāng)前目錄下的圖片  
  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.  }  

分享文章:Java程序設(shè)計(jì):圖形與多媒體處理
瀏覽地址:http://m.5511xx.com/article/codhghe.html