אהלן חברה תשמעו אני מאוד מתחיל ב-JAVA.
אני מנסה כרגע לכתוב CLASS שאחראי על יצירת 12 עיגולים, אחד בתוך השני, במרכז המסך. העיגול הראשון צריך להיות בעל רדיוס של 10 פיקסלים, וכל עיגול נוסף צריך להיות בעל רדיוס גדול יותר ב-10 פיקסלים.הקוד שכתבתי אמור לעשות בדיוק את זה אבל הוא יוצר עיגולים עם רדיוס שונה לגמרי ממה שכתבתי, ובמיקום שונה לגמרי ממה שכתבתי.
מי עוזר לי פה שניה?
הנה הקוד (שני class) :
// class GUIcircles
import java.awt.Graphics;
import javax.swing.JPanel;public class GUIcircles extends JPanel {
public void paintComponent( Graphics g )
{
// Call paintComponent to ensure the panel displays correctly
super.paintComponent( g );
int width = getWidth(), height = getHeight();
for( int radius=10; radius<=120; radius+=10)
g.drawOval( width/2-radius, height/2-radius, width/2+radius, height/2+radius);
}
}
-----------
// class GUIcirclesTest
import javax.swing.JFrame;
public class GUIcirclesTest {
public static void main( String args )
{
// Create a panel that contains our drawing
GUIcircles panel = new GUIcircles();
// Create a new frame to hold the panel
JFrame application = new JFrame();
// Set the frame to exit when it is closed
application.setDefaultCloseOperation( JFrame.EXIT_ON_CLOSE );
application.add( panel ); // Add the panel to the frame
application.setSize( 250, 250); // Set the size of the frame
application.setVisible( true ); // Make the frame visible
}
}
תודה מראש!
