JAVA 一个简单的代码 为什么画不出图? 哪里出了问题
//画图练习packagecome.kyle;importjava.awt.*;importjavax.swing.*;classTest{publicstaticvoi...
//画图练习
package come.kyle;
import java.awt.*;
import javax.swing.*;
class Test
{
public static void main(String[] args)
{
Windows w=new Windows();
}
}
class Windows extends JFrame
{
MyPanel mp=null;
public void Windows()
{
this.setSize(400, 400);
this.setTitle("画图测试");
this.setLocation(200,200);
this.setDefaultCloseOperation(EXIT_ON_CLOSE);
this.setVisible(true);
mp=new MyPanel();
this.add(mp);
System.out.println("hello");
}
}
class MyPanel extends Panel
{
public void paint(Graphics g)
{
super.paint(g);
System.out.println("paint被调用");
g.drawOval(10, 10, 30, 30);
}
} 展开
package come.kyle;
import java.awt.*;
import javax.swing.*;
class Test
{
public static void main(String[] args)
{
Windows w=new Windows();
}
}
class Windows extends JFrame
{
MyPanel mp=null;
public void Windows()
{
this.setSize(400, 400);
this.setTitle("画图测试");
this.setLocation(200,200);
this.setDefaultCloseOperation(EXIT_ON_CLOSE);
this.setVisible(true);
mp=new MyPanel();
this.add(mp);
System.out.println("hello");
}
}
class MyPanel extends Panel
{
public void paint(Graphics g)
{
super.paint(g);
System.out.println("paint被调用");
g.drawOval(10, 10, 30, 30);
}
} 展开
2个回答
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询