- 浏览: 476256 次
- 性别:
- 来自: 北京
文章分类
最新评论
-
谢谢你的祝福:
特地登陆上来感谢一下楼主,解决问题。
ORA-04098: 触发器无效且未通过重新验证问题 -
fuqiangjava:
写的不错 解决了自己的一个问题 谢谢了
ORA-00001:unique constraint (oracle 10g) -
hujinhuhujinhu:
make ...我有1.6.23
MyEclipse6.5安装自动提示功能的jQuery插件步骤 -
fool2011:
学习下,博主
JFreeChart类生成折线图的Java源代码 -
814687491:
你不是说的JQUERY吗?
MyEclipse6.5安装自动提示功能的jQuery插件步骤
效果如下图:
import java.applet.Applet; import java.awt.BasicStroke; import java.awt.Button; import java.awt.Canvas; import java.awt.Choice; import java.awt.Color; import java.awt.Cursor; import java.awt.FlowLayout;import java.awt.Graphics; import java.awt.Graphics2D; import java.awt.Image; import java.awt.Label; import java.awt.MediaTracker; import java.awt.MenuItem; import java.awt.Panel; import java.awt.PopupMenu; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; import java.awt.event.ItemEvent; import java.awt.event.ItemListener; import java.awt.event.KeyAdapter; import java.awt.event.KeyEvent; import java.awt.event.MouseAdapter; import java.awt.event.MouseEvent; import java.awt.event.MouseListener; import java.awt.event.MouseMotionAdapter; import java.awt.event.MouseMotionListener; import java.awt.geom.Ellipse2D; import java.awt.geom.Line2D; import java.awt.geom.Rectangle2D; import java.awt.image.BufferedImage; import java.io.File; import java.io.FileInputStream; import java.io.FileOutputStream; import java.io.IOException; import java.io.ObjectInputStream; import java.io.ObjectOutputStream; import java.io.Serializable; import java.util.Vector; import javax.imageio.ImageIO; import javax.swing.JColorChooser; import javax.swing.JFileChooser; import javax.swing.JPanel; import javax.swing.filechooser.FileFilter; public class DrawImage extends Applet implements ItemListener , MouseListener , MouseMotionListener , ActionListener { private static final long serialVersionUID = 1L; int count = 8; //装载图片的数量 Vector<Vector<Object>> v = new Vector<Vector<Object>>(); //存储绘图信息 Image[] img = new Image[count]; int myWidth = 0; //箭头起点坐标 int myHeight = 0; //箭头起点坐标 int widthcount = 0; //工具栏上图标之间隔 //boolean[] b = new boolean[count]; int[] width = new int[count]; int[] height = new int[count]; int[] w = new int[count]; int[] h = new int[count]; int[] wid = new int[count]; int[] hei = new int[count]; int[] ww = new int[count]; int[] hh = new int[count]; int startX = 0; int startY = 0; int endX = 0; int endY = 0; int clickX = 0; //点击动态图标时的X坐标 int clickY = 0; //点击动态图标时的Y坐标 int moveX = 0; //拖动动态图标时的X坐标 int moveY = 0; //拖动动态图标时的Y坐标 canvas[] can = null; //动态图标数组 myCanvas[] mycan = new myCanvas[count]; //动态图标数组 Canvas curcan = null; //当前获得焦点的图标 Canvas curdelcan = null; //需要删除的当前图标 Image curimg = null; //当前焦点图标的图象 JPanel jp = new JPanel(null); //图像工具条面板 MediaTracker mt = new MediaTracker(this); //媒体对象,用于装载图象到内存 PopupMenu popMenu2 = new PopupMenu(); //右键菜单 MenuItem menuItem1 = null; MenuItem menuItem2 = null; // MenuItem menuItem3 = null; MenuItem menuItem4 = null; MenuItem menuItem5 = null; int x = -1; int y = -1; int con = 1; // 画笔大小 int Econ = 5; // 橡皮大小 int toolFlag = 0; //工具标记 // toolFlag工具对应表: // (0--画笔);(1--橡皮);(2--清除); // (3--直线);(4--圆);(5--矩形); Color c = new Color(0, 0, 0); // 画笔颜色 BasicStroke size = new BasicStroke(this.con, 0, 2); // 画笔粗细 Point cutflag = new Point(-1, -1, this.c, 6, this.con); // 截断标志 Vector<Point> paintInfo = null; // 点信息向量组 int n = 1; FileInputStream picIn = null; FileOutputStream picOut = null; ObjectInputStream VIn = null; ObjectOutputStream VOut = null; Panel toolPanel; Button eraser; Button drLine; Button drCircle; Button drRect; Button clear; Button pen; Choice ColChoice; Choice SizeChoice; Choice EraserChoice; Button colchooser; Label 颜色; Label 大小B; Label 大小E; Button openPic; Button savePic; // FileDialog openPicture; BufferedImage bi = null; Graphics2D g2d = null; public void init() { // int width2 = Toolkit.getDefaultToolkit().getScreenSize().width; // 屏幕的宽 // int height2 = Toolkit.getDefaultToolkit().getScreenSize().height; // 屏蔽的高 // // this.bi = new BufferedImage(width2, height2, 1); this.bi = new BufferedImage(1280, 800, 1); //内存中创建指定大小的绘图区域 this.img[0] = getImage(getCodeBase(), "1.png"); this.img[1] = getImage(getCodeBase(), "2.png"); this.img[2] = getImage(getCodeBase(), "3.png"); this.img[3] = getImage(getCodeBase(), "4.png"); this.img[4] = getImage(getCodeBase(), "5.png"); this.img[5] = getImage(getCodeBase(), "6.png"); this.img[6] = getImage(getCodeBase(), "7.png"); this.img[7] = getImage(getCodeBase(), "8.png"); resize(800, 600); //设置applet的尺寸,在浏览器里浏览根据html代码来设置 setLayout(null); //设置布局管理器,因为要移动图标的位置,因此设置为null for (int i = 0; i < this.img.length; ++i) { this.mt.addImage(this.img[i], 0); } try { this.mt.waitForAll(); } catch (Exception ex) { System.err.println(ex.toString()); } add(this.jp); this.jp.setBounds(0, 0, 800, 80); //---------------绘制图像工具条------------------------------------------ for (int i = 0; i < this.img.length; ++i) { this.mycan[i] = new myCanvas(this.img[i]); this.width[i] = this.img[i].getWidth(this); this.height[i] = this.img[i].getHeight(this); this.jp.add(this.mycan[i]); this.mycan[i].setBounds(100 + 5 * (i + 1) + this.widthcount, 5, this.img[i].getWidth(this), this.img[i].getHeight(this)); this.widthcount += this.img[i].getWidth(this); } //---------------绘制图像工具条--------结束-------------------------------- // ---------------加载右键菜单----------------------------- this.menuItem1 = new MenuItem("隐藏图像工具栏"); this.menuItem2 = new MenuItem("显示图像工具栏"); // this.menuItem3 = new MenuItem("清空画面"); this.menuItem4 = new MenuItem("显示绘图工具栏"); this.menuItem5 = new MenuItem("隐藏绘图工具栏"); this.popMenu2.add(this.menuItem1); this.popMenu2.add(this.menuItem2); // this.popMenu2.add(this.menuItem3); this.popMenu2.addSeparator(); this.popMenu2.add(this.menuItem4); this.popMenu2.add(this.menuItem5); add(this.popMenu2); this.menuItem1.addActionListener(this); this.menuItem2.addActionListener(this); // this.menuItem3.addActionListener(this); this.menuItem4.addActionListener(this); this.menuItem5.addActionListener(this); // ---------------加载右键菜单------结束--------------------- // -----------------菜单条-------------------------------------- this.toolPanel = new Panel(null); //菜单条面板 this.toolPanel.setLayout(new FlowLayout()); this.paintInfo = new Vector<Point>(); this.ColChoice = new Choice(); // 画笔颜色选择下拉列表框 this.ColChoice.add("黑色"); this.ColChoice.add("红色"); this.ColChoice.add("蓝色"); this.ColChoice.add("绿色"); this.ColChoice.addItemListener(this); // 画笔大小选择 this.SizeChoice = new Choice(); //画笔大小下拉列表框 this.SizeChoice.add("1"); this.SizeChoice.add("3"); this.SizeChoice.add("5"); this.SizeChoice.add("7"); this.SizeChoice.add("9"); this.SizeChoice.addItemListener(this); // 橡皮大小下拉列表框 this.EraserChoice = new Choice(); this.EraserChoice.add("5"); this.EraserChoice.add("9"); this.EraserChoice.add("13"); this.EraserChoice.add("17"); this.EraserChoice.addItemListener(this); this.clear = new Button("清除"); this.eraser = new Button("橡皮擦"); this.pen = new Button("画笔"); this.drLine = new Button("画直线"); this.drCircle = new Button("画圆形"); this.drRect = new Button("画矩形"); this.openPic = new Button("导入图片"); this.savePic = new Button("保存图片"); this.colchooser = new Button("显示调色板"); // 各组件事件监听 this.clear.addActionListener(this); this.eraser.addActionListener(this); this.pen.addActionListener(this); this.drLine.addActionListener(this); this.drCircle.addActionListener(this); this.drRect.addActionListener(this); this.openPic.addActionListener(this); this.savePic.addActionListener(this); this.colchooser.addActionListener(this); this.颜色 = new Label("画笔颜色", 1); this.大小B = new Label("画笔大小", 1); this.大小E = new Label("橡皮大小", 1); this.toolPanel.add(this.openPic); this.toolPanel.add(this.savePic); this.toolPanel.add(this.pen); this.toolPanel.add(this.drLine); this.toolPanel.add(this.drCircle); this.toolPanel.add(this.drRect); this.toolPanel.add(this.颜色); this.toolPanel.add(this.ColChoice); this.toolPanel.add(this.大小B); this.toolPanel.add(this.SizeChoice); this.toolPanel.add(this.colchooser); this.toolPanel.add(this.eraser); this.toolPanel.add(this.大小E); this.toolPanel.add(this.EraserChoice); this.toolPanel.add(this.clear); add(this.toolPanel); this.toolPanel.setBounds(0, 0, 900, 40); this.toolPanel.setBackground(Color.black); this.toolPanel.setVisible(false); // ---------------------菜单条----加载结束----------------------------------------- addMouseListener(this); addMouseMotionListener(this); } /** * 功能:设置画笔颜色 */ public void itemStateChanged(ItemEvent e) { //画笔颜色设置 if (e.getSource() == this.ColChoice) { String name = this.ColChoice.getSelectedItem(); if (name == "黑色") { this.c = new Color(0, 0, 0); } else if (name == "红色") { this.c = new Color(255, 0, 0); } else if (name == "绿色") { this.c = new Color(0, 255, 0); } else { if (name != "蓝色") return; this.c = new Color(0, 0, 255); } } //画笔大小设置 else if (e.getSource() == this.SizeChoice) { String selected = this.SizeChoice.getSelectedItem(); if (selected == "1") { this.con = 1; } else if (selected == "3") { this.con = 3; } else if (selected == "5") { this.con = 5; } else if (selected == "7") { this.con = 7; } else if (selected == "9") { this.con = 9; } this.size = new BasicStroke(this.con, 0, 2); //设置画笔大小 } else { //设置橡皮擦大小 if (e.getSource() != this.EraserChoice) return; String Esize = this.EraserChoice.getSelectedItem(); if (Esize == "5") { this.Econ = 5 * 2; } else if (Esize == "9") { this.Econ = 9 * 2; } else if (Esize == "13") { this.Econ = 13 * 2; } else { if (Esize != "17") return; this.Econ = 17 * 3; } } } public void actionPerformed(ActionEvent e) { // ----------------设置右键菜单的显示与隐藏功能----------------------------- if (e.getSource() == this.menuItem1) { this.jp.setVisible(false); this.toolPanel.setVisible(true); repaint(); } else if (e.getSource() == this.menuItem2) { this.jp.setVisible(true); this.toolPanel.setVisible(false); repaint(); } // else if (e.getSource() == this.menuItem3) // { // //this.paintInfo.removeAllElements(); // //repaint(); // } else if (e.getSource() == this.menuItem4) { this.toolPanel.setVisible(true); repaint(); } else if (e.getSource() == this.menuItem5) { this.toolPanel.setVisible(false); repaint(); } // ----------------设置右键菜单的显示与隐藏功能--------结束--------------------- if (e.getSource() == this.pen) // 画笔 { this.toolFlag = 0; } if (e.getSource() == this.eraser) // 橡皮擦 { this.toolFlag = 1; } if (e.getSource() == this.clear) // 清除 { this.toolFlag = 2; this.paintInfo.removeAllElements(); repaint(); } if (e.getSource() == this.drLine) // 画直线 { this.toolFlag = 3; } if (e.getSource() == this.drCircle) // 画圆 { this.toolFlag = 4; } if (e.getSource() == this.drRect) // 画矩形 { this.toolFlag = 5; } if (e.getSource() == this.colchooser) // 调色板 { Color newColor = JColorChooser.showDialog(this, "调色板", this.c); this.c = newColor; } // -----------------------文件选择器以及打开和保存图片按钮的设置-------------------------------------------- JFileChooser chooser = new JFileChooser("../Control/WebRoot/images"); // 在当前目录下,创建文件选择器 JpgFileFilter jpgFilter = new JpgFileFilter(); // jpg过滤器 GifFileFilter gifFilter = new GifFileFilter(); // gif过滤器 chooser.addChoosableFileFilter(jpgFilter); // 加载jpg文件过滤器 chooser.addChoosableFileFilter(gifFilter); // 加载gif文件过滤器 chooser.setFileFilter(jpgFilter); // 设置默认的文件管理器。如果不设置,则最后添加的文件过滤器为默认过滤器 if (e.getSource() == this.openPic) // 打开图片按钮 { int returnVal = chooser.showOpenDialog(this); // 打开文件选择器窗口 if (returnVal == JFileChooser.APPROVE_OPTION) { String filepath = chooser.getSelectedFile().getPath(); // 选择的文件路径 String filename = chooser.getSelectedFile().getName(); // 选择的文件名 try { this.curimg = ImageIO.read(new File(filepath)); Canvas ca = new canvas(this.curimg); add(ca); ca.setBounds(100, 200, this.curimg.getWidth(this), this.curimg.getHeight(this)); validate(); this.curcan = null; } catch (IOException e1) { e1.printStackTrace(); } } } if (e.getSource() == this.savePic) // 保存图片按钮 { chooser.setSelectedFile(new File("backPicture.jpg")); // 设置保存时的,默认文件名 int returnVal = chooser.showSaveDialog(this); // 显示保存文件窗口 String filepath = chooser.getSelectedFile().getPath(); String filename = chooser.getSelectedFile().getName(); if (returnVal == JFileChooser.APPROVE_OPTION) { if (!filepath.endsWith("jpg")) // 如果不以jpg后缀结尾,则加该后缀 { filepath = filepath + ".jpg"; } try { ImageIO.write(this.bi, "JPEG", new File(filepath)); } catch (IOException e1) { e1.printStackTrace(); } } } } public void mouseClicked(MouseEvent e) { clickhere(e); } public void mouseEntered(MouseEvent e) { } public void mouseExited(MouseEvent e) { } public void update(Graphics g) { paint(g); } public void mousePressed(MouseEvent e) { Point p2; switch (this.toolFlag) { case 3: //直线 this.x = e.getX(); this.y = e.getY(); p2 = new Point(this.x, this.y, this.c, this.toolFlag, this.con); this.paintInfo.addElement(p2); break; case 4: //圆 this.x = e.getX(); this.y = e.getY(); p2 = new Point(this.x, this.y, this.c, this.toolFlag, this.con); this.paintInfo.addElement(p2); break; case 5: //矩形 this.x = e.getX(); this.y = e.getY(); p2 = new Point(this.x, this.y, this.c, this.toolFlag, this.con); this.paintInfo.addElement(p2); } } public void mouseReleased(MouseEvent e) { //单击右键时,显示右键菜单 if ((e.getButton() == 3)) { this.popMenu2.show(e.getComponent(), e.getX(), e.getY()); } Point p3; switch (this.toolFlag) { case 0: // 画笔 this.paintInfo.addElement(this.cutflag); break; case 1: //橡皮擦 this.paintInfo.addElement(this.cutflag); break; case 3: //直线 this.x = e.getX(); this.y = e.getY(); p3 = new Point(this.x, this.y, this.c, this.toolFlag, this.con); this.paintInfo.addElement(p3); this.paintInfo.addElement(this.cutflag); repaint(); break; case 4: //圆 this.x = e.getX(); this.y = e.getY(); p3 = new Point(this.x, this.y, this.c, this.toolFlag, this.con); this.paintInfo.addElement(p3); this.paintInfo.addElement(this.cutflag); repaint(); break; case 5: //矩形 this.x = e.getX(); this.y = e.getY(); p3 = new Point(this.x, this.y, this.c, this.toolFlag, this.con); this.paintInfo.addElement(p3); this.paintInfo.addElement(this.cutflag); repaint(); case 2: } } public void mouseDragged(MouseEvent e) { Point p1; switch (this.toolFlag) { case 0: //画笔 this.x = e.getX(); this.y = e.getY(); p1 = new Point(this.x, this.y, this.c, this.toolFlag, this.con); this.paintInfo.addElement(p1); repaint(); break; case 1: //橡皮擦 this.x = e.getX(); this.y = e.getY(); p1 = new Point(this.x, this.y, null, this.toolFlag, this.Econ); this.paintInfo.addElement(p1); repaint(); } } public void mouseMoved(MouseEvent e) { if (!(this.toolPanel.isVisible())) return; setCursor(new Cursor(1)); } public void clickhere(MouseEvent e) { if (this.curcan == null) return; /** * 当选中图像工具条上的图片后,然后,在绘图区域点击鼠标左键时, * 往绘图区域添加动态图标,位置在鼠标点击时的坐标点 */ if (e.getModifiers() == MouseEvent.BUTTON1_MASK) { Canvas ca = new canvas(curimg); this.add(ca); //ca.setBounds(e.getX(), e.getY(), curimg.getWidth(this), curimg.getHeight(this)); ca.setBounds(e.getX(), 800 * 2 / 3, curimg.getWidth(this), curimg .getHeight(this)); //鼠标点击位置画出图标 this.validate(); curcan = null; } } public void paint(Graphics g) { //this.g2d = ((Graphics2D) g); this.g2d = ((Graphics2D) this.bi.getGraphics()); this.n = this.paintInfo.size(); //点信息向量Vec if (this.toolFlag == 2) //清除按钮 { g.clearRect(0, 0, getSize().width, getSize().height); // 清除 this.g2d.clearRect(0, 0, getSize().width, getSize().height); } for (int i = 0; i < this.n - 1; ++i) { DrawImage.Point p1 = this.paintInfo.elementAt(i); DrawImage.Point p2 = this.paintInfo.elementAt(i + 1); this.size = new BasicStroke(p1.boarder, 0, 2); //画笔粗细 this.g2d.setColor(p1.col); this.g2d.setStroke(this.size); if (p1.tool != p2.tool) continue; switch (p1.tool) { // 画笔 case 0: Line2D line1 = new Line2D.Double(p1.x, p1.y, p2.x, p2.y); this.g2d.draw(line1); break; // 橡皮 case 1: g.clearRect(p1.x, p1.y, p1.boarder, p1.boarder); this.g2d.clearRect(p1.x, p1.y, p1.boarder, p1.boarder); break; // 画直线 case 3: Line2D line2 = null; int X = Math.abs(p2.x - p1.x); int Y = Math.abs(p2.y - p1.y); if (X >= Y) { line2 = new Line2D.Double(p1.x, p1.y, p2.x, p1.y); } else { line2 = new Line2D.Double(p1.x, p1.y, p1.x, p2.y); } this.g2d.draw(line2); break; // 画圆 case 4: Ellipse2D ellipse = new Ellipse2D.Double(p1.x, p1.y, Math .abs(p2.x - p1.x), Math.abs(p2.y - p1.y)); this.g2d.draw(ellipse); break; // 画矩形 case 5: Rectangle2D rect = new Rectangle2D.Double(p1.x, p1.y, Math .abs(p2.x - p1.x), Math.abs(p2.y - p1.y)); this.g2d.draw(rect); break; // 截断,跳过 case 6: ++i; case 2: } } g.drawImage(this.bi, 0, 0, this); } Graphics2D g2 = null; //-----------------图像工具条------------------------ class canvas extends Canvas { private static final long serialVersionUID = 1L; Image im = null; int X; int Y; int bufferX; int bufferY; int bufferWidth; int bufferHeight; public canvas(Image paramImage) { setCursor(new Cursor(Cursor.MOVE_CURSOR)); //设置鼠标悬浮样式,设立为移动形 this.im = paramImage; //注册鼠标按下事件,用于获取需要绘制的图标对象 addMouseListener(new MouseAdapter() { public void mousePressed(MouseEvent e) { canvas.this.clickcanvas(e); } public void mouseReleased(MouseEvent e) { Canvas mcan = (Canvas) e.getSource(); int mtop = mcan.getY(); int mleft = mcan.getX(); int mwidth = mcan.getWidth(); int mheight = mcan.getHeight(); canvas.this.X = (mleft + e.getX() - DrawImage.this.clickX); canvas.this.Y = (mtop + e.getY() - DrawImage.this.clickY); canvas.this.bufferX = canvas.this.X; canvas.this.bufferY = canvas.this.Y; canvas.this.bufferWidth = mwidth; canvas.this.bufferHeight = mheight; canvas.this.drawBufferImage(); //在缓冲区中绘制出动态图像 } }); /** * 动态图标键盘事件 */ addKeyListener(new KeyAdapter() { public void keyPressed(KeyEvent e) { if (e.getKeyCode() == 127) canvas.this.removecanvas(e); } }); /** * 动态图标鼠标移动和拖动事件 */ addMouseMotionListener(new MouseMotionAdapter() { public void mouseDragged(MouseEvent e) { canvas.this.movecanvas(e); } }); } //移动图标 public void movecanvas(MouseEvent e) { Canvas mcan = (Canvas) e.getSource(); int mtop = mcan.getY(); int mleft = mcan.getX(); int mwidth = mcan.getWidth(); int mheight = mcan.getHeight(); clearImage(); //在内存中画出新图标之前,先清空这一区域以前画的图标 mcan.setBounds(mleft + e.getX() - DrawImage.this.clickX, mtop + e.getY() - DrawImage.this.clickY, mwidth, mheight); for (int i = 0; i < DrawImage.this.v.size(); ++i) { Vector v1 = DrawImage.this.v.elementAt(i); if (((Canvas[]) v1.elementAt(0))[0].equals(mcan)) { ((int[]) v1.elementAt(1))[0] = mcan.getX(); ((int[]) v1.elementAt(1))[1] = mcan.getY(); ((int[]) v1.elementAt(1))[2] = mcan.getWidth(); ((int[]) v1.elementAt(1))[3] = mcan.getHeight(); } else { if (!(((Canvas[]) v1.elementAt(0))[1].equals(mcan))) continue; ((int[]) v1.elementAt(1))[4] = mcan.getX(); ((int[]) v1.elementAt(1))[5] = mcan.getY(); ((int[]) v1.elementAt(1))[6] = mcan.getWidth(); ((int[]) v1.elementAt(1))[7] = mcan.getHeight(); } } ((DrawImage) getParent()).repaint(); } public void removecanvas(KeyEvent e) { try { Canvas mcan = (Canvas) e.getSource(); ((DrawImage) getParent()).remove(DrawImage.this.curdelcan); for (int i = DrawImage.this.v.size() - 1; i >= 0; --i) { Vector v1 = DrawImage.this.v.elementAt(i); if ((!(((Canvas[]) v1.elementAt(0))[0].equals(mcan))) && (!(((Canvas[]) v1.elementAt(0))[1].equals(mcan)))) continue; DrawImage.this.v.removeElementAt(i); } ((DrawImage) getParent()).validate(); ((DrawImage) getParent()).repaint(); } catch (NullPointerException ex) { return; } } //在单击动态图标 public void clickcanvas(MouseEvent e) { DrawImage.this.curdelcan = ((Canvas) e.getSource()); //设置将要删除的图标 DrawImage.this.clickX = e.getX(); DrawImage.this.clickY = e.getY(); ((DrawImage) getParent()).repaint(); } public void paint(Graphics g) { g.drawImage(this.im, 0, 0, this); } //在缓冲区中绘制出动态图像 public void drawBufferImage() { //Graphics2D g2 = (Graphics2D) DrawImage.this.bi.getGraphics(); g2 = (Graphics2D) DrawImage.this.bi.getGraphics(); g2.drawImage(this.im, this.X, this.Y, this); g2.dispose(); } //清除内存中的该图标区域 public void clearImage() { //Graphics2D g2 = (Graphics2D) DrawImage.this.bi.getGraphics(); g2 = (Graphics2D) DrawImage.this.bi.getGraphics(); g2.clearRect(this.bufferX, this.bufferY, this.bufferWidth, this.bufferHeight); } } //-----------------工具栏图标--------------------------------- class myCanvas extends Canvas { private static final long serialVersionUID = 1L; Image im = null; String str = ""; public myCanvas(String paramString) { this.str = paramString; } public myCanvas(Image paramImage) { setCursor(new Cursor(Cursor.HAND_CURSOR)); //设置鼠标悬浮时的样式,这里为手型 this.im = paramImage; addMouseListener(new MouseAdapter() { public void mousePressed(MouseEvent e) { myCanvas.this.clickmyCanvas(e); } }); } /** * 每一个工具按钮单击事件 */ public void clickmyCanvas(MouseEvent e) { DrawImage.this.curcan = ((Canvas) e.getSource()); //获取当前图标对象 DrawImage.this.curimg = this.im; //获取当前图标对象的图象 } public void paint(Graphics g) { if (this.str.equals("")) { g.drawImage(this.im, 0, 0, this); } else { g.drawString(this.str, 20, getHeight() / 2); } } } //-----------------工具栏图标---------结束------------------------ class Point implements Serializable { private static final long serialVersionUID = 1L; int x; int y; Color col; int tool; int boarder; Point(int paramInt1, int paramInt2) { this.x = paramInt1; this.y = paramInt2; } Point(int paramInt1, int paramInt2, Color paramColor, int paramInt3, int paramInt4) { this.x = paramInt1; this.y = paramInt2; this.col = paramColor; this.tool = paramInt3; this.boarder = paramInt4; } } // -----------------文件选择器中jpg和gif文件的过滤------------------------------------- class JpgFileFilter extends FileFilter { public String getDescription() { return "*.jpg"; } public boolean accept(File file) { String name = file.getName(); return name.toLowerCase().endsWith(".jpg"); } } class GifFileFilter extends FileFilter { public String getDescription() { return "*.gif"; } public boolean accept(File file) { String name = file.getName(); return name.toLowerCase().endsWith(".gif"); } } //----------------文件选择器中jpg和gif文件的过滤---------结束----------------------------- }
发表评论
-
Applet画图程序
2010-01-11 14:18 1763双击右键才显示功能菜单。。。 import java ... -
Applet打印
2009-11-23 15:56 2081效果如上图: import java.awt.*; i ... -
applet数字签名实践篇三(转载)
2009-11-17 18:56 2068最近在研究applet,打算使用applet来开发一个上传文件 ... -
applet数字签名实践篇二(转载)
2009-11-17 18:45 1366【摘 要】如果你要考虑在Internet上实现这个Applet ... -
applet数字签名实践篇一(转载)
2009-11-17 18:44 1563本人在报表开发之时, ... -
Applet与Servlet通信
2009-11-13 17:42 1194在今天的多层结构的web应用程序的设计中,我们可以同时使用Ja ... -
使用 Java applet 访问远程 Web 服务
2009-11-13 10:35 1911通过浏览器提交、接收和分析 XML Web 服务消息 ... -
利用Applet进行Web打印
2009-11-07 17:45 1960一web打印常见方法: 1,一种简单的方法是在html上调用w ... -
applet应用小技巧
2009-11-06 13:29 10551。获取屏幕分辩率的宽和高: int width=To ... -
applet图像的处理
2009-11-03 16:08 2079设置呈现(RenderingHints)提示 8.2 ... -
applet绘制纹理图
2009-11-03 16:04 1171其效果如下图: import java.applet.*; ... -
applet中保存canvas中的图片
2009-11-02 15:36 1631效果图如下: import java.awt.*; ... -
applet画图板程序(画直线、画圆、画笔、画矩形、调色板)
2009-10-27 17:08 5084import java.applet.*; import j ... -
applet画图板程序
2009-10-27 17:00 2056import java.applet.Applet; imp ... -
applet的简单流程图绘制小工具
2009-10-27 16:58 1924使用说明如下: 1.在主区域的上面有一个写有"dr ... -
applet图形缩放类
2009-10-24 20:11 1325import java.awt.Image; import ... -
applet文字和图标的合成
2009-10-24 17:43 1625相信大家平时碰到过一些在JAVA中对图像进行处理的需求,比如需 ... -
运行applet时出现无法载入class的问题,以及设置codeBase
2009-08-13 17:57 2393最简单的方法就是:把它们放在同一个目录就不用设置啦。。。,但是 ... -
IE中Applet不能运行的问题
2009-08-13 17:49 2169applet程序正常没问题,在Html页面中的设置也没问题,只 ... -
Applet 双缓冲技术
2009-07-23 17:32 1564import java.applet.Applet; imp ...
相关推荐
本案例中,我们探讨的是一个利用Applet来实现画图操作界面的应用。这个界面允许用户绘制直线、椭圆、矩形以及曲线,并且可以自定义颜色和画笔的大小,提供了一种丰富的图形绘制功能。 首先,我们需要了解Applet的...
此Java小游戏利用 `Applet` 类结合 `Graphics` 接口和事件监听器实现了简单的鼠标画图功能,通过按钮可以轻松地更改颜色以及清除图形,是一个很好的学习示例,帮助理解 Java 图形编程的基本概念和技术。
Java Applet 是一种小型的、可嵌入网页中的Java程序。它可以在支持Java的Web浏览器上运行,用于增强网页的功能性和交互性。在本案例中,我们通过Java Applet 实现了一个具有简单功能的风扇模拟器,该程序允许用户...
3. Applet编程:在Java Applet程序中,需要覆盖父类的paint()方法来完成画图操作。 4. 标识符:Java中的标识符是指变量、方法、类等的名称。合法的标识符必须以字母开头,后跟字母、数字或下划线。 5. 访问控制符...
5. Java Applet程序用户自定义的Applet子类中,一般需要重载父类的paint()方法来完成一些画图操作。 二、Java语言基础 1. 在Java中,赋值运算符的优先级高于比较运算符。 2. 在Java中,使用类名作为前缀可以调用...
通过这些Applet,学习者可以更深入地了解数据如何在内存中组织以及算法如何影响其性能。 ExamplePrograms.ZIP则很可能包含了实际的Java源代码,涵盖各种经典的数据结构和算法实现。这些源码可能包括了数组、链表、...
在这个例子中,`paint`方法使用`Graphics`对象绘制文本,说明了如何使用颜色和字符串在屏幕上画图。 在基本数据类型的例子中,我们看到了`char`、`int`以及它们与Unicode的关系。`Example2_1`展示了如何将Unicode码...
11. **Applet绘图**:Applet需要重写`paint()`或`paintComponent()`方法来实现画图功能。 12. **布局管理器**:BorderLayout、FlowLayout、GridLayout和CardLayout分别是Java GUI中常用的布局管理器。- ...
26. "画图"软件:Windows 98的附件中包含"画图"程序,用于创建、编辑和查看图片。 27. 局域网与广域网:局域网通常提供高有效性且可靠性高,相比之下,广域网可能在覆盖范围更广的同时牺牲一部分效率和可靠性。 28...
20. **重构**:在Eclipse中,可以使用重构功能来统一修改被多次引用的类或者变量的名字。 #### 二十一、Java Web开发技术 21. **Java Web开发技术**:Java开发Web程序的主要技术包括`Servlet`和`JSP`。 #### 二十...
2. 自定义的Applet子类通常需要覆盖 `paint()` 方法来完成画图操作。 3. 合法的逻辑表达式是 `9>6&&8。 4. Java 语言由 Sun 公司于1995年发布。 5. 合法的变量定义语句是 `double a=Double.MAX_VALUE`。 6. 被 `...
实例31 用Applet显示图片 实例32 图片火焰效果 实例33 图片百叶窗 实例34 图片倒影 实例35 图片翻折 实例36 闹钟 实例37 万年历 实例38 计算器 实例39 电子相册 实例40 声音播放程序 实例41 视频播放程序 实例42 半...
Java是一种服务器端或客户端运行的语言,但在Web浏览器中通常使用JavaScript或VBScript来编写客户端脚本,而Java主要用于开发服务器端应用程序或通过Applet在客户端运行。 **正确答案:** C. Java ### 11. Python...
5.2.4 修改后的妈妈类 5.3 知识点扩展——线程的状态 5.3.1 线程的创建状态 5.3.2 线程的暂停状态 5.3.3 线程的结束状态 5.4 小结 第6章 火车站售票系统(线程安全知识) 6.1 火车站售票系统原理 6.1.1 项目结构框架...
根据给定文件的信息,我们可以总结出...- **事件处理:** Java Applet中处理事件通常需要导入`java.awt.event`包。 **答案解析:** 正确的答案是**import java.awt.event**。这通常是为了导入处理事件所需的类和接口。