黑马程序员技术交流社区

标题: 学习swing时写的画图小程序 [打印本页]

作者: David19910809    时间: 2015-6-4 22:45
标题: 学习swing时写的画图小程序
package com.first;

import javax.imageio.ImageIO;
import javax.swing.*;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.MouseEvent;
import java.awt.event.MouseListener;
import java.io.File;
import java.io.IOException;
import java.util.Random;
public class Draw {

        /**
         * @param args
         * @throws IOException
         */
        public static void main(String[] args) throws IOException {
                // TODO Auto-generated method stub
   
               
                final JFrame ss = new JFrame ();
                ss.setSize(400,300);
                ss.setVisible(true);
               
               
                final MyDraw hh = new MyDraw();
                ss.add(hh);
               
                JButton jb = new JButton();
                ss.add(jb,BorderLayout.SOUTH);
                jb.addActionListener(new ActionListener(){

                        @Override
                        public void actionPerformed(ActionEvent e) {
                                // TODO Auto-generated method stub
                                hh.repaint();
                        }
                       
                });
               
               
                       
        }
       
}
class MyDraw extends Canvas
{
        Random r = new Random();
       
        public void paint(Graphics g)
        {
               
                       
               
                g.setColor(Color.red);
        try {
                        g.drawImage( ImageIO.read(new File("$5W)3O2~`UGWD``XS~L5I(V")),0,0,null);
                } catch (IOException e) {
                        // TODO Auto-generated catch block
                        e.printStackTrace();
                }                               
        }
}
   




欢迎光临 黑马程序员技术交流社区 (http://bbs.itheima.com/) 黑马程序员IT技术论坛 X3.2