我似乎無法弄清楚爲什麼我的同心圓不排列。我的循環對我來說看起來是正確的,測量結果是正確的,但由於某種原因,最後幾圈是偏離中心的。這是我遇到的第一個問題。第二個問題是,我似乎無法在每個方塊中打印同心圓。再次,我似乎無法在我的邏輯中發現任何問題,但顯然存在一個問題。任何幫助都會很棒。圖形漆組件和迴路故障
這應該是最終產品
*現在,這是我的源代碼 - ExampleGUI.java *
import javax.swing.*;
public class ExampleGUI {
public static void main(String args []) {
JFrame frame = new JFrame("Example Graphics");
ExamplePanel panel = new ExamplePanel();
frame.getContentPane().add(panel);
frame.setDefaultCloseOperation(3);
frame.pack();
frame.setVisible(true);
}
}
* ExamplePanel.java *
import java.awt.*;
import javax.swing.*;
public class ExamplePanel extends JPanel{
public ExamplePanel() {
setPreferredSize(new Dimension (600, 600));
}
public void paintComponent(Graphics g) {
super.paintComponent(g);
int x = 0;
int x2 = 5;
int y = 500;
int y2 = 505;
int w = 100;
int w2 = 90;
int h = 100;
int h2 = 90;
int i, j, k;
for(j = 1; j < 7; j++) {
x = 0;
x2 = x + 5;
for(i = 1; i < 7; i++) {
if ((i + j) % 2 == 0) {
g.setColor(Color.white);
} else {
g.setColor(Color.yellow);
}
g.fillRect(x, y, w, h);
g.setColor(Color.black);
g.drawRect(x, y, w, h);
g.setColor(Color.green);
g.fillOval(x2, y2, w2, h2);
for(k = 1; k < 7; k++) {
g.setColor(Color.black);
g.drawOval(x2, y2, w2, h2);
x2 = x2 + 5;
y2 = y2 + 5;
w2 = w2 - 10;
h2 = h2 - 10;
}
x = x + w;
x2 = x2 + w2 + 10;
}
x = x + w;
y = y - h;
y2 = (y2 - h2) - 10;
}
}
}
*這是我的程序在運行時的樣子。它看起來並不像其他圖片出於某種原因*
我想幫助你,但是通過盯着圖形來描述。其實我無法從圖表中看出你在說什麼。 – MeBigFatGuy 2014-11-25 02:05:23
所以...你的問題是什麼?簡單地說我的代碼不起作用不會幫助人們瞭解您的問題並提供幫助 – 2014-11-25 02:07:08
該圖像是我想要的樣子,但我的代碼看起來不像這樣 - 它非常接近。 – KangarooRIOT 2014-11-25 02:07:20