import java.awt.*;
public class EllipseTest extends Frame {
public static void main (String args[]) {
EllipseTest test=new EllipseTest();
test.setSize(300,300);
test.setVisible(true);
Graphics g=test.getGraphics();
g.fillOval(150,150,60,50);
g.setColor(Color.red);
test.paint(g);
test.paint(g);
}
}
这是我自己写的一个程序,但是有几个问题,一个是执行程序只显示黑色,不能按题目要求出现红色。二是在最大和最小化窗口时候会看不见那个椭圆。请问大家要怎么解决这些问题,谢谢!
public class EllipseTest extends Frame {
public static void main (String args[]) {
EllipseTest test=new EllipseTest();
test.setSize(300,300);
test.setVisible(true);
Graphics g=test.getGraphics();
g.fillOval(150,150,60,50);
g.setColor(Color.red);
test.paint(g);
test.paint(g);
}
}
这是我自己写的一个程序,但是有几个问题,一个是执行程序只显示黑色,不能按题目要求出现红色。二是在最大和最小化窗口时候会看不见那个椭圆。请问大家要怎么解决这些问题,谢谢!
import java.awt.*;public class EllipseTest extends Frame { public static void main (String args[]) {
EllipseTest test=new EllipseTest();
test.setSize(300,300);
test.setVisible(true);// Graphics g=test.getGraphics();
// g.fillOval(150,150,60,50);
// g.setColor(Color.red);
// test.paint(g);// test.paint(g);
}
public void paint(Graphics g) {
super.paint(g);
g.setColor(Color.red);
g.fillOval(150,150,60,50);
}
}
2 rewrite the frame's
public void paint(Graphics g){
// Your codes here
}instead of calling frame.paint(g)
import java.awt.*;
import java.awt.event.*;public class EllipseTest extends Frame {
public EllipseTest() {
this.addComponentListener(new ComponentAdapter() {
public void componentResized(ComponentEvent e) {
repaint();
}
});
} public static void main (String args[]) {
EllipseTest test=new EllipseTest();
test.setSize(300,300);
test.setVisible(true);
} public void paint(Graphics g) {
super.paint(g);
g.setColor(Color.red);
g.fillOval((int)getSize().getWidth()/2-30,(int)getSize().getHeight()/2-25,60,50);
}
}