Hi
i'm tryna make a 4 dimensional array that includes colors and changes color when i click any box.
how do i creat the box first using swing and no applet?
please note i dont wanna use button.
thank you
9 1674
just say:
g.drawRect(point.x, point.y, rectWidth, rectHeight);
Hope this helps. I'm not to good with Graphical User Interfaces though.
JosAH 11,448
Recognized Expert MVP
Hi
i'm tryna make a 4 dimensional array that includes colors and changes color when i click any box.
How do you want to display a four dimensional box on a two dimensional screen?
kind regards,
Jos
How do you want to display a four dimensional box on a two dimensional screen?
kind regards,
Jos
i wanna use swing not applet. and i'm using frame and mouseEventListener
JosAH 11,448
Recognized Expert MVP
i wanna use swing not applet. and i'm using frame and mouseEventListener
Huh? erm, and I wanna have a beer not soda. and I'm using strong black tobacco
and Dutch jenever but I fail to see what that has to with four dimensional boxes.
kind regards,
Jos
Hi
i'm tryna make a 4 dimensional array that includes colors and changes color when i click any box.
how do i creat the box first using swing and no applet?
please note i dont wanna use button.
thank you
Are you attempting to store all the RGB color combinations in an array?
Maybe you can just have it in a 2 dimensional array....
eg: box[current color][RGB colors]
regards,
sukatoa
Are you attempting to store all the RGB color combinations in an array?
Maybe you can just have it in a 2 dimensional array....
eg: box[current color][RGB colors]
regards,
sukatoa
i'm tryna create a tictactoe game. but i dont wanna use gdraw . i'm tryna see if i could use jpanel. also i dont wanna use buttons either since i'm gonna use mouse eventlistener. finally the array for the boxes should be 2-dimensional array.
thank you
finally i was able to come up wif this. but the thing is wrote method for checking if the board is full, method for win, and method t clear screen but i dont know how to use mouse listener to connect it.... also i dont know if my logic is right.
please i need help its due tuesday. -
import java.awt.*;
-
import java.awt.event.*;
-
import java.awt.event.MouseEvent;
-
import javax.swing.*;
-
import javax.swing.text.*;
-
import java.text.DecimalFormat;
-
import java.awt.datatransfer.*;
-
-
public class TicTacToeGame extends JFrame implements ActionListener {
-
-
private JPanel ticTacPanel = new JPanel();
-
JLabel tictacpanelDisplay[][] = new JLabel[3][3];
-
ImageIcon xImage = createImageIcon("XImage.gif", "");
-
ImageIcon OImage = createImageIcon("OImage.gif", "");
-
ImageIcon plainImage = createImageIcon("plain.gif", "");
-
char player1 = 'x';
-
char player2 = 'o';
-
char empty = 'p';
-
char field[][] = new char[3][3];
-
-
public TicTacToeGame() {
-
-
-
this.setLayout(new BorderLayout());
-
ticTacPanel.setLayout(new GridLayout(3, 3));
-
ticTacPanel.addMouseListener(new MouseAdapter() {
-
});
-
//create an instance of the menu
-
MenuBar mnuBar = new MenuBar();
-
setMenuBar(mnuBar);
-
-
//construct and populate the File menu
-
Menu mnuFile = new Menu("File", true);
-
mnuBar.add(mnuFile);
-
MenuItem mnuFileNew = new MenuItem("New Game");
-
mnuFile.add(mnuFileNew);
-
MenuItem mnuFileScore = new MenuItem("See Score");
-
mnuFile.add(mnuFileScore);
-
MenuItem mnuFileExit = new MenuItem("Exit");
-
mnuFile.add(mnuFileExit);
-
-
mnuFileNew.addActionListener(this);
-
mnuFileScore.addActionListener(this);
-
mnuFileExit.addActionListener(this);
-
-
mnuFileNew.setActionCommand("New Game");
-
mnuFileScore.setActionCommand("See Score");
-
mnuFileExit.setActionCommand("Exit");
-
-
for (int i = 0; i < 3; i++)
-
{
-
for (int j = 0; j < 3; j++)
-
{
-
tictacpanelDisplay[i][j] = new JLabel(plainImage);
-
ticTacPanel.add(tictacpanelDisplay[i][j]);
-
}
-
}
-
add(ticTacPanel, BorderLayout.CENTER);
-
-
for (int row = 0; row < 3; row++)
-
{
-
for (int column = 0; column < 3; column++)
-
{
-
field[row][column] = empty;
-
System.out.print(field[row][column]);
-
}
-
}
-
-
}
-
-
-
public boolean BoarfIsFull()
-
{
-
for (int i = 0; i < 3; i++)
-
{
-
for (int j = 0; j < 3; j++)
-
{
-
if(field[i][j]== empty)
-
return false;
-
}
-
}
-
return true;
-
-
}
-
-
-
public void clearboard()
-
{
-
for (int i = 0; i < 3; i++)
-
{
-
for (int j = 0; j < 3; j++)
-
{
-
field[i][j] = empty;
-
}
-
}
-
for (int i = 0; i < 3; i++)
-
{
-
for (int j = 0; j < 3; j++)
-
{
-
tictacpanelDisplay[i][j] = new JLabel(plainImage);
-
ticTacPanel.add(tictacpanelDisplay[i][j]);
-
}
-
}
-
-
}
-
-
public boolean BoardIsFull() {
-
for (int i = 0; i < 3; i++) {
-
for (int j = 0; j < 3; j++) {
-
if (field[i][j] == empty) {
-
return false;
-
}
-
}
-
}
-
return true;
-
-
}
-
-
public void playgame(boolean click)
-
{
-
int count=0;
-
for (int i = 0; i < 3; i++)
-
{
-
for (int j = 0; j < 3; j++)
-
{
-
if (click && (!BoardIsFull()) &&(count==0||count==2||count==4||count ==6||count ==8))
-
{
-
-
field[i][j]=player1;
-
}
-
else if(click && (!BoardIsFull()) &&(count==1||count==3||count==5||count ==7))
-
field[i][j] = player2;
-
-
}
-
-
}
-
}
-
-
public boolean isAwin(char token) {
-
for (int i = 0; i < 3; i++) {
-
if ((field[i][0] == token) && (field[i][1] == token) && (field[i][2] == token)) {
-
return true;
-
}
-
}
-
-
for (int j = 0; j < 3; j++) {
-
if ((field[0][j] == token) && (field[1][j] == token) && (field[2][j] == token)) {
-
return true;
-
}
-
}
-
-
if ((field[0][0] == token) && (field[1][1] == token) && (field[2][2] == token)) {
-
return true;
-
}
-
-
if ((field[0][2] == token) && (field[1][1] == token) && (field[2][0] == token)) {
-
return true;
-
}
-
-
return false;
-
}
-
-
// The code is executed when the mouse is pressed
-
public void mousePressed(MouseEvent me) {
-
}
-
-
-
public void actionPerformed(ActionEvent e) {
-
//test for menu item clicks
-
String arg = e.getActionCommand();
-
if (arg == "Exit") {
-
System.exit(0);
-
}
-
}
-
-
/** Returns an ImageIcon, or null if the path was invalid. */
-
protected ImageIcon createImageIcon(String path,
-
String description) {
-
java.net.URL imgURL = getClass().getResource(path);
-
if (imgURL != null) {
-
return new ImageIcon(imgURL, description);
-
} else {
-
System.err.println("Couldn't find file: " + path);
-
return null;
-
}
-
}
-
-
-
public static void main(String args[]) {
-
TicTacToeGame mine = new TicTacToeGame();
-
mine.setBounds(300, 300, 300, 400);
-
mine.setTitle("The Game of Tic Tac Toe");
-
mine.setVisible(true);
-
}
-
}
1.) Don't mix AWT and Swing.
2) For the mouselistener, read Sun's tutorial here.
3.) For the correct logic, write down the correct steps in psuedo code and see if your program conforms to those steps.
1.) Don't mix AWT and Swing.
2) For the mouselistener, read Sun's tutorial here.
3.) For the correct logic, write down the correct steps in psuedo code and see if your program conforms to those steps.
thanks i finally solve is but i dont know was jus happen and i started getting this error
i'm finally done wif ma code but i'm getting this error. do u av any idea wat the prob is? - init:
-
deps-jar:
-
Compiling 1 source file to /Users/ask4soteria/NetBeansProjects/ticTacToeGame/build/classes
-
compile-single:
-
run-single:
-
Exception in thread "main" java.lang.NullPointerException
-
at ticTacToeGame.<init>(ticTacToeGame.java:38)
-
at ticTacToeGame.main(ticTacToeGame.java:208)
-
Java Result: 1
-
BUILD SUCCESSFUL (total time: 2 seconds)
Sign in to post your reply or Sign up for a free account.
Similar topics |
by: Brian |
last post by:
I'm diddlying with a script, and found some behavior I don't understand.
Take this snippet:
for ($i = 0; $i <= count($m); $i++) {
array_shift($m);
reset($m);
}
|
by: Stormkid |
last post by:
Hi Group I'm trying to figure out a way that I can take two (two
dimensional) arrays and avShed and shed, and subtract the matching elements
in shed from avShed I've pasted the arrays blow from a...
|
by: lawrence |
last post by:
I wanted to test xml_parse_into_struct() so I took the example off of
www.php.net and put this code up on a site:
<?php
$simple = <<<END
<item>
|
by: vcardillo |
last post by:
Hello all,
Okay, I am having some troubles. What I am doing here is dealing with
an employee hierarchy that is stored in an array. It looks like this:
$employees = array( "user_id" => array(...
|
by: Sam Collett |
last post by:
How do I remove an item with a specified value from an array?
i.e. array values 1,2,2,5,7,12,15,21
remove 2 from array would return
1,5,7,12,15,21
(12 and 21 are NOT removed, duplicates are...
| |
by: Mike S. Nowostawsky |
last post by:
I tried using the "toUpperCase()" property to change the value of an array
entity to uppercase BUT it tells me that the property is invalid. It seems
that an array is not considered an object when...
|
by: jr |
last post by:
Sorry for this very dumb question, but I've clearly got a long way to go!
Can someone please help me pass an array into a function. Here's a starting
point.
void TheMainFunc()
{
// Body of...
|
by: Leszek |
last post by:
Hi.
Is it possible in javascript to operate on an array without knowing how mamy
elements it has?
What i want to do is sending an array to a script, and this script should
add all values from...
|
by: Jim Carlock |
last post by:
Looking for suggestions on how to handle bad words that might
get passed in through $_GET variables.
My first thoughts included using str_replace() to strip out such
content, but then one ends...
|
by: =?Utf-8?B?U2hhcm9u?= |
last post by:
Hi Gurus,
I need to transfer a jagged array of byte by reference to unmanaged
function, The unmanaged code should changed the values of the array, and when
the unmanaged function returns I need...
|
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers,...
| |
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
|
by: Hystou |
last post by:
Overview:
Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
|
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
|
by: agi2029 |
last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome a new...
|
by: conductexam |
last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
| |
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
|
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
| |