Hi
I am trying to make a program that prints a snooker board on the screen.
I am trying to print the different parts on top of each other.
So far all I am able to do is print the background.
when i try to print the cloth on top of that only the cloth prints.
Here is the code:
package table;
import javax.swing.*;
import java.awt.*;
public class Table_drawer
{
public static void main(String[] args)
{
JFrame frame = new JFrame();
frame.setLayout(new FlowLayout());
frame.setSize(800, 450);
frame.setTitle("Snooker");
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
Background background = new Background();
Cloth cloth = new Cloth();
frame.add(background);
frame.add(cloth);
frame.setVisible(true);
}
}
Here is the Background class;
package table;
import java.awt.*;
import javax.swing.JComponent;
public class Background extends JComponent
{
public void paint(Graphics g)
{
Color cloth = new Color(50,20,0);
// Recover Graphics2D
Graphics2D g2 = (Graphics2D) g;
g2.setColor(cloth);
// Construct a rectangle and draw it
Rectangle box = new Rectangle(800,450);
g2.fill(box);
}
}
And the Cloth class:
package table;
import java.awt.*;
import javax.swing.JComponent;
public class Cloth extends JComponent
{
public void paint(Graphics g)
{
Color cloth = new Color(50,150,50);
// Recover Graphics2D
Graphics2D g2 = (Graphics2D) g;
g2.setColor(cloth);
// Construct a rectangle and draw it
Rectangle box = new Rectangle(44,22,712,357);
g2.fill(box);
}
}
Thanks in advance.