使用JAVA创建Paint程序 [英] create Paint program using JAVA

查看:86
本文介绍了使用JAVA创建Paint程序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个想法,可以创建一个与Windows中的PAINT程序相同的PAINT程序.我想使用JAVA语言.这是我从互联网上获得的一些编码.

I get an idea to create a PAINT program same with PAINT program in Windows. I want to use JAVA language. This is some of coding that I get from the internet.

import java.applet.*;
import java.awt.*;
import java.awt.event.*;

public class Paint extends Applet
implements MouseMotionListener {

int width, height;
Image backbuffer;
Graphics backg;

public void init() {
width = getSize().width;
height = getSize().height;

backbuffer = createImage( width, height );
backg = backbuffer.getGraphics();
backg.setColor( Color.white );
backg.fillRect( 0, 0, width, height );
backg.setColor( Color.red );

backbuffer = createImage( width, height );
backg = backbuffer.getGraphics();
backg.setColor( Color.white );
backg.fillRect( 0, 0, width, height );
backg.setColor( Color.blue );

addMouseMotionListener( this );
}
public void mouseMoved( MouseEvent e ) { }
public void mouseDragged( MouseEvent e ) {
int x = e.getX();
int y = e.getY();
backg.fillOval(x-10,y-10,20,20);
repaint();
e.consume();
}

public void update( Graphics g ) {
g.drawImage( backbuffer, 0, 0, this );
}
public void paint( Graphics g ) {
update( g );
}
}


从这个代码中,我想在该程序中添加一些工具..所以,我希望所有程序员都提供一些建议或想法..如果您有一个指导如何创建它的链接,我将很高兴学习它..

谢谢..


From this code,i want to add some tools in this program..So,i want some advice or idea from all programmer..If u have a link that guide how to create it,im so happy to learn it..

Thank You..

推荐答案

如果您出于学习目的确实需要此代码(请参阅问题注释中的讨论),则确实需要编写自己编写编辑器代码,而不是尝试修改从Internet上获取的某些代码.您只能使用这样的代码来获得基本思想,学习一些技巧等.可能找到的代码不是按照您的要求编写的,可能是不好的,或者只是写得不好.导致此类代码的潜在实用性低的一个因素是:Paint功能的实现实际上没有任何实际意义:存在一些不错的开源图形编辑器(也在线),并且Microsoft Paint具有如此有限且较差的功能,实际上几乎没有用.即使对于您的目的来说仍然很好,但要注意的是:为实现惨淡的目标而编写的代码通常不是由合格的开发人员编写的,它难以阅读,不被支持且容易出错.您无法从中获得很多好处,甚至不能节省开发时间,而浪费了很多.

以您的代码示例中的代码为例:它与编辑器所需的代码不同.只是看一下像-10或20这样的硬编码立即数就可以告诉我它不能被合理地支持或修改.如果您编写自己的代码,则将更好地利用您的时间.如果从良好的软件开发中讲出不好的话,至少可以得到一些经验.

祝你好运,
—SA
If you really need this code for the purposes of study (please see the discussion in the comments to the question), you really need to write the editor code by yourself, instead of trying to modify some code taken from Internet. You could use such code only to take the basic ideas, learn some techniques, etc. The code you can possibly find is not written per your requirements, it could be bad, or just poorly written. One factor contributing to low potential usefulness of such code is: the implementation of Paint functionality would have virtually no practical sense: some decent open-source graphical editor exist (on-line, too), and the Microsoft Paint has so limited and poor functionality, that it''s hardly practically useful. Even though it would still be fine for your purposes, the catch is: the code written for miserable goals is usually written by not a qualified developer, it''s hard to read, unsupportable and fool of bugs; you cannot get much benefits of using it, not even save your development time, rather waste a lot of it.

Take the code of your code sample: it does not resemble the code needed for an editor. Just a look for hard-coded immediate constants like -10 or 20 tells me it cannot be reasonably supported or modified. You will much better use your time if you write your own code. At least you can get some experience if telling bad from good and software development.

Good luck,
—SA


这篇关于使用JAVA创建Paint程序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