aspose file tools*
The moose likes Beginning Java and the fly likes TextField and setEditable Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Soft Skills this week in the Jobs Discussion forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "TextField and setEditable" Watch "TextField and setEditable" New topic
Author

TextField and setEditable

Dave Morley
Ranch Hand

Joined: Jul 23, 2004
Posts: 38
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




miguel lisboa
Ranch Hand

Joined: Feb 08, 2004
Posts: 1281

i get a warning:
TestS.java:5: warning: [serial] serializable class S has no definition of serialVersionUID
class S extends JFrame {
^
1 warning

but dont know how to get rid of it...
[ June 11, 2005: Message edited by: miguel lisboa ]

java amateur
Dave Morley
Ranch Hand

Joined: Jul 23, 2004
Posts: 38
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
miguel lisboa
Ranch Hand

Joined: Feb 08, 2004
Posts: 1281
try moving to the line after

i hope this will give you an idea:

[ June 11, 2005: Message edited by: miguel lisboa ]
Dave Morley
Ranch Hand

Joined: Jul 23, 2004
Posts: 38
Thanks Again Miguel

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

Regards
Dave
miguel lisboa
Ranch Hand

Joined: Feb 08, 2004
Posts: 1281
i edited my post, posting the full running code; remember to use the import statements
Dave Morley
Ranch Hand

Joined: Jul 23, 2004
Posts: 38
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.

miguel lisboa
Ranch Hand

Joined: Feb 08, 2004
Posts: 1281
hi, Dave

javaranch is a wonderful community, so be confident because you are at the right place

dont discourage, because for sure you'll get it

me too, i'm a self taugh java student, (so i'm not an expert at all), but i'll try to give you a hand

let me start by this: pls use UBB tags to format your code, so it gets more readable

it looks like your exercise is driving you crazy: a good aproach to it is identifying and spliting the various aspects involved in its resolution

you have loops, arrays, interfaces (ActionListener), swing (and in swing you have widgets, layout managers, events and more), and so on

in my opinion that's too much.

i'd start from somewhere (a piece a time), for example: can you properly initialize an array?

Are you able to iterate over an array?

do you understand the swing event model, or, at least, do you understand how one can make some action happen when you click a button?

Do you have any idea about layout and layout managers?

as you might imagine, i could go on with this list.

so, i repeat, dont bother with building the whole app right now, at once, but instead focus on single parts of it - mastering an array, a loop, etc.

feel free to point out from where you wanna begin

also, if i were you i'd write a bit of code and then test it at once: this way you'd be sure that what you had just writen was functioning properly

the following is a mere example of how to create a class and then quickly test it (note that i'm not worried at all about proper encapsulation or with access modifiers)

miguel lisboa
Ranch Hand

Joined: Feb 08, 2004
Posts: 1281
here's a more sofisticated version:
another advantage of having tests is that you can alter your class and then understand that was new added code that broke it, because before tests ran ok
Dave Morley
Ranch Hand

Joined: Jul 23, 2004
Posts: 38
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....
miguel lisboa
Ranch Hand

Joined: Feb 08, 2004
Posts: 1281
you'r wellcome

just hope i didnt scare you
Dave Morley
Ranch Hand

Joined: Jul 23, 2004
Posts: 38
Miguel

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

Regards
Dave
Timmy Marks
Ranch Hand

Joined: Dec 01, 2003
Posts: 226
With regards to your first and third posts, you are trying to call setEditable on an ARRAY of TextFields instead of each TextField individually. The line disappears in later posts, but you should change to
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: TextField and setEditable