-2
我將如何將它變成兩個參數的構造函數,可用於指定繪製對象的位置和/或縮放對象。這用於Jframe圖形項目。如果它有幫助,我也可以發佈Jframe。兩個參數構造函數指定對象應該在哪裏繪製?
import java.awt.Color;
import java.awt.Graphics;
import java.awt.Graphics2D;
import java.awt.Rectangle;
import java.awt.geom.Ellipse2D;
import java.awt.geom.Line2D;
import javax.swing.JComponent;
import java.awt.GradientPaint;
/*
component that draws the concert speakers
*/
public class ConcertSpeaker extends JComponent
{
public void paintComponent(Graphics g)
{
super.paintComponent(g);
// Recover Graphics2D
Graphics2D g2 = (Graphics2D) g;
// Speaker base
g2.setColor(Color.BLACK);
Rectangle base = new Rectangle (300, 400, 50, 100);
g2.fill(base);
// Speakers circles gray top
g2.setColor(Color.DARK_GRAY);
Ellipse2D.Double speakerTop = new Ellipse2D.Double(310, 410, 30, 30);
g2.fill(speakerTop);
//speakers circles black top
g2.setColor(Color.BLACK);
Ellipse2D.Double speakerTop1 = new Ellipse2D.Double(315, 415, 20, 20);
g2.fill(speakerTop1);
// Speakers circles gray bottom
g2.setColor(Color.DARK_GRAY);
Ellipse2D.Double speakerBottom = new Ellipse2D.Double(310, 450, 30, 30);
g2.fill(speakerBottom);
//speakers circles black bottom
g2.setColor(Color.BLACK);
Ellipse2D.Double speakerBottom1 = new Ellipse2D.Double(315, 455, 20, 20);
g2.fill(speakerBottom1);
}
}
你認爲這可以做什麼?有任何想法嗎?有關構造函數的兩個參數是什麼的想法?任何嘗試製作一個? –
代碼中沒有縮放比例。 – hasan83