Darren Wilkinson

+ Follow
since Feb 09, 2004
Merit badge: grant badges
For More
Cows and Likes
Total received
In last 30 days
Total given
Total received
Received in last 30 days
Total given
Given in last 30 days
Forums and Threads
Scavenger Hunt
expand Ranch Hand Scavenger Hunt
expand Greenhorn Scavenger Hunt

Recent posts by Darren Wilkinson

Thank you :-)

My question is: why does this work and my code not work. I am having trouble following the reason for this.

Could you explain please.

Thank you.

By the way, this isn't a homework assignment. I am studying towards the J2SE Programmers certification but on my own using Mughal & Rasmussens' Guide to Java Certification... oh and the WhizLabs exam sim.
19 years ago
I have a class ApplicationGui2 (ag) which creates an instance of MyTableModel2 (mtm)

MyTableModel2 has all the methods required to create instances of the class RecordData (rd)

The user uses a modal dialog which instantiates an instance of class NewRecordInput (nri)

nri gathers the user data and then needs to pass this data (stored as a String[]) to the mtm method createNewRecord() which creates a new instance of class RecordData and stores this object in mtm's Vector

What I want to do is; pass a reference to mtm, from ag to nri, so that nri can call mtm.createNewRecord() but my attempts so far produce a NullPointerException

Can anyone help ???
19 years ago
Thank you

This has pointed me in the right direction
19 years ago
Hello :-)

I need to make a modal dialog window that requires the user to input text into 3 textfields

It also needs two buttons

A cancel button (which gets rid of the dialog)

Another button which passes the users text on to the class that created the dialog

Can anyone point me in the right direction on this please

19 years ago

Am I going in the right direction with this?

I think the TableModel is now less tightly linked to the data structure of the data in the TestRecord's.

My next step (assuming the above is right) is to try to make the TestRecord methods setRecordData() and getRecordData() less hard coded by somehow using the class type of the data in a given column determine which TestRecord field to update... but I am not sure if this is the right approach to take.

Any comments are appreciated.

19 years ago
Thanks Ed :-)

re: your comments about the tight link between the TestRecord and the MyTableModel were very enlightening. I was starting to suspect I was doing something wrong whilst I was working but decided to ignore it for now and come back to it when I had something that worked. Your explanation of the need to avoid such tight 'linking' has both confirmed my suspicions and gently nudged me in the right direction for the solution.

I will post my re-design later for you (and any others) to comment on.

Thanks for taking the time to look through my work. It has been a bit of a struggle for me but it is very rewarding to hear from more experienced programmers that I am on the right path.

19 years ago
Hello :-)

I have been busy working on this and I think I am making progress. I just wanted to make sure I am heading in the right direction, so if anyone could spare the time to look through this code and comment upon it, I would be grateful.

The MyTableModel class isn't perfect and neither is the behaviour of the JTable, but after checking that I am heading in the right direction, I will start to sort out those problems.

Code below:

[ September 11, 2004: Message edited by: Darren Wilkinson ]
19 years ago
Thanks Eddie

I will try this and see how I get on

19 years ago
Thank you for the reply Terry

I'm not sure it answers my question though as I know that my TestRecord class could have its data stored in a vector (field) as opposed to being stored in seperate fields and then this vector could be passed and stored in the Table Models vector 'rows' - I have already done this and had it working.

The thing is, this approach appears to me to go against the rule of designing classes and the objects they produce with seperate fields that hold the data of the object.

I have been taught to design the classes as follows (simplified)

// constants

// instance variables

// static variables

// constructor - accepting field values

// getters and setters

// utility methods


// vector

// constructor - accepting 'field' values

// vector methods : add, remove, etc

The vector approach seems to make the TestRecord object only really work for the JTable and TableModel, whereas I thought the point of designing classes was that they can be used (accessed, updated, etc) by other objects using the getters and setters.

How does the current design and functionality of my TestRecord class/object fit into the vector of vector requirements of the JTable constructor?

Thank you.

19 years ago

Can someone help me get a clear understanding of JTables.

I have a TestRecord class which creates TestRecords

I have an application which displays the table and creates some TestRecords

I have a table model...

The table model is a mess because I began with the record data being stored as a vector but (and here is where I am confused) this seemed to make the actual record object itself redundant.

I admit to being a java beginner however I thought that one of the key activities was to abstract things (in this case a record) into classes and objects (in this case a TestRecord class that creates TestRecord objects).

It makes sense to me to store these TestRecord objects into a vector as they are created, but I dont understand how to get the Table Model to use this vector of stored TestRecord objects. I understand how to get and set the fields within each TestRecord object (as the above code shows) and I can see a possible link between the objects data and its display in the table...

Table rows link to objects in vector
Table columns link to fields in object

... but I have no idea how to...

A) make the Table Model handle the display of the object data in this way
B) whether I am wasting my time as Table Models (and JTables) simply do not work this way

I think there is something about JTables, Table Models and (in this case) the TestRecord objects they display, that I have not grasped and if someone could help clear this up for me then I would be really grateful.

Thank you.

19 years ago

I need help on how to approach the solution to the problem, rather than actual code.

In my assignment I have a class called VehicleRecord which has two fields: String registrationDate and String expiryDate.

This class must include validation methods (for validating the data supplied by the user for the fields) and I have to use the following method signature; .

The above validation method has to be used for validating two different dates, registrationDate and expiryDate (both with the same validation parameters : 4 digits (MMDD) date range = 0181 -> 1220) after the user has supplied them but [ITALIC]before[/ITALIC] the supplied data is passed to the respective field.

I have coded the actual validation and it works fine.

The problem I have is that the method signature does not allow for any returned value. Due to this, I do not see a way that the validation method can tell which date it is validating, so the following cannot happen...

... because which fields date is the method validating.

I am restricted by the terms of the assignment but if I were not, I would go about it as follows (in fact I have and this approach works fine).

... but I cant use the above approach.

Can anyone suggest a way to approach this problem?

Thank you
[ July 22, 2004: Message edited by: Darren Wilkinson ]
19 years ago
thanks don

the change worked but i dont understand why ?

19 years ago