資源簡介
使用J2SE 對jpeg格式的圖片進行操控,并實現(xiàn)一定的繪圖功能

代碼片段和文件信息
import?java.awt.*;
import?java.util.*;
import?java.awt.geom.*;
import?java.awt.image.*;
import?java.awt.event.*;
import?java.io.*;
import?javax.swing.*;
import?com.sun.image.codec.jpeg.*;
class?Point
{int?xy;
?Point(int?xint?y)
?{this.x=x;this.y=y;
?}
}
public?class?MakeJPEG?extends?Canvas?implements?MouseMotionListenerMouseListenerActionListener
{??
???int?x=-1y=-1橡皮擦通知=0清除通知=0;
???Vector?v=null;int?n=1;
???Graphics2D??ggg?;?????????????????????????????????????????????
???BufferedImage?image;??????????????????????????????????????????
???frame?window;
???Button?保存調色板橡皮清除畫筆獲取屏幕繪制圖形;
???Color?畫筆顏色;
???Panel?pCenterpSouthpNorth;
??
?public?MakeJPEG()
?{?
????保存=new?Button(“將繪制的圖形或屏幕保存為JPG文件“);
????獲取屏幕=new?Button(“獲取屏幕“);
????繪制圖形=new?Button(“繪制圖形“);
????調色板=new?Button(“打開調色板“);
????畫筆=new?Button(“畫筆“);
????橡皮=new?Button(“橡皮“);
????清除=new?Button(“清除“);
????調色板.addActionListener(this);
????繪制圖形.addActionListener(this);
????保存.addActionListener(this);
????畫筆.addActionListener(this);
????橡皮.addActionListener(this);
????清除.addActionListener(this);
????獲取屏幕.addActionListener(this);
????畫筆顏色=new?Color(000);
????addMouseMotionListener(this);?
????addMouseListener(this);
????v=new?Vector();?
????setBackground(Color.white);?????????????????????????????????
????image=new?BufferedImage(200200BufferedImage.TYPE_INT_RGB);
????ggg=image.createGraphics();?????????????????????????????????
????Rectangle2D?rect=new?Rectangle2D.Double(00200200);??????
????ggg.setColor(getBackground());
????ggg.fill(rect);?????????????????????????????????????????????
????window=new?frame(“JPEG圖像生成器“);
????pCenter=new?Panel();
????pCenter.setLayout(null);
????pCenter.add(this);
????pCenter.setBackground(Color.gray);
????this.setBounds(8030210210);??????????????????????????????
????window.add(pCenterBorderLayout.CENTER);
????pNorth=new?Panel();
????pNorth.add(保存);
????pNorth.add(繪制圖形);
????pNorth.add(獲取屏幕);
????window.add(pNorthBorderLayout.NORTH);
????pSouth=new?Panel();
????pSouth.add(調色板);
????pSouth.add(橡皮);
????pSouth.add(清除);
????pSouth.add(畫筆);
????window.add(pSouthBorderLayout.SOUTH);
????window.setVisible(true);
????window.addWindowListener(new?WindowAdapter()
???????????????????{?
?????????????????????public?void?windowClosing(WindowEvent?e)
?????????????????????{?
????????????????????????System.exit(0);
?????? ?????????????}
?????? ???????????});
????window.setBounds(10080390380);
????window.validate();?????????????????????????????????????????
?}
?public?void?paint(Graphics?g)?????????????????????????????????
?{
????if(x!=-1&&y!=-1&&橡皮擦通知==0&&清除通知==0)
?????{??
????????g.setColor(畫筆顏色);
????????n=v.size();
????????for(int?i=0;i ?????????{
???????????Point?p1=(Point)v.elementAt(i);?
???????????Point?p2=(Point)v.elementAt(i+1);?
???????????g.drawLine(p1.xp1.yp2.xp2.y);?????????????????????
???????????ggg.setColor(g.getColor());
???????????ggg.draw
?屬性????????????大小?????日期????時間???名稱
-----------?---------??----------?-----??----
?????文件???????6992??2003-12-09?08:54??MakeJPEG.java
-----------?---------??----------?-----??----
?????????????????6992????????????????????1
- 上一篇:java ba
se64的jar包 - 下一篇:android應用注冊界面
評論
共有 條評論