最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

Java設(shè)計(jì)圖形與多媒體處理

 更新時(shí)間:2015年09月23日 14:26:34   投稿:lijiao  
本文主要介紹了Java的圖形設(shè)計(jì)以及多媒體處理,源碼也做了詳細(xì)的注釋,對(duì)于初學(xué)者應(yīng)該不難。詳細(xì)請(qǐng)看下文

本文實(shí)現(xiàn)了兩個(gè)效果:

第一種,同心圓效果圖:

/** 
 *程序要求:新建一個(gè)600*600像素的應(yīng)用程序窗口,并在窗口中繪制5個(gè)不同顏色的同心圓, 
 *所有圓心都是屏幕的中心點(diǎn),相鄰兩個(gè)圓直接的半徑相差50像素 
 *效果圖如下圖所示(顏色隨機(jī)設(shè)置),源程序保存為Ex7_1.java。 
 *作者:wwj 
 *日期:2012/4/25 
 *功能:顯示一個(gè)有5個(gè)不同顏色的同心圓 
 **/ 
 
 import javax.swing.*; 
 import java.awt.*; 
 import java.awt.Color; 
 public class Ex7_1 extends JFrame 
 { 
   int red,green,blue; 
   Color color; 
 
   public Ex7_1() 
   { 
     super("一個(gè)有5個(gè)不同顏色的同心圓");  //顯示窗口名稱 
     setSize(600,600);           //設(shè)置窗口大小 
     setVisible(true);           //設(shè)置為可見 
     setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);//設(shè)置窗口關(guān)閉動(dòng)作 
   
   } 
 
   
   public void paint(Graphics g) 
   { 
     //第一個(gè)圓 
    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); 
    //第二個(gè)圓 
    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); 
    //第三個(gè)圓 
    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); 
    //第四個(gè)圓 
    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); 
    //第五個(gè)圓 
    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();    
   } 
 
 } 

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

/** 
 *程序要求:編寫一個(gè)Applet的小程序,準(zhǔn)備5幅圖片和三個(gè)音樂文件,繪制到Applet中, 
 *并增加幾個(gè)按鈕,控制圖片的切換、放大、縮小和音樂文件的播放。 
 *作者:wwj 
 *日期:2012/4/29 
 *參考:neicole 
 *功能:能進(jìn)行圖片和歌曲的選擇變換的applet小程序 
 **/ 
 
 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 
 { 
 
   //創(chuàng)建兩個(gè)面板 
   JPanel p1=new JPanel(); 
   JPanel p2=new JPanel(); 
   JPanel p3=new JPanel(); 
   //聲音對(duì)象 
   AudioClip[] sound=new AudioClip[3]; 
   int playingSong=0; 
   //切換圖片的按鈕 
   JButton lastPic=new JButton("上一張"); 
   JButton setLarge=new JButton("放大"); 
   JButton setLittle=new JButton("縮小"); 
   JButton nextPic=new JButton("下一張"); 
   //切換歌曲的按鈕 
   JButton lastSound=new JButton("上一首"); 
   JButton play=new JButton("播放"); 
   JButton loop=new JButton("連續(xù)"); 
   JButton stop=new JButton("停止"); 
   JButton nextSound=new JButton("下一首"); 
   //曲目下拉列表 
   JComboBox xx; 
   String names[]={ "曲目1.wav","曲目2.wav","曲目3.wav"}; 
   
  //創(chuàng)建畫布對(duì)象 
  MyCanvasl showPhotos; 
 
    
 
   public void init() 
   { 
     //窗口布局 
     this.setLayout(new BorderLayout()); 
 
     //為圖片控制按鈕注冊(cè)監(jiān)聽器 
     lastPic.addActionListener(this); 
     setLarge.addActionListener(this); 
     setLittle.addActionListener(this); 
     nextPic.addActionListener(this); 
 
     //向面板p1添加組件 
     p1.add(lastPic); 
     p1.add(setLarge); 
     p1.add(setLittle); 
     p1.add(nextPic); 
     p1.repaint(); 
   
    //實(shí)例化下拉列表對(duì)象 
    xx = new JComboBox(names); 
    xx.addItemListener(this); 
 
    //為控制播放音樂按鈕注冊(cè)監(jiān)聽器 
    lastSound.addActionListener(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/"+"曲目" 
          +Integer.toString(i+1)+".wav"); 
     } 
     
 
     
    //向面板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(); 
 
    //把面板p1和p2分別布置到窗口的北部和南部  
     add(p1,BorderLayout.NORTH); 
     add(p2,BorderLayout.SOUTH); 
     add(p3,BorderLayout.CENTER); 
 
     this.repaint(); 
 
   } 
 
 
   //按鈕的事件處理 
   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){ //上一首 
      sound[playingSong].stop(); 
      playingSong=(playingSong-1+3)%3; 
      xx.setSelectedIndex(playingSong); 
      sound[playingSong].play(); 
 
    } 
    else if(e.getSource()==play){    //按下播放按鈕 
      sound[playingSong].play(); 
    } 
    else if(e.getSource()==loop){    //按下循環(huán)按鈕 
      sound[playingSong].loop(); 
    } 
    else if(e.getSource()==stop){    //按下停止按鈕 
      sound[playingSong].stop(); 
    } 
    else{                //下一首 
      sound[playingSong].stop(); 
      playingSong=(playingSong+1)%3; 
      xx.setSelectedIndex(playingSong); 
      sound[playingSong].play(); 
 
    }   
   } 
 
 
   //下拉列表的事件處理 
   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); 
     //獲取當(dāng)前目錄下的圖片 
     for(int i=0;i<5;i++){ 
       img[i]=getImage(getCodeBase(),"image/"+Integer.toString(i+1)+".jpg"); 
     } 
    } 
 
 
    private void changePhotoIndex(int index){ 
      nowImageIndex = index; 
      changePhotoSize('M'); 
    } 
 
 
 
    public void changePhotoShow(char command){ 
      if('P' == command){ 
        changePhotoIndex((nowImageIndex + 5 - 1 ) % 5); 
      } 
      else if('N' == command){ 
        changePhotoIndex((nowImageIndex + 1) % 5); 
      } 
    } 
     
 
 
     public void changePhotoSize(char command){ 
      if ('M' == command){ 
        currentWidth = MaxWidth; 
        currentHeight = MaxHeight; 
      } 
      else if ('B' == command){ 
        if(MaxWidth >= (currentWidth + 100) && MaxHeight >= (currentHeight + 100)){ 
          currentWidth += 100; 
          currentHeight += 100; 
        } 
      } 
      else if('S' == command){ 
        if((0 < (currentWidth - 100)) && (0 < (currentHeight - 100))){ 
          currentWidth = currentWidth - 100; 
          currentHeight = currentHeight - 100; 
        } 
      } 
      coordinateX = (MaxWidth - currentWidth) / 2; 
      coordinateY = (MaxHeight - currentHeight) / 2; 
      repaint(); 
    } 
      //paint方法用來在窗口顯示圖片 
   public void paint(Graphics g){ 
      g.drawImage(img[nowImageIndex],coordinateX,coordinateY,currentWidth,currentHeight,this); 
 
   } 
  } 
 } 

 以上就是關(guān)于Java的圖形設(shè)計(jì)以及多媒體處理的全部?jī)?nèi)容,希望對(duì)大家的學(xué)習(xí)有所幫助。

