一下代码为何只绘出了圆弧,没有绘出矩形,感谢兄台赐教!
import javax.swing.JApplet;
import javax.swing.JComponent;
import java.awt.Color;
import java.awt.Graphics2D;
import java.awt.Container;
import java.awt.Graphics;
import java.awt.Rectangle;
import java.awt.geom.Rectangle2D;
import java.awt.geom.QuadCurve2D;public class ttt extends JApplet {
// Initialize the applet
public void init() {
// Create pane containing curves
Container content = getContentPane(); // Get the content pane
// Add the pane displaying the curves to the content pane for the applet
content.add(new cPane()); // BorderLayout.CENTER is default position
}
// Class defining a pane on which to draw
class cPane extends JComponent {
// Constructor
public cPane() {
quadCurve = new QuadCurve2D.Double(50,75,80,25,150,75); // Create quadratic curve
rect=new Rectangle2D.Double(50,50,50,50);//Create rectangle
} public void paint(Graphics g) {
Graphics2D g2D = (Graphics2D)g; // Get a 2D device context // Draw the curves and rect
g2D.setPaint(Color.BLUE);
g2D.draw(rect);
g2D.draw(quadCurve);
}
}
// Points for quadratic curve
// Points for cubic curve
QuadCurve2D.Double quadCurve;
Rectangle2D.Double rect; // Quadratic curve
// Cubic curve
// Pane to contain curves
}
import javax.swing.JApplet;
import javax.swing.JComponent;
import java.awt.Color;
import java.awt.Graphics2D;
import java.awt.Container;
import java.awt.Graphics;
import java.awt.Rectangle;
import java.awt.geom.Rectangle2D;
import java.awt.geom.QuadCurve2D;public class ttt extends JApplet {
// Initialize the applet
public void init() {
// Create pane containing curves
Container content = getContentPane(); // Get the content pane
// Add the pane displaying the curves to the content pane for the applet
content.add(new cPane()); // BorderLayout.CENTER is default position
}
// Class defining a pane on which to draw
class cPane extends JComponent {
// Constructor
public cPane() {
quadCurve = new QuadCurve2D.Double(50,75,80,25,150,75); // Create quadratic curve
rect=new Rectangle2D.Double(50,50,50,50);//Create rectangle
} public void paint(Graphics g) {
Graphics2D g2D = (Graphics2D)g; // Get a 2D device context // Draw the curves and rect
g2D.setPaint(Color.BLUE);
g2D.draw(rect);
g2D.draw(quadCurve);
}
}
// Points for quadratic curve
// Points for cubic curve
QuadCurve2D.Double quadCurve;
Rectangle2D.Double rect; // Quadratic curve
// Cubic curve
// Pane to contain curves
}
解决方案 »
免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货