If this is your first visit, be sure to
check out the FAQ by clicking the
link above. You may have to register
before you can post: click the register link above to proceed. To start viewing messages,
select the forum that you want to visit from the selection below.

then create a class called btnCancel, which has a method called actionPerfomed

example

class btnCancel implements ActionListener
{
public void actionPerfomed(ActionEvent e)
{
System.exit(0); //This will kill ur app
frame.dispose(); // this will dispose of ur frame, but u need to declare the frame in ur main class and not in the method.
}
}

we have a few examples at www.java.codeyourself.com, which you can download and compile, you may find some thing usefull. But plz show ur support by registering. If you need any more help let me know, or any one else here

You should consider changing your code to Object Oriented code instead on using static methods. Also, I notice that your variable are all declared in methods which means their scope only applies within those methods. Perhaps this might work: (i cannot compile code as i am in work)

Personally I prefer putting the action listening code in the same class so I have modified it to do this (this is just my preferred coding approach). There was a typo in the declaration of actionPerformed, it read actionPerfomed ('r' missing). Here is the code with my adjustments:

I want to set up validation where if an incorrect value is entered, a message box pops up saying so...

I have already set the input type for the First Day of Rental and Time of Booking, which changes the input as soon as the user leaves the box, but I want the user to know the input type it has to be (by a message box)... also I need to make sure that the user MUST select the Licence and that the Number of Days is less than a 4 digit number.

I hope what Ive said makes sense, and any help guys is MUCH appreciated!

Hi this is refering to your question regarding adding an action listener for the ok button. You would simple add an actionlistener to the okay button

example

iOK.addActionListener(this);

then in your action performed method which is this,

Code:

public void actionPerformed(ActionEvent e)
{
// dispose frame, 'this' keyword refers to this object(CustomerView)
this.dispose(); // if exit(0) is called first, this can never be called
// kill application
System.exit(0);
}

Above you need to have an if statment to check for, which button was clicked.

As you can see, this way of doing it means that you need if statments to get the source, as in what ever button was clicked. If you have more then a few buttons, I would personaly say that it would be better to create a class for each button. so instead of having

I am trying to put the same confirmation message box that is used for the Cancel button, on the X button of the frame, so it asks the user before closing the frame that way. I saw some examples on various websites about watching the window etc, but they always seemed to give me various errors when I tried using that method

What I meant about the validation is that when the user types "abc" into the Number of Days field, I want it to bring up a message saying "Sorry, only numbers allowed in here"... a similar thing for the two date fields, where it brings up messages when the user enters the date in the incorrect format, and forces them to change it... for the Licence I want it so that an option has to be selected... of course this will have to be done when the user presses the OK button. I hope it makes more sense now.

I would just like to say that thank you so much for your help, and that I owe you guys a lot

Its not possible to add action listeners to the minimise, maximise and close buttons of a GUI window because these buttons are located in native code. You can however add a window listener to the GUI in the same way you added the actionlistener:

A class can only ever extend one class (JFrame in this case) but it can implement as many interfaces as you want (ActionListener and WindowListener in this case). When you implement an interface, you must override ALL the methods it declares, whether you use them or not. I will leave it up to you as a learning exercise to find out the methods that need to be implemented using the javadocs (a java developers most critical tool)

Learning how to use the javadocs if the most valueable lesson that new developers need to learn, as it is the blueprint for java language.

The validation issues you describe aren't really validation issues they are more like error catching issues. You need to use exception handling to catch such error as you describe. A brief lesson on exception should do the trick at:

In the try block, you put the code that you expect will throw an exception. Then you declare a catch block for every exception the code in try can throw. (Looking at the javadocs, the only statement that can throw an exception is Integer.parseInt(). It thrws a NumberFormatException) In the catch block you put the error handling code. If there is no error, code execution resumes from the next statement after the catch block, but nothing in the catch block is executed,