import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import java.awt.geom.*;
class Point {
private int x;
private int y;
public Point(){
x=0;
y=0;
}
public Point(int xx,int yy){
x=xx;
y=yy;
}
public void setPint(int xx,int yy){
x=xx;
y=yy;
}
public int getX(){
return x;
}
public int getY(){
return y;
}
}
public void paintComponent(Graphics g) {
super.paintComponent(g);
Graphics2D g2 = (Graphics2D)g;
g2.setColor(Color.blue);
double u=0.1;
int Sqr=10;
//Point P,Q,S,R;
Point[][] points=new Point[4][4];
points[0][0]=new Point(100,100);
points[0][1]= new Point(300,100);
points[0][2]= new Point(100,300);
points[0][3]= new Point(300,300);
g2.drawLine(points[0][0].getX(), points[0][0].getY(), points[0][1].getX(), points[0][1].getY());
g2.drawLine(points[0][3].getX(), points[0][3].getY(), points[0][1].getX(), points[0][1].getY());
g2.drawLine(points[0][2].getX(), points[0][2].getY(), points[0][3].getX(), points[0][3].getY());
g2.drawLine(points[0][0].getX(), points[0][0].getY(), points[0][2].getX(), points[0][2].getY());
//points[0][0]=P;
//points[0][1]=Q;
//points[0][2]=S;
//points[0][3]=R;
for(int i=0;i<4;i++){
for(int j=0;j<4;j++){
//points[i][j]=new Point();
points[i+1][j].setPint((int)((1-u)* points[i][j].getX()+ u * points[i][j+1].getX()),(int) ((1-u) * points[i][j].getY()+ u * points[i][j+1].getY()));
}
// for(int line=0;line<4;line++){
// g2.drawLine(points[i][line].getX(),points[i][line].getY(),points[i][line+1].getX(),points[i][line+1].getY());
// }
}
// System.out.println("#####");
// System.out.println(points[0][0].getX());
// System.out.println(points[0][0].getY());
// System.out.println("#####");
//
//P1.setPint((int) ((1-u)*P.getX()+ u* Q.getX()), (int) ((1-u)*P.getY()+ u* Q.getY()));
//Q1.setPint((int) ((1-u)*Q.getX()+ u* R.getX()), (int) ((1-u)*Q.getY()+ u* R.getY()));
//R1.setPint((int) ((1-u)*R.getX()+ u* S.getX()), (int) ((1-u)*R.getY()+ u* S.getY()));
//S1.setPint((int) ((1-u)*S.getX()+ u* P.getX()), (int) ((1-u)*S.getY()+ u* P.getY()));
//
//g2.drawLine(points[0][0].getX(), points[0][0].getY(), points[0][1].getX(), points[0][1].getY());
//g2.drawLine(points[0][1].getX(), points[0][1].getY(), points[0][3].getX(), points[0][3].getY());
//g2.drawLine(points[0][3].getX(), points[0][3].getY(), points[0][2].getX(), points[0][2].getY());
//g2.drawLine(points[0][2].getX(), points[0][2].getY(), points[0][0].getX(), points[0][0].getY());
}
线程中的异常&#34; AWT-EventQueue-0&#34;显示java.lang.NullPointerException
在Hello2DPanel.paintComponent(Hello2D.java:78)处 javax.swing.JComponent.paint(JComponent.java:1056)at javax.swing.JComponent.paintChildren(JComponent.java:889)at javax.swing.JComponent.paint(JComponent.java:1065)at javax.swing.JComponent.paintChildren(JComponent.java:889)at javax.swing.JComponent.paint(JComponent.java:1065)at javax.swing.JLayeredPane.paint(JLayeredPane.java:586)at at javax.swing.JComponent.paintChildren(JComponent.java:889)at javax.swing.JComponent.paintToOffscreen(JComponent.java:5217)at javax.swing.RepaintManager中的$ PaintManager.paintDoubleBuffered(RepaintManager.java:1579) 在 javax.swing.RepaintManager中的$ PaintManager.paint(RepaintManager.java:1502) 在javax.swing.RepaintManager.paint(RepaintManager.java:1272)at javax.swing.JComponent.paint(JComponent.java:1042)at java.awt.GraphicsCallback $ PaintCallback.run(GraphicsCallback.java:39) 在 sun.awt.SunGraphicsCallback.runOneComponent(SunGraphicsCallback.java:79) 在 sun.awt.SunGraphicsCallback.runComponents(SunGraphicsCallback.java:116) 在java.awt.Container.paint(Container.java:1975)at javax.swing.RepaintManager $ 4.run(RepaintManager.java:842)at javax.swing.RepaintManager $ 4.run(RepaintManager.java:814)at java.security.AccessController.doPrivileged(Native Method)at java.security.ProtectionDomain $ JavaSecurityAccessImpl.doIntersectionPrivilege(ProtectionDomain.java:76) 在 javax.swing.RepaintManager.paintDirtyRegions(RepaintManager.java:814) 在 javax.swing.RepaintManager.paintDirtyRegions(RepaintManager.java:789) 在 javax.swing.RepaintManager.prePaintDirtyRegions(RepaintManager.java:738) 在javax.swing.RepaintManager.access $ 1200(RepaintManager.java:64)at javax.swing.RepaintManager中的$ ProcessingRunnable.run(RepaintManager.java:1732) at java.awt.event.InvocationEvent.dispatch(InvocationEvent.java:311) 在java.awt.EventQueue.dispatchEventImpl(EventQueue.java:756)at java.awt.EventQueue.access $ 500(EventQueue.java:97)at java.awt.EventQueue $ 3.run(EventQueue.java:709)at java.awt.EventQueue $ 3.run(EventQueue.java:703)at java.security.AccessController.doPrivileged(Native Method)at java.security.ProtectionDomain $ JavaSecurityAccessImpl.doIntersectionPrivilege(ProtectionDomain.java:76) 在java.awt.EventQueue.dispatchEvent(EventQueue.java:726)at java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:201) 在 java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:116) 在 java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:105) 在 java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:101) 在 java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:93) at java.awt.EventDispatchThread.run(EventDispatchThread.java:82) 线程中的异常&#34; AWT-EventQueue-0&#34;显示java.lang.NullPointerException 在Hello2DPanel.paintComponent(Hello2D.java:78)at javax.swing.JComponent.paint(JComponent.java:1056)at javax.swing.JComponent.paintChildren(JComponent.java:889)at javax.swing.JComponent.paint(JComponent.java:1065)at javax.swing.JComponent.paintChildren(JComponent.java:889)at javax.swing.JComponent.paint(JComponent.java:1065)at javax.swing.JLayeredPane.paint(JLayeredPane.java:586)at at javax.swing.JComponent.paintChildren(JComponent.java:889)at javax.swing.JComponent.paintToOffscreen(JComponent.java:5217)at javax.swing.RepaintManager中的$ PaintManager.paintDoubleBuffered(RepaintManager.java:1579) 在 javax.swing.RepaintManager中的$ PaintManager.paint(RepaintManager.java:1502) 在javax.swing.RepaintManager.paint(RepaintManager.java:1272)at javax.swing.JComponent.paint(JComponent.java:1042)at java.awt.GraphicsCallback $ PaintCallback.run(GraphicsCallback.java:39) 在 sun.awt.SunGraphicsCallback.runOneComponent(SunGraphicsCallback.java:79) 在 sun.awt.SunGraphicsCallback.runComponents(SunGraphicsCallback.java:116) 在java.awt.Container.paint(Container.java:1975)at javax.swing.RepaintManager $ 4.run(RepaintManager.java:842)at javax.swing.RepaintManager $ 4.run(RepaintManager.java:814)at java.security.AccessController.doPrivileged(Native Method)at java.security.ProtectionDomain $ JavaSecurityAccessImpl.doIntersectionPrivilege(ProtectionDomain.java:76) 在 javax.swing.RepaintManager.paintDirtyRegions(RepaintManager.java:814) 在 javax.swing.RepaintManager.paintDirtyRegions(RepaintManager.java:789) 在 javax.swing.RepaintManager.prePaintDirtyRegions(RepaintManager.java:738) 在javax.swing.RepaintManager.access $ 1200(RepaintManager.java:64)at javax.swing.RepaintManager中的$ ProcessingRunnable.run(RepaintManager.java:1732) at java.awt.event.InvocationEvent.dispatch(InvocationEvent.java:311) 在java.awt.EventQueue.dispatchEventImpl(EventQueue.java:756)at java.awt.EventQueue.access $ 500(EventQueue.java:97)at java.awt.EventQueue $ 3.run(EventQueue.java:709)at java.awt.EventQueue $ 3.run(EventQueue.java:703)at java.security.AccessController.doPrivileged(Native Method)at java.security.ProtectionDomain $ JavaSecurityAccessImpl.doIntersectionPrivilege(ProtectionDomain.java:76) 在java.awt.EventQueue.dispatchEvent(EventQueue.java:726)at java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:201) 在 java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:116) 在 java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:105) 在 java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:101) 在 java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:93) 在java.awt.EventDispatchThread.run(EventDispatchThread.java:82)
绘制一个正方形,然后通过参数u在第一个缩小的尺寸内绘制第二个正方形,依此类推
P1x =((1-u)* Px)+(u * Qx)
P1y =((1 - u)* Py)+(u * Qy)
类似地,Q,R,S
注意:不使用Cos和Sin或高级三角方程。
哪里错了?