Jay Kamdar

Greenhorn
+ Follow
since Sep 02, 2005
Cows and Likes
Cows
Total received
0
In last 30 days
0
Total given
0
Likes
Total received
0
Received in last 30 days
0
Total given
0
Given in last 30 days
0
Forums and Threads
Scavenger Hunt
expand Ranch Hand Scavenger Hunt
expand Greenhorn Scavenger Hunt

Recent posts by Jay Kamdar

How do you traverse a binary search tree with a loop?
15 years ago
How would you make an High Score list that changes when a player wins a game of Minesweeper? It has to decide if it is beginner, intermediate, or expert.
15 years ago
How can you check if the user pressed the left and right click at the same time? I know how to do left or right click separately.
15 years ago
I need to display numbers when the user clicks a Jbutton depending on the variable and I need a colored Icon but the button is enabled. Is this possible?

If not, how can i set text to the Jbutton, it is too big and only shows three dots.
15 years ago
I am making minesweeper and the buttons for it are not working correctly because its mouseclicked event or any mouse events are not working.

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

public class BoxButton extends JButton implements MouseListener
{
private int row;
private int col;
private Environment env;

public BoxButton()
{
throw new IllegalArgumentException(�Needs to be in an array with row and height� ;
}

public BoxButton(int row, int col, Environment env)
{
this.row = row;
this.col = col;
this.env = env;
setEnabled(true);

}


public void mouseClicked(MouseEvent event)
{
Box box = (Box) env.objectAt(new Location(row,col));
if(event.getButton() == event.BUTTON2)
{
box.setFlag(!box.hasFlag());

}

if(event.getButton() == event.BUTTON1)
{
this.setEnabled(false);
System.out.println(�Mouse Listener works� ;
setSelected(false);
}
if(box.hasFlag())
{
this.setIcon(new ImageIcon(�flag.jpg� );
}
else
{
this.setIcon(null);
}
this.repaint();
}

public void mouseReleased(MouseEvent event)
{
if(event.getButton() == event.BUTTON1)
{
this.setEnabled(false);
this.setBorderPainted(false);
this.setVisible(false);
}
}

public void mousePressed(MouseEvent event)
{

}


public void mouseEntered(MouseEvent event)
{

}


public void mouseExited(MouseEvent event)
{

}
}
if you can�t figure it out from that, i can send you the rest of the files.

http://www.megaupload.com/?d=JK1WRXML

Thanks in advance.
16 years ago
I am making minesweeper and i need to know how to flatten the buttons using JButton.
16 years ago
I can’t get the Jbutton to display. I am making minesweeper.

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

public class MinePanel extends JPanel
{
private JMenuBar menuBar;
private JButton[][] boxes;
public final int boxSize = 20;



public MinePanel()
{
initialize(10,10,10);
}

public MinePanel(int height, int width, int mines)
{
initialize(height, width, mines);
}

private void initialize(int height, int width, int numOfmines)
{
setPreferredSize(new Dimension(25 * width ,25 * height));
setLayout(null);

menuBar = new JMenuBar();
JMenu menuGame = new JMenu(“Game” ;
JMenuItem menuItemNewGame = new JMenuItem(“New Game” ;
JMenuItem menuItemExit = new JMenuItem(“Exit” ;
JMenu menuHelp = new JMenu(“Help” ;
JMenuItem menuItemHelpContents = new JMenuItem(“Help Contents” ;
TimePlayed label = new TimePlayed();
MinesLeft mineLabel = new MinesLeft();

boxes = buttons(10,10);

menuItemExit.addActionListener(new ExitAction());
menuItemNewGame.addActionListener(new ResetListener());

menuGame.add(menuItemNewGame);
menuGame.add(menuItemExit);
menuHelp.add(menuItemHelpContents);

menuBar.add(menuGame);
menuBar.add(menuHelp);

menuBar.setBounds(0,0,(int) getPreferredSize().getWidth(),(int) getPreferredSize().getHeight() / 20);

label.setBounds((int) getPreferredSize().getWidth() * 3 / 40,(int) getPreferredSize().getHeight() * 5 / 80,
(int) getPreferredSize().getWidth() / 4,(int) getPreferredSize().getHeight() * 3 / 40);

mineLabel.setBounds((int) getPreferredSize().getWidth() * 27 / 40,(int) getPreferredSize().getHeight() * 5 / 80,
(int) getPreferredSize().getWidth() / 4,(int) getPreferredSize().getHeight() * 3 / 40);

add(label);
add(mineLabel);
add(menuBar);
}

private JButton[][] buttons(int row, int col)
{
int height = (int) getPreferredSize().getHeight() * 7 / 40;
int width = (int) getPreferredSize().getWidth();

boxes = new JButton[row][col];

for(int i = 0; i < boxes.length; i++)
{
for(int j = 0; j < boxes[0].length; j++)
{
boxes[i][j] = new JButton();
boxes[i][j].setBounds(width + boxSize * j,height + boxSize * i ,boxSize, boxSize);
boxes[i][j].setEnabled(true);
boxes[i][j].setBorder(new LineBorder(Color.blue, 1));
add(boxes[i][j]);
}
}
return boxes;
}

private class ExitAction extends AbstractAction
{
public void actionPerformed(ActionEvent e)
{
System.exit(0);
}
}

private class ResetListener extends AbstractAction
{
public void actionPerformed(ActionEvent e)
{

}
}
}
16 years ago
Should you use the JFrame's setJmenuBar method to a menu or the JFrame's getContentPane method and use the Container got that returned method add to menu if you are trying to get the menu to the top of the screen like normal toobars and menus?

How would you do the second one, I don't know how to position the menu in a Container?
16 years ago
Let say you are in one class and you want to find out when another method is called and you want to call one of your methods right after.

Is that possible, can you use a thread to do that?
16 years ago
I am trying to make one spot in an array, immutable and the rest normal but i can't create another array.

I am trying to make a fish in the marine biology case study that will always stay in the environment's array and can never be deleted.
16 years ago
How can you change a number from its numerical value to string reprensation?
Ex 5 to "five"
78 to "seventy eight"
16 years ago
How would you make a loop that runs once every second, minute, and hour?
16 years ago
Thank You, Our teacher was not very specific about the extra arrays. All he said that don't use arraycopy.
16 years ago
I am trying to do mergesort without breaking the orginal in pieces and i can't understand what is wrong.

[ December 04, 2005: Message edited by: Jim Yingst ]
16 years ago
I have this program to code but my output is only different because some of the lines have too little spaces before them.

Here is the problem
A Fractal Pattern
Examine this pattern of asterisks and blanks, and write a recursive function that can generate patterns such as this:


With recursive thinking, the function needs only seven or eight lines of code (including two recursive calls). Your prototype should look like this:

String pattern(String outs, int n, int i);
// Precondition: n is a power of 2 greater than zero.
// Postcondition: A pattern based on the above example has been
// printed to the String outs. The longest line of the pattern has
// n stars beginning in column i of the output. For example,
// The above pattern is produced by the call pattern(out, 8, 0).

Hints: You do not need to check the precondition. Think about how the pattern is a fractal. Can you find two smaller versions of the pattern within the large pattern? Here is some code that may be useful within your function:

// A loop to print exactly i spaces:
for (k = 0; k < i; k++) outs += ' ';

// A loop to print n asterisks, each one followed by a space:
for (k = 0; k < n; k++) outs += "* ";


Here is my code


My output looks like this

[ November 25, 2005: Message edited by: Marilyn de Queiroz ]
16 years ago