code

import java.awt.*;
import javax.swing.*;
import java.awt.geom.*;

public class QuestionA extends JApplet 
{ 
public void init() 
{
PanelLukis panel = new PanelLukis(this);
getContentPane().add(panel);
}
}

class PanelLukis extends JPanel
{
private int x_axis, y_axis;
private int squareWidth, squareHeight;
private int x, y, coordinateX, coordinateY, squareNo;

JApplet app;
public PanelLukis(JApplet a) 
{
app = a;
app.setBackground(Color.white);
}

public void paintComponent(Graphics g)
{
x_axis = getWidth();
y_axis = getHeight();
squareWidth = 50;
squareHeight = 50;

Graphics2D graphic2d = (Graphics2D) g;
y = (y_axis -300) / 2;

for(int j = 0; j <= 5; j++)
{
x = (x_axis -300) / 2;
for(int i = 0; i <= 5; i++)
{
Rectangle2D.Double square = new Rectangle2D.Double(x, y, squareWidth, squareHeight);
graphic2d.draw(square);
x += squareWidth;
}
y += squareHeight;
}
}
}

this is the board for the game

import java.awt.*;
import javax.swing.*;

public class blue extends JApplet
{
public void paint (Graphics g)

{
g.setColor(Color.blue);
g.fillOval(0,0,40,40);

}
}

this is the blue ball

import java.awt.*;
import javax.swing.*;

public class yellow extends JApplet
{
public void paint (Graphics g)

{
g.setColor(Color.yellow);
g.fillOval(0,0,40,40);

}
}

this is yellow ball

import java.awt.*;
import javax.swing.*;

public class red extends JApplet
{
public void paint (Graphics g)

{
g.setColor(Color.red);
g.fillOval(0,0,40,40);

}
}

this is red ball
i need help in this programming..
i want to make this game similar like this http://www.geekin.de/data/public/umsetzung/five_or_more/ or like tic-tac-toe..
anyone can help me..
this is my final year project.
i don't know how to integrate the ball and the board to appear in randomly. (",)

1. Why every class extends JApplet?
2. Why do you not use a class "Ball" with size and colour instead of creating every ball as new object?

Random generation:
A) generate number between 0-80 inclusive for total squares on board
B) generate number between 0-8 inclusive, one for row and one for column

thanks peter..
you give me new idea..
:)

for your question,
1) i use each of the ball in the separated way, because i still in learning to get use in java enviroment, the only way that i can make the ball is make it in the separated way..
:)
thanks a lot..

now, i'm trying to work for it algorithm..
:)

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.