画一个圆用窗口显示,圆的尺寸怎么通过控制台输入?
程序代码:
package 实验3_2; import java.awt.*; import javax.swing.*; public class MyCircle { private int r; private Color Color2; private int x,y; JFrame mf; static double π=3.14159; //设置格式 public MyCircle(int r,int x,int y,JFrame mf) { this.r=r; this.mf=mf; this.x=x; this.y=y; this.Color2=new Color(25,25,100); } public void draw (Graphics g) { g.setColor(this.Color2); g.fillOval(x, y, r, r); } public void test() { mf.repaint(); } }
//窗口
程序代码:
package 实验3_2; import javax.swing.*; import java.util.Scanner; import java.awt.*; @SuppressWarnings("serial") public class MyJFrame extends JFrame { MyCircle mc; public MyJFrame() { this.setSize(1000,1000); this.setVisible(true); } public void paint(Graphics g) { mc.draw(g); } public static void main(String[] arg) { // TODO Auto-generated method stub MyJFrame mf=new MyJFrame(); int X1=50; int Y1=200; int R1=100; Scanner in=new Scanner(System.in); X1=in.nextInt(); Y1=in.nextInt(); R1=in.nextInt(); mf.mc=new MyCircle(R1,X1,Y1,mf); mf.mc.test(); } }
控制台输出Exception in thread "AWT-EventQueue-0" java.lang.NullPointerException
at 实验3_2.MyJFrame.paint(MyJFrame.java:21)
、、