Dave Morley

Ranch Hand
+ Follow
since Jul 23, 2004
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 Dave Morley

Thank you Manuel

It did work.

Regards
Dave Morley

16 years ago
Thank you Manuel

Will try it and let you know

Regards
Dave Morley
16 years ago
I have a question:

I am enlivenning two buttons .
The code follows:

public void actionPerformed(ActionEvent e)
{
String arg = e.getActionCommand();

if (arg == "Go !"); // check to see if the go button has been pressed
{
startData = Integer.parseInt(startField.getText());// must parse it.
stopData = Integer.parseInt(stopField.getText());
stepData = Integer.parseInt(stepField.getText());

for(int i = 0; i <= 15; i++)
checkArray[i].setBackground(Color.MAGENTA);


}

if (arg == "Clear");
{
startField.setText("");
stopField.setText("");
stepField.setText("");
}


the question is this, the program compiles and runs except when you press the Go button the code for the clear button is also carried out. Why is this???

Any help is appreciated.

Regards
Dave Morley
16 years ago
Miguel

Not at all, just need to free up the brain cells.

Regards
Dave
16 years ago
Thanks Again Miguel

You are of course right.

I am going to leave it for a while, and let my brain simmer down.


Regards
Dave Morley

PS thank you for all the help....
16 years ago
Good Day Miguel

As I am on the other side of the world , I didn't get your post till now.

I have used the import statements as you suggested.

I will place the code I have written so far, if it is too much trouble I understand. I am incredibly frustrated and confused at this moment, and I am really thinking of leaving it.

Thanks Anyway

Regards
Dave Morley

/*
For test 3
Project 2 in the lab, page j5.51
Programmer: Dave Morley
Date: June 5th 2005
Program Name: Checkerboard
*/

import java.awt.*;
import java.awt.event.*;

public class Checkerboard extends Frame implements ActionListener
{
public TextField checkArray[];
public Panel gridBlock;
public TextField startField;
public TextField stopField;
public TextField stepField;
public Label startLabel;
public Label stopLabel;
public Label stepLabel;
public int startData;
public int stopData;
public int stepData;
public Button clearButton;
public Button goButton;
public Panel functionPanel;

public Checkerboard()
{
checkArray = new TextField[16];
gridBlock = new Panel();
startField = new TextField(20);
startLabel = new Label("Start");
stopField = new TextField(20);
stopLabel = new Label("Stop");
stepField = new TextField(20);
stepLabel = new Label("Step");
startData = 0;
stopData = 0;
stepData = 0;
clearButton = new Button("Clear !");
goButton = new Button("Go !");
functionPanel = new Panel();

// Set Frame Layout Manager
setLayout(new BorderLayout());
gridBlock.setLayout(new GridLayout(4,4,10,10)); // sets the textfiels 4x4 with gaps of 10 pixels each
functionPanel.setLayout(new GridLayout(3,3,10,10));// sets the rest of the components in the panel

// create textfields
for(int i = 0; i <=15; i++)
checkArray[i] = new TextField(String.valueOf(i));


// add fields to the panel
for(int i = 0; i <= 3; i++)
gridBlock.add(checkArray[i]);
for(int i = 4; i <= 7; i++)
gridBlock.add(checkArray[i]);
for(int i = 8; i <= 11; i++)
gridBlock.add(checkArray[i]);
for(int i = 12; i <= 15; i++)
gridBlock.add(checkArray[i]);





functionPanel.add(startField);
functionPanel.add(stopField);
functionPanel.add(stepField);
functionPanel.add(startLabel);
functionPanel.add(stopLabel);
functionPanel.add(stepLabel);
functionPanel.add(clearButton);
clearButton.addActionListener(this);
functionPanel.add(goButton);
goButton.addActionListener(this);

add(gridBlock, BorderLayout.NORTH);
add(functionPanel, BorderLayout.SOUTH);


addWindowListener(
new WindowAdapter()
{
public void windowClosing(WindowEvent e)
{
System.exit(0);
}
}

);


}

public void actionPerformed(ActionEvent e)
{
String arg = e.getActionCommand();
if(arg == "Go !")// check to see if the go button has been pressed
}
}


I haven't finished the rest of the coding but it seems to be getting more and more complicated or the book is not making itself very clear.

16 years ago
Thanks Again Miguel

I have tried that I get an error message cannot resolve symbol, method setEditable(boolean)

Regards
Dave
16 years ago
Thank you Miguel

For the very swift reply, however I have to use the method and coding as it stands on the page as I wrote it. I didn't quite get your code. Would it be possible for you to type it in , using the code I wrote.

I am very new to Java and Just trying to understand.

Thanks Again
Dave Morley
16 years ago
Good Day

I really need some help with some coding I am doing, as I try vainly to make my way through a correspondence course.

The text book states the following:

write a loop to traverse the array and set each of the 16 textfields in that array so they cannot be edited. Within the same loop set each textfield's text to match the loop increment.

Then they suggest you use the setEditable and setText methods.

what follows is what I coded.:::


// create textfields
for(int i = 0; i <=15; i++)
checkArray[i] = new TextField(String.valueOf(i));

// add fields to the panel
for(int i = 0; i <= 3; i++)
gridBlock.add(checkArray[i]);
for(int i = 4; i <= 7; i++)
gridBlock.add(checkArray[i]);
for(int i = 8; i <= 11; i++)
gridBlock.add(checkArray[i]);
for(int i = 12; i <= 15; i++)
gridBlock.add(checkArray[i]);
checkArray.setEditable(false); // this last line is really where I come unstuck.

I know this is wrong....

Any help would really be greatly appreciated

Many Thanks
Dave Morley




16 years ago
Thank you Manuel

I get it!!!

Regards
Dave Morley
16 years ago
Good Day

I am currently coding a project for a course, in the project there are an Array of textfields. The only thng is the textfields must be square.

When you declare the textfield you can declare the length but can you also declare the vertical height:

This is how I think it should be coded:

public class Checkerboard extends frame implements ActionListener
{

public TextField checkArray[16] // decalres 16 elements in the array.

and down to the following


public checkerboard()
{
checkArray = new TextField(20,20);// declares the height as 20 and the length as 20???

is this correct???


Any help is greatly appreciated.

Regards
Dave Morley

16 years ago
Thanks Guys

I've Got it.

It's funny because the course clearly states to make all the varaibles public, and I can't understand why.

But I understand now.

many Thanks
Dave Morley
16 years ago
Thanks for the swift reply Henry

So in essence what you are saying is that you should keep the variables as Public???

Regards
Dave Morley
16 years ago
Good Day

I am currently doing a correspondence course and I am wading through some exercises. If someone could just explain the following to me.

example code:


public class Calculator extends Fram implements ActionListener
{
private Button keysArray[];
private TextField lcdField;
etc...........

public Calculator()
{


The question is this : why would you sometimes decalre the variables i.e. lcdField as private and sometimes declare it as public??? What do you achieve by doing it either private or public.

I just can't seem to get my head around this, I understand that it has to do with the scope of the variable, but in real terms what does it achieve once the program is compiled and running???

I hope I have made it clear enough.

many Thanks
Dave Morley


16 years ago
I am new to java programming and recently switched over to a Mac, I used to use JCreator on the windows machine but would like to use X Code. I find it very complicated. If any one using x code could give me some pointers or answer my basic questions that would be great otherwise I am looking for a simple IDE for MAC OS X Tiger.

Any help is greatly appreciated.

Many Thanks
Dave Morley
16 years ago