图形错误 [英] Graphics Error

查看:88
本文介绍了图形错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我一直在尝试制作一个java图形程序但是每当我试图让它工作时没有任何反应,就不会出现任何窗口。这是我的源代码:


import java.awt。*;


公共类图形{

public static void main(String args []){


}

public void paint(Graphics g){

g.drawRect (300,200,75,75);

}

}

ps我有一个没有任何内容的公共静态void main的原因是因为否则当我运行它时,它说我需要在其中有一个公共静态void main(String args [])。

I have been trying to make a java graphics program but whenever i try to make it work nothing happens, no window appears. Here is my source code:

import java.awt.*;

public class graphics {
public static void main(String args[]){

}
public void paint(Graphics g){
g.drawRect(300, 200, 75, 75);
}
}
p.s. the reason i have a public static void main without anything in it is because otherwise when i run it, it says i need to have a public static void main(String args[]) in it.

推荐答案

public static void main(String [] args)是主要方法 - 程序执行,该函数告诉它做什么。所以如果你只是改变它:
public static void main(String[] args) is the main method - the program does, what this function tells it to do. So if you just change it like this:
展开 | 选择 | Wrap | 行号



我有一直试图制作一个java图形程序,但每当我尝试使其工作没有任何反应时,没有窗口出现。这是我的源代码:


import java.awt。*;


公共类图形{

public static void main(String args []){


}

public void paint(Graphics g){

g.drawRect (300,200,75,75);

}

}

ps我有一个没有任何东西的公共静态void main的原因是因为否则当我运行它时,它说我需要一个public static void main(String args [])。
I have been trying to make a java graphics program but whenever i try to make it work nothing happens, no window appears. Here is my source code:

import java.awt.*;

public class graphics {
public static void main(String args[]){

}
public void paint(Graphics g){
g.drawRect(300, 200, 75, 75);
}
}
p.s. the reason i have a public static void main without anything in it is because otherwise when i run it, it says i need to have a public static void main(String args[]) in it.



好​​的。嗯,你需要在你看到的地方画画。现在你不要那样画到控制台。阅读 Sun的绘画教程,看看它是如何完成的。

OK. Um, you need to be painting somewhere you see. Now you don''t paint to the console like that. Read Sun''s painting tutorial to see how it''s done.


这是否意味着我应该将public void paint(Graphics g)置于public static void main
Does that mean that i should place the public void paint(Graphics g) should be within the public static void main


这篇关于图形错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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