<rt id="bn8ez"></rt>
<label id="bn8ez"></label>

  • <span id="bn8ez"></span>

    <label id="bn8ez"><meter id="bn8ez"></meter></label>

    posts - 1,comments - 1,trackbacks - 0

    import java.awt.*;
    import java.awt.event.*;
    import javax.swing.*;

    import java.awt.image.*;
    import com.sun.image.codec.jpeg.*;
    import java.io.*;
    public class mouse implements ActionListener, WindowListener, MouseMotionListener, MouseListener
    {
     Frame f;

     

     TextField t=new TextField();
     int j;
     int x,y;
     Graphics g,g_in;
     int x1,y1;
     BufferedImage i;

     Panel p1=new Panel(new GridLayout(2,3));

     Button b1=new Button("紅色");
     Button b2=new Button("黃色");
     Button b3=new Button("藍(lán)色");
     Button b4=new Button("綠色");
     Button b5=new Button("矩形");
     Button b6=new Button("圓形");
     
      
     mouse()
     {
      
      
      
     
      t.setEnabled(false);
      
      f=new Frame("畫(huà)圖!");
      
      p1.add(b1);
      p1.add(b2);
      p1.add(b3);
      p1.add(b4);
      p1.add(b5);
      p1.add(b6);
      
      b1.addActionListener(this);
      b2.addActionListener(this);
      b3.addActionListener(this);
      b4.addActionListener(this);
      b5.addActionListener(this);
      b6.addActionListener(this);
      
      f.add(t,BorderLayout.NORTH);
      f.add(p1,BorderLayout.EAST);
      
      
      f.setSize(400,400);
      int w=(int)Toolkit.getDefaultToolkit().getScreenSize().getWidth();
      int h=(int)Toolkit.getDefaultToolkit().getScreenSize().getHeight();
      
      f.setLocation((w-400)/2,(h-400)/2);
      f.setBackground(Color.ORANGE);
        
      f.setResizable(false); 
      f.setVisible(true);
      f.addWindowListener(this);
      f.addMouseListener(this);
      f.addMouseMotionListener(this);
      this.getG();
      
     }
     public void getG()
     {
      f.addMouseListener(this); 
      this.g=f.getGraphics();
      i=new BufferedImage(f.getWidth(),f.getHeight(),BufferedImage.TYPE_INT_RGB);
      g_in=i.getGraphics();
      
      
      g_in.setColor(Color.white);
      g_in.fill3DRect(0,0,i.getWidth(),i.getHeight(),true);
     
     }
     
     public void actionPerformed(ActionEvent e)
     {
      if(e.getSource()==b1)
      {
       g.setColor(Color.red);
       g_in.setColor(Color.red);
      }
      else if(e.getSource()==b2)
      {
       g.setColor(Color.yellow);
       g_in.setColor(Color.yellow);
      }
      else if(e.getSource()==b3)
      {
       g.setColor(Color.blue);
       g_in.setColor(Color.blue);
      }
      else if(e.getSource()==b4)

      {
       g.setColor(Color.green);
       g_in.setColor(Color.green);
      }
      else if(e.getSource()==b5)
      {
       j=0;
      }
      else if(e.getSource()==b6)
      {
       j=1;
      }
     
      
      
        
     }
     
     public static void main(String args[])
     {
      mouse my=new mouse();
     }

     public void windowOpened(WindowEvent e) {
     
     }

     public void windowClosing(WindowEvent e) {
     try
      {
       ByteArrayOutputStream is=new ByteArrayOutputStream();//創(chuàng)建一個(gè)字節(jié)類型數(shù)據(jù)的數(shù)據(jù)區(qū)
       
       JPEGImageEncoder coder=JPEGCodec.createJPEGEncoder(is);
       //聲明此數(shù)據(jù)區(qū)只能保存JPG格式的數(shù)據(jù)
       
       coder.encode(i);
       //從內(nèi)存i圖片中提取JPG格式數(shù)據(jù),保存到數(shù)據(jù)區(qū)
       
       FileOutputStream fo=new FileOutputStream("a.jpg");
       
       byte[] b=is.toByteArray();//將數(shù)據(jù)提取成字節(jié)數(shù)組
       
       fo.write(b);//將數(shù)據(jù)寫(xiě)入a.jpg文件中
       fo.close();//關(guān)閉文件的寫(xiě)入
       
       f.dispose();
       
       JOptionPane.showMessageDialog(null,"圖片已保存為a.jpg,請(qǐng)察看!"); 
        
      }catch(Exception el){}
     }

     public void windowClosed(WindowEvent e) {
     
     }

     public void windowIconified(WindowEvent e) {
     
     }

     public void windowDeiconified(WindowEvent e) {
     
     }

     public void windowActivated(WindowEvent e) {
      
     }

     public void windowDeactivated(WindowEvent e) {
      
     }

     public void mouseDragged(MouseEvent e) {
      // TODO: Add your code here
     }

     

     public void mouseMoved(MouseEvent e) {
     t.setText("X:"+e.getX()+"Y:"+e.getY()); 
      
     }

     public void mouseClicked(MouseEvent e) {
      // TODO: Add your code here
     }

     public void mousePressed(MouseEvent e) {
      x=e.getX();y=e.getY();
     
     }

     public void mouseReleased(MouseEvent e) {
      
      x1=e.getX();y1=e.getY();
       if (j==1)
       {
        if(x1>=x)
        {
       if(y1>=y)
       {
       g.fillOval(x,y,x1-x,y1-y);
       g_in.fillOval(x,y,x1-x,y1-y);
       }
       else if(y1<y)
       {
       g.fillOval(x,y1,x1-x,y-y1);
       g_in.fillOval(x,y1,x1-x,y-y1);
       }
      }
      
      else if(x1<x)
      {
       if(y1<y)
       {
       g_in.fillOval(x1,y1,x-x1,y-y1);
       g.fillOval(x1,y1,x-x1,y-y1);
       }
       else if(y1>=y)
       {
        g.fillOval(x1,y,x-x1,y1-y);
        g_in.fillOval(x1,y,x-x1,y1-y);
       }
      }}
      else if(j==0)
      {
       if(x1>=x)
        {
       if(y1>=y)
       {
      g.fillRect(x,y,x1-x,y1-y);
      g_in.fillRect(x,y,x1-x,y1-y);
       }
       else if(y1<y)
       {
      g.fillRect(x,y1,x1-x,y-y1);
      g_in.fillRect(x,y1,x1-x,y-y1);
       }
      }
      
      else if(x1<x)
      {
       if(y1<y)
       {
       g.fillRect(x1,y1,x-x1,y-y1);
       g_in.fillRect(x1,y1,x-x1,y-y1);
       }
       else if(y1>=y)
       {
        g.fillRect(x1,y,x-x1,y1-y);
        g_in.fillRect(x1,y,x-x1,y1-y);
       }
      }
      }
      
      
     
     }

     public void mouseEntered(MouseEvent e) {
      
     }

     public void mouseExited(MouseEvent e) {
      // TODO: Add your code here
     }
     
     
      
     
     }

    posted on 2006-02-28 19:02 飄忽著的 閱讀(320) 評(píng)論(1)  編輯  收藏

    FeedBack:
    # re: 昨天的作業(yè)(畫(huà)板)
    2006-02-28 19:53 | dudu
    這樣的文章不要發(fā)表到首頁(yè)。  回復(fù)  更多評(píng)論
      

    只有注冊(cè)用戶登錄后才能發(fā)表評(píng)論。


    網(wǎng)站導(dǎo)航:
     
    主站蜘蛛池模板: 亚洲成综合人影院在院播放| 亚洲精品无码av人在线观看 | 成人a视频片在线观看免费| 一级毛片正片免费视频手机看| 最近的免费中文字幕视频| 亚洲一区二区三区免费观看| 亚洲成在人线aⅴ免费毛片| 亚洲人成777在线播放| 最近中文字幕免费mv视频8| 亚洲精品乱码久久久久久V| 暖暖免费高清日本中文| 青草青草视频2免费观看| 亚洲国产小视频精品久久久三级| 一级特黄特色的免费大片视频| 亚洲中文字幕视频国产| 美女被cao网站免费看在线看| 亚洲AV人人澡人人爽人人夜夜| 67pao强力打造国产免费| 亚洲三级中文字幕| 国产资源免费观看| 国产精品1024在线永久免费 | 免费一区二区无码东京热| 亚洲av无码不卡| 久久受www免费人成_看片中文| 亚洲日韩精品无码专区加勒比| 国产无遮挡裸体免费视频| aa级毛片毛片免费观看久| 久久久久亚洲AV无码专区首JN| 在人线av无码免费高潮喷水| 国产成人精品亚洲| 亚洲AV成人一区二区三区AV| 国产精品69白浆在线观看免费| 羞羞视频在线免费观看| 亚洲国产天堂久久综合网站| 好吊妞998视频免费观看在线| av片在线观看永久免费| 亚洲日产2021三区在线| 亚洲AV无码成人精品区大在线 | 猫咪免费人成网站在线观看入口| 亚洲日韩小电影在线观看| 一个人看的免费高清视频日本 |