-
calling methods
Im using a progress Panel for a typing tutor. When the typing lesson ends I cannot do anything else with the Progress Panel e.g. resetting a lesson. Other less important buttons work e.g. changing the colour and font sizes etc.
The buttons are created by an action Listener. It all works perfect untill the lesson ends, and the progress panel freezes.
What is the correct way to call an action Listener method so that it will work when the lesson is completed?
Here is some of the code im using.
boolean isCorrectKey = progressPanel.type( charTyped );
if( progressPanel.atEnd() ) {
currentLessonLine++;
switch (lessonNumber) {
case 1:
if (currentLessonLine < lesson1.length) {
progressPanel.setText(lesson1[currentLessonLine]);
currentLessonLine++;
break;
}
case 2:
if (currentLessonLine < lesson2.length) {
progressPanel.setText(lesson2[currentLessonLine]);
currentLessonLine++;
break;
}
default: // end of lesson
javax.swing.JOptionPane.showMessageDialog(null, progressPanel.message());
javax.swing.JOptionPane.showMessageDialog(null, progressPanel.getResults());
/*
* Close off lesson - more typing will cause exceptions - exceeding array bounds
*/
//}
}
}
public void lessonbutton_ActionPerformed(ActionEvent event) {
if(lessons.getSelectedItem() == "Lesson 1"){
progressPanel.setText( lesson1[currentLessonLine] );
mainheading.setText("Lesson 1: The home keys");
lessonNumber =1;
}
else if(lessons.getSelectedItem() == "Lesson 2") {
progressPanel.setText( lesson2[currentLessonLine] );
mainheading.setText("Lesson 2: 'g' and 'h' keys");
lessonNumber =2;
}
-
You don't actually call an actionListener, what you do it you tell actionGenerators,
like the buttons, that your panel is willing to receive the actions they generate,
so your panel is set up as an actionListener (implements it)
and 'hooks up' to the button like:
button.addActionListener(panel);
This tells the button that your panel is an actionslistener that listens with the method
actionPerformed(ActionEvent, a)
So normally you never write code in your program that invokes this method, - it is
called by the buttons, comboboxes etc. when the user does something with them.
But you can easily do a 'button click' programmatically like:
panel.actionPerformed(new ActionEvent(button, 0,"Java clicked it"));
----
So, telling what is wrong with your code is impossible as you have used the callback
method (actionPerformed) to set some components and vars, not how the progress
panel ticks, and that is where the problem exists.
eschew obfuscation
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
Forum Rules
|
Top DevX Stories
Easy Web Services with SQL Server 2005 HTTP Endpoints
JavaOne 2005: Java Platform Roadmap Focuses on Ease of Development, Sun Focuses on the "Free" in F.O.S.S.
Wed Yourself to UML with the Power of Associations
Microsoft to Add AJAX Capabilities to ASP.NET
IBM's Cloudscape Versus MySQL
|
Bookmarks