Declan Dee

Greenhorn
+ Follow
since May 04, 2010
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 Declan Dee

Hi,

Of course it can be made even simpler:



However there is one BIG problem. When using this you can enter a minus number and it will be accepted
11 years ago
Hi,

I was asked during my course to set up a JTextfield to make sure that only integers are accepted. I spent ages on several forums looking for a solution but I could not find anything.

Luckily I manged to find a solution, but unfortunatly I am not 100% what I have typed and I would love to know excatly what it is. Its works perfectly by the way.

You can type only integers and nothing else



Any explination? - Thanks in advance

Good to finally have a solution!

You have no idea how long I was looking for this!
11 years ago
Just getting back. The code is actuall this:



This gives you the value of what is currently selected in the Combobox. That was the problem all along.

The rest

11 years ago
Hi Paul,

I am sure I can get the value of the textField but using the getText method, I am ok there.

Is the compare part that I am not sure about

Declan D
Hi Gents,

Does anyone out there please provide some help or a link to where I can find a way to compare an integer that I have typed into a JTextfield against a field in a MySQL database?

For example if I type 4 into the textbox, I can compare this value to the database field and take action accordingly

I can find absolutly nothing on the net about this.

Any help or links is greatly appreciated.

I need to do the same for strings as well. I just need some links/examples to get me started

Declan

Hi Gents,

In desperate need of help

I need to do the following

I need to select from a range of values (via a regular resultset) and show this information in a Drop Down List - I succeded

Now I need to show in a JList ONLY values that are linked to what is currently selected in the combox, that are coming out of a MySQL database and I am already over 6 hours doing it

So basically when I select an option for example 'dance' or 'circus' in the drop down list. I need to get ONLY what is linked with 'Circus' in the MySQL database (via the code I have shown)

The MySQL code is fine. Currently the Prep statement is 'prepStatement.setString (1,"Dans");' This means that no matter what I select in the main drop down list, I will only get what is linked 'Dans' and not the other genres.

I tried with this but to no avail:


Here is the code, showing the two methods. The first method works fine when called. It makes a dropdown list with just Genres.

The second however...........



I would be very grateful if someone could help

Declan D
11 years ago
Hi,

For anyone that is interested, this is the complete solution:

[b]The program in ONE COMPLETE CLASS[/b]



Now the program in two seperate classes. One class for the design of the GUI and one for the connection to the database



Now the class for the database connection

I have solved my problem

At the start I had two questions:

1 - "How do I make it that the column information in the DB matches the textfield information? How do I make it that the column ‘name’ in my MySQL database shows up in the name texfield in my GUI"

That I solved with the method that I mentioned above.

2 - "How do I connect the two together? "

This was where I was having all my issues. In the end (I guess I am still a beginner) it was very simple and I feel very stupid.

But the solution was to call that method (the one that I have typed above, its called 'getDatabaseValues') from the console, in the main method and thats a bingo!



I need to check a few small things with my instructor and I will post the entire code tomorrow





Jelle Klap wrote:Hint: the comment "Should not be void???!" could be right on the money.
Unless you're bound to that interface?



Im sorry I dont understand

I am not bound to it
Hi,

I have done some more research and I found something that might be useful but I am not sure where it is supposed to go.

I know I have to bring in the value of the column from the MySQL database. When I usually want to bring in something to a textfield, I use this command:



So now I have created this code:



The only problem I have now is, where do I put this?

I was thinking of making a method called:



And putting in all the colums and corresponding textfields that I need. The problem is that if I put it into the GUI class, it cannot see the resultset variable...
and If I put it in the database class it wont see the textfield variables.

But at least a step forward!

Moguluri Ravi Kiran wrote:

Declan Dee wrote:
How do I make it that the column ‘name’ in my MySQL database shows up in the name texfield in my GUI.



I think ResultSetMetaData serves you.



Hi Kiran,

I have used this before. I thought it was just for getting what types of data where in columns (amoungst other things)
Greetings,

I am hoping someone can help me. I have trawled through the internet for hours and hours now trying to find a solution to this simple problem and for some reason I cannot find anything that can remotely help. So what I am I trying to do I hear you ask? well its simple:

*****Display information from a database in a custom made GUI *****

I have already created one class that has all the elements of the GUI and a second class that has all the database elements.

When I run the database class (using the instance in the GUI class) all information is shown on screen, exactly in the order that I have it instructed to. This is perfect.

When I run my GUI class, my GUI appears, all my text buttons and labels are fine. This is also perfect.

However my question is this, and this is what I have been looking for for ages now: How do I connect the two together?

How do I make it that the column information in the DB matches the textfield information? How do I make it that the column ‘name’ in my MySQL database shows up in the name texfield in my GUI.

For the rest of the project I am sorted. I know how to create ActionListeners to add/remove, go back/forth etc, its just this little part is holding the whole thing up.

I will continue my research

The code is shown below, if you need it. Just keep an eye out for the Dutch

Again as always, your help is greatly appreciated

Declan

The GUI Class



The Database Class

Campbell Ritchie wrote:Why are you trying to control creation from inside the constructor? Is it because you have a class invariant that the values must be in a particular range? If so, I think the IllegalArgumentException technique looks better to me.



Yes indeed. First my thanks to Dave for his help. Thanks Dave, Greatly appreciated.

so, yes, I have to make sure that no object (in this case a employee) can be created with a date less than the 1st of January 1977. If I create an employee with a start date that is less than that, there has to be an error.

You see the company was set up on that date so it was impossible that a start date for an employee could have been before that. Hence the control.

Thank you very much indeed

11 years ago
It does indeed Sean - Thank You!

Now I have to find a way of taking this (now working method) and run it against objects in a Treeset

11 years ago
Hi Gents,

This is something that I am stuck on.

I am creating a constructor that can take in variables of the following type:

public Date(int day, int month, int year) {
this.day = day;
this.month = month;
this.year = year;

I need to change so that if an object is created of type date and this date is before a certain date e.g. 12/01/1977 that a message is generated.

So basically what I am saying is that I want to use the constructor to control what object can be created.

The second thing that I am looking for is to make sure that a date entered must be between two specific dates and not outside This is my pathetic attempt so far:




For the life of me I have absolutely no idea on how I can achieve these, or where even to start.

Can someone be so kind as to shed some light on these please?

Declan
11 years ago