Hi
I'm new to Java & am working through the Dietels' "Java How to Program" and am stuck on exercise 6.1 (I'm not doing a formal course)
I managed to get the bulls eye required but I can't seem to get my constructor to 'work' - one of the circles should be red the colours when I create a DrawBullseye object but it defaults to black.
Any suggestions gratefully appreciated
[highlight = JAVA]
import java.util.Random;
import javax.swing.JFrame;
public class DrawSmileyTest
{
public static void main(String[] args)
{
DrawBullseye target = new DrawBullseye(200,0,0);
JFrame frame = new JFrame();
frame.setDefaultCloseOperation( JFrame.EXIT_ON_CLOSE);
frame.add(target);
frame.setSize( 250,250);
frame.setVisible(true);
}
}
[/highlight]
[highlight = Java]
import java.awt.Color;
import java.awt.Graphics;
import javax.swing.JPanel;
import java.util.Random;
public class DrawBullseye extends JPanel
{
int counter = 0;
int red1;
int green1;
int blue1;
int red2 = 99;
int green2 = 182;
int blue2 = 222;
public DrawBullseye(int r1, int g1, int b1)
{
red1 = r1;
green1 = g1;
blue1 = b1;
}
Color firstColour = new Color(red1, green1, blue1);
Color secondColour = new Color (red2, green2, blue2);
public void paintComponent (Graphics g)
{
super.paintComponent(g);
for (int l = 1; l<=10; l++)
{
int step = 10;
g.setColor(firstColour);
g.fillOval( 10 + (counter*step), 10 + (counter*step), 200 - (counter*2*step), 200 - (counter*2*step) );
g.setColor(secondColour);
g.fillOval ( 15 + (counter*step), 15 + (counter*step), 200 - (counter*2*step) - 10, 200 - (counter*2*step) - 10 );
counter++;
}
}
}
[/highlight]