为什么画不出图?
import 。。。。……
public class Game extends Frame{
private final static int FW = 400, FH = 510;
private final static int HKW = 300, HKH = 480;
public static void main(String[] args) {
new Game().newFrame();
}
public void newFrame() {
Frame f = new Frame();
f.setBounds(500,100,FW,FH);
f.setVisible(true);
f.setResizable(false);
f.addWindowListener(new WindowAdapter() {
public void windowClosing(WindowEvent e) {
System.exit(0);
}
});
}
public void paint(Graphics g) {
Color c = g.getColor();
g.setColor(Color.RED);
g.drawRect(3,24,HKW,HKH);
g.setColor(c);
}
}
----------------解决方案--------------------------------------------------------
不知道是LZ复制的时候出错还是编写错误.
导包有问题,最后一个花括号也是中文符号.
以下是我修改后的代码,希望LZ满意.
程序代码:
import java.awt.*;
import java.awt.event.*;
public class Game extends Frame
{
private final static int FW = 400, FH = 510;
private final static int HKW = 300, HKH = 480;
public static void main(String[] args)
{
Game g=new Game();//.newFrame();
g.newFrame();
g.setSize(600,600);
g.show();
}
public void newFrame()
{
Frame f = new Frame();
f.setBounds(500,100,FW,FH);
// f.setVisible(true);
f.setResizable(false);
f.addWindowListener(new WindowAdapter()
{
public void windowClosing(WindowEvent e)
{
System.exit(0);
}
});
}
public void paint(Graphics g)
{
Color c = g.getColor();
g.setColor(Color.red);
g.drawRect(120,50,HKW,HKH);
g.setColor(c);
}
}
import java.awt.event.*;
public class Game extends Frame
{
private final static int FW = 400, FH = 510;
private final static int HKW = 300, HKH = 480;
public static void main(String[] args)
{
Game g=new Game();//.newFrame();
g.newFrame();
g.setSize(600,600);
g.show();
}
public void newFrame()
{
Frame f = new Frame();
f.setBounds(500,100,FW,FH);
// f.setVisible(true);
f.setResizable(false);
f.addWindowListener(new WindowAdapter()
{
public void windowClosing(WindowEvent e)
{
System.exit(0);
}
});
}
public void paint(Graphics g)
{
Color c = g.getColor();
g.setColor(Color.red);
g.drawRect(120,50,HKW,HKH);
g.setColor(c);
}
}
----------------解决方案--------------------------------------------------------
不知是LZ复制时疏忽还是编写时错误.
导包有问题,最后一个}花括号是中文符号.
以下是简单修改后的代码:
程序代码:
import java.awt.*;
import java.awt.event.*;
public class Game extends Frame
{
private final static int FW = 400, FH = 510;
private final static int HKW = 300, HKH = 480;
public static void main(String[] args)
{
Game g=new Game();//.newFrame();
g.newFrame();
g.setSize(600,600);
g.show();
}
public void newFrame()
{
Frame f = new Frame();
f.setBounds(500,100,FW,FH);
//f.setVisible(true);
f.setResizable(false);
f.addWindowListener(new WindowAdapter()
{
public void windowClosing(WindowEvent e)
{
System.exit(0);
}
});
}
public void paint(Graphics g)
{
//Color c = g.getColor();
g.setColor(Color.red);
g.drawRect(120,50,HKW,HKH);
//g.setColor(c);
}
}
import java.awt.event.*;
public class Game extends Frame
{
private final static int FW = 400, FH = 510;
private final static int HKW = 300, HKH = 480;
public static void main(String[] args)
{
Game g=new Game();//.newFrame();
g.newFrame();
g.setSize(600,600);
g.show();
}
public void newFrame()
{
Frame f = new Frame();
f.setBounds(500,100,FW,FH);
//f.setVisible(true);
f.setResizable(false);
f.addWindowListener(new WindowAdapter()
{
public void windowClosing(WindowEvent e)
{
System.exit(0);
}
});
}
public void paint(Graphics g)
{
//Color c = g.getColor();
g.setColor(Color.red);
g.drawRect(120,50,HKW,HKH);
//g.setColor(c);
}
}
----------------解决方案--------------------------------------------------------
那个怎么还是发出去了!!! 2楼可以忽略
----------------解决方案--------------------------------------------------------
mark
----------------解决方案--------------------------------------------------------
谢谢各位帮忙了,不过在之前自己已经解决了。主要是在我在main中就new出了一个来,然后又在newFrame()中有去new一个。这样就有了两个,而画圆则是画在
main中new出来那个,而恰恰这个有没有显示出来,所以出现没有出现在屏幕上了。
----------------解决方案--------------------------------------------------------
两个new 就容易出错了,我经常犯这个错,但是自己知道
----------------解决方案--------------------------------------------------------