老师布置了一个作业,说是要自己编个代码画个圆,直线什么的,然后还要打印出来我们是在命令行方式下,用java与javac方式的,请问有没有类是专门用来画图的啊?或者其它方式画图?
谢谢!!!

解决方案 »

  1.   

    applet可以
    也可以画在panel等上面
      

  2.   

    void destroy() 
              Called by the browser or applet viewer to inform this applet that it is being reclaimed and that it should destroy any resources that it has allocated. 
     AccessibleContext getAccessibleContext() 
              Gets the AccessibleContext associated with this Applet. 
     AppletContext getAppletContext() 
              Determines this applet's context, which allows the applet to query and affect the environment in which it runs. 
     String getAppletInfo() 
              Returns information about this applet. 
     AudioClip getAudioClip(URL url) 
              Returns the AudioClip object specified by the URL argument. 
     AudioClip getAudioClip(URL url, String name) 
              Returns the AudioClip object specified by the URL and name arguments. 
     URL getCodeBase() 
              Gets the base URL. 
     URL getDocumentBase() 
              Gets the URL of the document in which this applet is embedded. 
     Image getImage(URL url) 
              Returns an Image object that can then be painted on the screen. 
     Image getImage(URL url, String name) 
              Returns an Image object that can then be painted on the screen. 
     Locale getLocale() 
              Gets the Locale for the applet, if it has been set. 
     String getParameter(String name) 
              Returns the value of the named parameter in the HTML tag. 
     String[][] getParameterInfo() 
              Returns information about the parameters that are understood by this applet. 
     void init() 
              Called by the browser or applet viewer to inform this applet that it has been loaded into the system. 
     boolean isActive() 
              Determines if this applet is active. 
    static AudioClip newAudioClip(URL url) 
              Get an audio clip from the given URL. 
     void play(URL url) 
              Plays the audio clip at the specified absolute URL. 
     void play(URL url, String name) 
              Plays the audio clip given the URL and a specifier that is relative to it. 
     void resize(Dimension d) 
              Requests that this applet be resized. 
     void resize(int width, int height) 
              Requests that this applet be resized. 
     void setStub(AppletStub stub) 
              Sets this applet's stub. 
     void showStatus(String msg) 
              Requests that the argument string be displayed in the "status window". 
     void start() 
              Called by the browser or applet viewer to inform this applet that it should start its execution. 
     void stop() 
              Called by the browser or applet viewer to inform this applet that it should stop its execution. 我在文档里,找遍了。可就是没有找到我要找画图的函数啊?
    请问是这个applet吗?谢谢!在Java中有没有画像素点的函数啊?
      

  3.   

    随便找本教材,涉及到appet肯定会有画图这部分的
    paint方法
      

  4.   

    java.awt.Graphics 查下jdk帮助文档,另外在jdk的安装目录有个示例程序, $JDKHOME\demo\jfc\Java2D
      

  5.   

    Java中画像素点可以有如下方法实现:
      1. 画一条直线,起始点和终结点重合(drawLine(x,y,x,y))
      2. 画一个椭圆,椭圆的长轴和短轴长度都为1(drawOval(x,y,1,1))
      

  6.   

    前两天刚写一个画图的东西.不过没加打印.
    你可以参考一下.
    http://www.javafan.net/jive/thread.jsp?forum=1&thread=2436
      

  7.   

    用Graphics 类
    好像要定义一个Graphics g对象,然后,用g.draw******()的方法,里面有画各种图形的函数
      

  8.   

    import java.applet.Applet;
    import java.awt.Graphics;public class draw extends Applet{
        public void paint(Graphics g){
            g.drawOval(100,200,50,50);
        }
        
    }用了这段代码,可这并不能画出一个圆来,因为它这儿缺少一个main方法
    然后我自己加了一个main方法的类,可这个Graphics 参数该怎么办啊,它是抽象类,不能创建对象的啊?
    可怎么写才能在命令行方式下输入java draw就能画出一个图啊?
    谢谢了!!!
      

  9.   

    先定义一个框架类:ExitableJFrame,用来生成框架,做好以后可以一直用了!
    import javax.swing.*;
    public class ExitableJFrame extends JFrame {
    public ExitableJFrame(){
    }
    public ExitableJFrame(String title){
    super(title);
    }
    protected void frameInit(){
    super.frameInit();
    setDefaultCloseOperation(EXIT_ON_CLOSE);
    }
    }
    然后生成一个剪切的子类实现对椭圆的剪切:
    import java.awt.*;
    import java.util.*;
    public class Clip extends ExitableJFrame {
    Insets insets;
    public void paint(Graphics g){
    super.paint(g);
    if(insets == null){
    insets=getInsets();
    }
         int x=insets.left;
         int y=insets.top;
         int width=getWidth()-insets.left-insets.right-1;
         int height=getHeight()-insets.top-insets.bottom-1;
         g.drawOval(x,y,width,height);
         int quarter=height/4;
         g.clipRect(x,y+quarter,width,height-quarter*2);
         g.fillOval(x,y,width,height);
    }     
         

    public static void main(String[] args) {
    Frame f=new Clip();
    f.setTitle("clip");
    f.setSize(300,200);
    f.show();
    }
    }
    画图的工具主要是java.awt包。
      

  10.   

    是不是在java不能在XP系统的CMD界面里画图,是吗?
      

  11.   

    是的, 必须在一个窗口系统中才能画的, 要 new 一个Frame出来供画图使用