相關(guān)文章

  • 詳解java中通過post方式訪問后臺(tái)服務(wù)器

    詳解java中通過post方式訪問后臺(tái)服務(wù)器

    本篇文章主要介紹了詳解java中通過post方式訪問后臺(tái)服務(wù)器,具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下。
    2017-03-03
  • tk.Mybatis 插入數(shù)據(jù)獲取Id問題

    tk.Mybatis 插入數(shù)據(jù)獲取Id問題

    本文主要介紹了tk.Mybatis 插入數(shù)據(jù)獲取Id問題,文中通過示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下
    2021-12-12
  • idea創(chuàng)建包含多個(gè)springboot module的maven project的方法

    idea創(chuàng)建包含多個(gè)springboot module的maven project的方法

    這篇文章主要介紹了idea創(chuàng)建包含多個(gè)springboot module的maven project的方法,本文給大家介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或工作具有一定的參考借鑒價(jià)值,需要的朋友可以參考下
    2020-09-09
  • SpringBoot中優(yōu)化Undertow性能的方法總結(jié)

    SpringBoot中優(yōu)化Undertow性能的方法總結(jié)

    Undertow是一個(gè)采用 Java 開發(fā)的靈活的高性能Web服務(wù)器,提供包括阻塞和基于NIO的非堵塞機(jī)制,本文將給大家介紹SpringBoot中優(yōu)化Undertow性能的方法,文中有相關(guān)的代碼示例供大家參考,需要的朋友可以參考下
    2024-08-08
  • 詳解Java8中接口的默認(rèn)方法和靜態(tài)方法

    詳解Java8中接口的默認(rèn)方法和靜態(tài)方法

    Java 8是Java語(yǔ)言的一個(gè)重要版本,其中引入了許多新特性和改進(jìn),其中一個(gè)值得關(guān)注的特性是接口的默認(rèn)方法和靜態(tài)方法,本文就來和大家簡(jiǎn)單講講吧
    2023-05-05
  • 死磕 java同步系列之synchronized解析

    死磕 java同步系列之synchronized解析

    這篇文章主要介紹了Java中syncronized正確使用方法解析,文中通過示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友可以參考下
    2021-06-06
  • 最新評(píng)論

    彭泽县| 肇源县| 南部县| 鹤庆县| 广东省| 天台县| 喀什市| 肃宁县| 图片| 应城市| 罗山县| 正镶白旗| 乌恰县| 永定县| 安阳市| 四平市| 甘南县| 色达县| 哈密市| 阜南县| 东方市| 青铜峡市| 海盐县| 连城县| 林州市| 南丰县| 凤台县| 棋牌| 眉山市| 三门峡市| 景德镇市| 双峰县| 和林格尔县| 措勤县| 贵南县| 榆林市| 黄龙县| 三穗县| 平度市| 延川县| 哈尔滨市|