Drop_of_Rain
asked on
Look over this class
Hello everyone thanks for all your support. I have another question. I modified
this class to be able to have a user set a timer and then store the total number
of Milliseconds to a variable. I then need to pass this to a TimerClass or should
i just have it as a inner class in this one?
Can you go over it and see if i got it right.
I added these If statement to stop the down button from working if the int was 0
Will these work?
if (hr = 0) // stoping the down button from working when the number is 0
{
this.guiPanel.downButton.e nablied(fa lse)
}
if (hr = 0) // stoping the down button from working when the number is 0
{
this.guiPanel.downButton.e nablied(fa lse)
}
I also added these are these correct?
int hrms = hr * 60 * 60 * 1000; // convert hr to Milliseconds
int minms min * 60 * 1000; // convert min to Milliseconds
userTimerAlarm = hrms + minms; // store total Milliseconds
package my.test;
import java.awt.event.ActionEvent ;
import javax.swing.AbstractAction ;
import javax.swing.JLabel;
import my.test.GuiPanel.Mode;
class AdvanceModeAction extends AbstractAction
{
private final GuiPanel guiPanel;
public AdvanceModeAction(GuiPanel guiPanel, String name)
{
super(name);
this.guiPanel = guiPanel;
}
public void actionPerformed(ActionEven t e)
{
String cmd = e.getActionCommand();
if (this.guiPanel.currentMode == Mode.Timer)
{
this.guiPanel.timeDisplay. setText("0 0:00:00"); //Reset time to 0
if (cmd.equals(this.guiPanel. hourButton ))
{
selected = HR;
}
else if (cmd.equals(this.guiPanel. minutesBut ton))
{
selected = MIN;
}
else if (cmd.equals(this.guiPanel. upButton))
{
if (selected == HR)
{
String time = this.guiPanel.timeDisplay. getText();
String[] splitTime = time.split(":");
int hr = Integer.parseInt(splitTime [0].trim() );
time = Integer.toString(hr + 1) + ":" + splitTime[1] + ":" + splitTime[2];
guiPanel.timeDisplay.setTe xt(time); //modified time
}
else if (selected == MIN)
{
String time = this.guiPanel.timeDisplay. getText();
String[] splitTime = time.split(":");
int min = Integer.parseInt(splitTime [1].trim() );
time = splitTime[0] + ":" + Integer.toString(min + 1) + ":" + splitTime[2];
guiPanel.timeDisplay.setTe xt(time); //modified time
}
}
else if (cmd.equals(this.guiPanel. downButton ))
{
if (selected == HR)
{
String time = guiPanel.timeDisplay.getTe xt();
String[] splitTime = time.split(":");
if (hr = 0) // stoping the down button from working when the number is 0
{
this.guiPanel.downButton.e nablied(fa lse)
}
int hr = Integer.parseInt(splitTime [0].trim() );
time = Integer.toString(hr - 1) + ":" + splitTime[1] + ":" + splitTime[2];
guiPanel.timeDisplay.setTe xt(time); //modified time
}
else if (selected == MIN)
{
String time = guiPanel.timeDisplay.getTe xt();
String[] splitTime = time.split(":");
int min = Integer.parseInt(splitTime [1].trim() );
if (min = 0) // stoping the down button from working when the number is 0
{
this.guiPanel.downButton.e nablied(fa lse)
}
time = splitTime[0] + ":" + Integer.toString(min - 1) + ":" + splitTime[2];
guiPanel.timeDisplay.setTe xt(time); //modified time
}
}
else if (cmd.equals(this.guiPanel. okButton.g etText()))
{
//time should be stored in timerDisplay
this.guiPanel.alarmStarted = true;
Int hrms = hr * 60 * 60 * 1000; // convert hr to Milliseconds
Int minms min * 60 * 1000; // convert min to Milliseconds
userTimerAlarm = hrms + minms; // store total Milliseconds
this.guiPanel.alarmTime = this.guiPanel.timeDisplay. getText();
selected = HR;
this.guiPanel.currentMode = Mode.Clock;
this.guiPanel.modeDisplay. setText(th is.guiPane l.currentM ode.toStri ng());
this.guiPanel.dispProv.set DispListen er(this.gu iPanel.tim eDisplay);
}
}
}
}
this class to be able to have a user set a timer and then store the total number
of Milliseconds to a variable. I then need to pass this to a TimerClass or should
i just have it as a inner class in this one?
Can you go over it and see if i got it right.
I added these If statement to stop the down button from working if the int was 0
Will these work?
if (hr = 0) // stoping the down button from working when the number is 0
{
this.guiPanel.downButton.e
}
if (hr = 0) // stoping the down button from working when the number is 0
{
this.guiPanel.downButton.e
}
I also added these are these correct?
int hrms = hr * 60 * 60 * 1000; // convert hr to Milliseconds
int minms min * 60 * 1000; // convert min to Milliseconds
userTimerAlarm = hrms + minms; // store total Milliseconds
package my.test;
import java.awt.event.ActionEvent
import javax.swing.AbstractAction
import javax.swing.JLabel;
import my.test.GuiPanel.Mode;
class AdvanceModeAction extends AbstractAction
{
private final GuiPanel guiPanel;
public AdvanceModeAction(GuiPanel
{
super(name);
this.guiPanel = guiPanel;
}
public void actionPerformed(ActionEven
{
String cmd = e.getActionCommand();
if (this.guiPanel.currentMode
{
this.guiPanel.timeDisplay.
if (cmd.equals(this.guiPanel.
{
selected = HR;
}
else if (cmd.equals(this.guiPanel.
{
selected = MIN;
}
else if (cmd.equals(this.guiPanel.
{
if (selected == HR)
{
String time = this.guiPanel.timeDisplay.
String[] splitTime = time.split(":");
int hr = Integer.parseInt(splitTime
time = Integer.toString(hr + 1) + ":" + splitTime[1] + ":" + splitTime[2];
guiPanel.timeDisplay.setTe
}
else if (selected == MIN)
{
String time = this.guiPanel.timeDisplay.
String[] splitTime = time.split(":");
int min = Integer.parseInt(splitTime
time = splitTime[0] + ":" + Integer.toString(min + 1) + ":" + splitTime[2];
guiPanel.timeDisplay.setTe
}
}
else if (cmd.equals(this.guiPanel.
{
if (selected == HR)
{
String time = guiPanel.timeDisplay.getTe
String[] splitTime = time.split(":");
if (hr = 0) // stoping the down button from working when the number is 0
{
this.guiPanel.downButton.e
}
int hr = Integer.parseInt(splitTime
time = Integer.toString(hr - 1) + ":" + splitTime[1] + ":" + splitTime[2];
guiPanel.timeDisplay.setTe
}
else if (selected == MIN)
{
String time = guiPanel.timeDisplay.getTe
String[] splitTime = time.split(":");
int min = Integer.parseInt(splitTime
if (min = 0) // stoping the down button from working when the number is 0
{
this.guiPanel.downButton.e
}
time = splitTime[0] + ":" + Integer.toString(min - 1) + ":" + splitTime[2];
guiPanel.timeDisplay.setTe
}
}
else if (cmd.equals(this.guiPanel.
{
//time should be stored in timerDisplay
this.guiPanel.alarmStarted
Int hrms = hr * 60 * 60 * 1000; // convert hr to Milliseconds
Int minms min * 60 * 1000; // convert min to Milliseconds
userTimerAlarm = hrms + minms; // store total Milliseconds
this.guiPanel.alarmTime = this.guiPanel.timeDisplay.
selected = HR;
this.guiPanel.currentMode = Mode.Clock;
this.guiPanel.modeDisplay.
this.guiPanel.dispProv.set
}
}
}
}
You can use the MyTimer class in your other question if the Mode is correct. I would write the if statements as a switch/case statement as in my earlier examples
ASKER
Does it look right above?
The problem i had with doing that in another class seems that it wanted an int to use as the case. I must be missing someithing here. Here is the Case you gave me.
private class AdvanceModeActionCase extends javax.swing.AbstractAction
{
public AdvanceModeActionCase(Stri ng name)
{
super(name);
}
public void actionPerformed(java.awt.e vent.Actio nEvent e)
{
advanceMode();
enableAllButtons();
switch (currentMode)
{
case Alarm:
recordButton.setEnabled(fa lse);
playButton.setEnabled(fals e);
stopButton.setEnabled(fals e);
fastButton.setEnabled(fals e);
alarmTempDisplay = new JLabel(timeDisplay.getText ());
alarmStarted = false;
dispProv.setDispListener(a larmTempDi splay);
break;
case Audio:
hourButton.setEnabled(fals e);
minutesButton.setEnabled(f alse);
break;
case Clock:
recordButton.setEnabled(fa lse);
playButton.setEnabled(fals e);
stopButton.setEnabled(fals e);
break;
case Date:
recordButton.setEnabled(fa lse);
playButton.setEnabled(fals e);
stopButton.setEnabled(fals e);
break;
case Timer:
recordButton.setEnabled(fa lse);
stopButton.setText("Reset" );
fastButton.setEnabled(true ); // changes like these
fastButton.setText("Reset" ); // changes like these
playButton.setEnabled(fals e);
stopButton.setEnabled(fals e);
break;
}
}
}
The problem i had with doing that in another class seems that it wanted an int to use as the case. I must be missing someithing here. Here is the Case you gave me.
private class AdvanceModeActionCase extends javax.swing.AbstractAction
{
public AdvanceModeActionCase(Stri
{
super(name);
}
public void actionPerformed(java.awt.e
{
advanceMode();
enableAllButtons();
switch (currentMode)
{
case Alarm:
recordButton.setEnabled(fa
playButton.setEnabled(fals
stopButton.setEnabled(fals
fastButton.setEnabled(fals
alarmTempDisplay = new JLabel(timeDisplay.getText
alarmStarted = false;
dispProv.setDispListener(a
break;
case Audio:
hourButton.setEnabled(fals
minutesButton.setEnabled(f
break;
case Clock:
recordButton.setEnabled(fa
playButton.setEnabled(fals
stopButton.setEnabled(fals
break;
case Date:
recordButton.setEnabled(fa
playButton.setEnabled(fals
stopButton.setEnabled(fals
break;
case Timer:
recordButton.setEnabled(fa
stopButton.setText("Reset"
fastButton.setEnabled(true
fastButton.setText("Reset"
playButton.setEnabled(fals
stopButton.setEnabled(fals
break;
}
}
}
>>that it wanted an int to use as the case
You should be using the enum that i gave you (Mode). If it's case Audio, start playing, with or without a Timer
You should be using the enum that i gave you (Mode). If it's case Audio, start playing, with or without a Timer
ASKER
I just went to that question and copied what you gave me here it is.
https://www.experts-exchange.com/questions/22696219/Changing-action-command-by-changing-text-in-the-button.html
So how would this be added to this class?
When i added this to this class it says it can not be local, can you tell me what is happening here?
enum Mode {
Clock, Date, Alarm, Timer, Audio, Custom,
};
private class AdvanceModeAction extends javax.swing.AbstractAction
{
public AdvanceModeAction(String name)
{
super(name);
enum Mode {
Clock, Date, Alarm, Timer, Audio, Custom,
};
}
public void actionPerformed(java.awt.e vent.Actio nEvent e)
{
advanceMode();
enableAllButtons();
switch (currentMode)
{
case Alarm:
recordButton.setEnabled(fa lse);
playButton.setEnabled(fals e);
stopButton.setEnabled(fals e);
fastButton.setEnabled(fals e);
alarmTempDisplay = new JLabel(timeDisplay.getText ());
alarmStarted = false;
dispProv.setDispListener(a larmTempDi splay);
break;
case Audio:
hourButton.setEnabled(fals e);
minutesButton.setEnabled(f alse);
break;
case Clock:
recordButton.setEnabled(fa lse);
playButton.setEnabled(fals e);
stopButton.setEnabled(fals e);
break;
case Date:
recordButton.setEnabled(fa lse);
playButton.setEnabled(fals e);
stopButton.setEnabled(fals e);
break;
case Timer:
recordButton.setEnabled(fa lse);
playButton.setEnabled(fals e);
stopButton.setEnabled(fals e);
dispProv.setDispListener(t imeDisplay );
break;
}
}
}
https://www.experts-exchange.com/questions/22696219/Changing-action-command-by-changing-text-in-the-button.html
So how would this be added to this class?
When i added this to this class it says it can not be local, can you tell me what is happening here?
enum Mode {
Clock, Date, Alarm, Timer, Audio, Custom,
};
private class AdvanceModeAction extends javax.swing.AbstractAction
{
public AdvanceModeAction(String name)
{
super(name);
enum Mode {
Clock, Date, Alarm, Timer, Audio, Custom,
};
}
public void actionPerformed(java.awt.e
{
advanceMode();
enableAllButtons();
switch (currentMode)
{
case Alarm:
recordButton.setEnabled(fa
playButton.setEnabled(fals
stopButton.setEnabled(fals
fastButton.setEnabled(fals
alarmTempDisplay = new JLabel(timeDisplay.getText
alarmStarted = false;
dispProv.setDispListener(a
break;
case Audio:
hourButton.setEnabled(fals
minutesButton.setEnabled(f
break;
case Clock:
recordButton.setEnabled(fa
playButton.setEnabled(fals
stopButton.setEnabled(fals
break;
case Date:
recordButton.setEnabled(fa
playButton.setEnabled(fals
stopButton.setEnabled(fals
break;
case Timer:
recordButton.setEnabled(fa
playButton.setEnabled(fals
stopButton.setEnabled(fals
dispProv.setDispListener(t
break;
}
}
}
ASKER
enum Mode {
Clock, Date, Alarm, Timer, Audio, Custom,
};
So would i just chane currentMode to Mode?
private class AdvanceModeAction extends javax.swing.AbstractAction
{
public AdvanceModeAction(String name)
{
super(name);
}
public void actionPerformed(java.awt.e vent.Actio nEvent e)
{
advanceMode();
enableAllButtons();
switch (currentMode) // switch currentMode to Mode
{
case Alarm:
recordButton.setEnabled(fa lse);
playButton.setEnabled(fals e);
stopButton.setEnabled(fals e);
fastButton.setEnabled(fals e);
alarmTempDisplay = new JLabel(timeDisplay.getText ());
alarmStarted = false;
dispProv.setDispListener(a larmTempDi splay);
break;
case Audio:
hourButton.setEnabled(fals e);
minutesButton.setEnabled(f alse);
break;
case Clock:
recordButton.setEnabled(fa lse);
playButton.setEnabled(fals e);
stopButton.setEnabled(fals e);
break;
case Date:
recordButton.setEnabled(fa lse);
playButton.setEnabled(fals e);
stopButton.setEnabled(fals e);
break;
case Timer:
recordButton.setEnabled(fa lse);
playButton.setEnabled(fals e);
stopButton.setEnabled(fals e);
dispProv.setDispListener(t imeDisplay );
break;
}
}
}
Clock, Date, Alarm, Timer, Audio, Custom,
};
So would i just chane currentMode to Mode?
private class AdvanceModeAction extends javax.swing.AbstractAction
{
public AdvanceModeAction(String name)
{
super(name);
}
public void actionPerformed(java.awt.e
{
advanceMode();
enableAllButtons();
switch (currentMode) // switch currentMode to Mode
{
case Alarm:
recordButton.setEnabled(fa
playButton.setEnabled(fals
stopButton.setEnabled(fals
fastButton.setEnabled(fals
alarmTempDisplay = new JLabel(timeDisplay.getText
alarmStarted = false;
dispProv.setDispListener(a
break;
case Audio:
hourButton.setEnabled(fals
minutesButton.setEnabled(f
break;
case Clock:
recordButton.setEnabled(fa
playButton.setEnabled(fals
stopButton.setEnabled(fals
break;
case Date:
recordButton.setEnabled(fa
playButton.setEnabled(fals
stopButton.setEnabled(fals
break;
case Timer:
recordButton.setEnabled(fa
playButton.setEnabled(fals
stopButton.setEnabled(fals
dispProv.setDispListener(t
break;
}
}
}
ASKER
So is this right now, sorry for not trying more earlier.
public enum Mode {
Clock, Date, Alarm, Timer, Audio, Custom,
};
private class AdvanceModeAction extends javax.swing.AbstractAction
{
Mode mode;
public AdvanceModeAction(Mode mode)
{ this mode = mode;
}
public void actionPerformed(java.awt.e vent.Actio nEvent e)
{
advanceMode();
enableAllButtons();
switch (mode) // switch currentMode to Mode
{
case Alarm:
recordButton.setEnabled(fa lse);
playButton.setEnabled(fals e);
stopButton.setEnabled(fals e);
fastButton.setEnabled(fals e);
alarmTempDisplay = new JLabel(timeDisplay.getText ());
alarmStarted = false;
dispProv.setDispListener(a larmTempDi splay);
break;
case Audio:
hourButton.setEnabled(fals e);
minutesButton.setEnabled(f alse);
break;
case Clock:
recordButton.setEnabled(fa lse);
playButton.setEnabled(fals e);
stopButton.setEnabled(fals e);
break;
case Date:
recordButton.setEnabled(fa lse);
playButton.setEnabled(fals e);
stopButton.setEnabled(fals e);
break;
case Timer:
recordButton.setEnabled(fa lse);
playButton.setEnabled(fals e);
stopButton.setEnabled(fals e);
dispProv.setDispListener(t imeDisplay );
break;
}
}
}
public enum Mode {
Clock, Date, Alarm, Timer, Audio, Custom,
};
private class AdvanceModeAction extends javax.swing.AbstractAction
{
Mode mode;
public AdvanceModeAction(Mode mode)
{ this mode = mode;
}
public void actionPerformed(java.awt.e
{
advanceMode();
enableAllButtons();
switch (mode) // switch currentMode to Mode
{
case Alarm:
recordButton.setEnabled(fa
playButton.setEnabled(fals
stopButton.setEnabled(fals
fastButton.setEnabled(fals
alarmTempDisplay = new JLabel(timeDisplay.getText
alarmStarted = false;
dispProv.setDispListener(a
break;
case Audio:
hourButton.setEnabled(fals
minutesButton.setEnabled(f
break;
case Clock:
recordButton.setEnabled(fa
playButton.setEnabled(fals
stopButton.setEnabled(fals
break;
case Date:
recordButton.setEnabled(fa
playButton.setEnabled(fals
stopButton.setEnabled(fals
break;
case Timer:
recordButton.setEnabled(fa
playButton.setEnabled(fals
stopButton.setEnabled(fals
dispProv.setDispListener(t
break;
}
}
}
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
To ensure accessibility it would probably be better to compile
public enum Mode {
Clock, Date, Alarm, Timer, Audio, Custom,
}
in its own source files
public enum Mode {
Clock, Date, Alarm, Timer, Audio, Custom,
}
in its own source files
in its own source files=in its own source file
ASKER
Ok now you have lost me, what do you mean by source file. I though a source file was a file of java code not compiled. What do you mean. Please explain this to me. I looked it up and that was all i found. Should i make them all caps?
CEHJ:To ensure accessibility it would probably be better to compile
public enum Mode {
Clock, Date, Alarm, Timer, Audio, Custom,
}
in its own source filesAccept Multiple Solutions Accept as Solution
CEHJ:in its own source files=in its own source file
CEHJ:To ensure accessibility it would probably be better to compile
public enum Mode {
Clock, Date, Alarm, Timer, Audio, Custom,
}
in its own source filesAccept Multiple Solutions Accept as Solution
CEHJ:in its own source files=in its own source file
>>I though a source file was a file of java code not compiled.
It is
It is
ASKER
IS THIS WHAT YOU MEAN?
public class ModesClass {
/** Creates a new instance of ModesClass */
public ModesClass() {
}
enum Mode {
CLOCK, ALARM, TIMER, AUDIO, DATE, CUSTOM,
};
}
public class ModesClass {
/** Creates a new instance of ModesClass */
public ModesClass() {
}
enum Mode {
CLOCK, ALARM, TIMER, AUDIO, DATE, CUSTOM,
};
}
Ah i see the confusion. An enum is really a class. You don't need to wrap it in another. Save the last source i posted as Mode.java
btw CPlusJavaCSharp is right about the case of the symbols. Making the enums upper case signals to readers of the code that constants are being used. So
public enum Mode {
CLOCK, ALARM, TIMER, AUDIO, DATE, CUSTOM,
}
btw CPlusJavaCSharp is right about the case of the symbols. Making the enums upper case signals to readers of the code that constants are being used. So
public enum Mode {
CLOCK, ALARM, TIMER, AUDIO, DATE, CUSTOM,
}
ASKER
Or something like this?
public class ModesClass {
public ModesClass() {
}
public getMode(){
enum Mode {
CLOCK, ALARM, TIMER, AUDIO, DATE, CUSTOM,
};
}
}
public class ModesClass {
public ModesClass() {
}
public getMode(){
enum Mode {
CLOCK, ALARM, TIMER, AUDIO, DATE, CUSTOM,
};
}
}
No. See my last post
ASKER
I had this in my earier post which is the same except the CAPS. So were will this code go, in the class?
Now that we have this clear, but we have gotten off what the original question was, could you go back up and look at it. You never answered it
public enum Mode {
Clock, Date, Alarm, Timer, Audio, Custom,
};
Now that we have this clear, but we have gotten off what the original question was, could you go back up and look at it. You never answered it
public enum Mode {
Clock, Date, Alarm, Timer, Audio, Custom,
};
>>I had this in my earier post which is the same except the CAPS.
No - it isn't the same. There is a terminating semi-colon.
>>So were will this code go, in the class?
I've already said - in its own source file
No - it isn't the same. There is a terminating semi-colon.
>>So were will this code go, in the class?
I've already said - in its own source file
ASKER
How is this source file structured, I can't find anything about how to.
See your earlier questioin where I explained about simplifying your listener.
You don't need *any* if/case statements. Whenevr you start doing things like that it generally means theres a problem in your code.
In this case you need seperate listener for buttons with different action, which is in fact how they are meant to be used. One listener for all button defaets the purpose of being able to specify listeners :)
eg.
public AlarmListener inmplements ActionListener
{
public void ationPerformed(ActionEvent e)
{
recordButton.setEnabled(fa lse);
playButton.setEnabled(fals e);
stopButton.setEnabled(fals e);
fastButton.setEnabled(fals e);
alarmTempDisplay = new JLabel(timeDisplay.getText ());
alarmStarted = false;
dispProv.setDispListener(a larmTempDi splay);
}
}
nice and simple, and clear :)
You don't need *any* if/case statements. Whenevr you start doing things like that it generally means theres a problem in your code.
In this case you need seperate listener for buttons with different action, which is in fact how they are meant to be used. One listener for all button defaets the purpose of being able to specify listeners :)
eg.
public AlarmListener inmplements ActionListener
{
public void ationPerformed(ActionEvent
{
recordButton.setEnabled(fa
playButton.setEnabled(fals
stopButton.setEnabled(fals
fastButton.setEnabled(fals
alarmTempDisplay = new JLabel(timeDisplay.getText
alarmStarted = false;
dispProv.setDispListener(a
}
}
nice and simple, and clear :)
ASKER
Objects: The case statement above are based upon the text in a label being changed because of a button being pressed and each time the button is pressed it cycles through the enum. It is the change in the label here is is being looked at. So then it would be a PropertyChangeListene for the label and the text change in it? I would still need to use If statements to look at the property change, so what would be the real difference?
Go to the top of the page and look at my oringinal question, everyone has gotten off that. I would like to know if I am right with the changes i made.
Go to the top of the page and look at my oringinal question, everyone has gotten off that. I would like to know if I am right with the changes i made.
ASKER
CEHJ:
I don't see anything in EE database or in Google about enum being or needing to be in a seperate file.
I don't see anything in EE database or in Google about enum being or needing to be in a seperate file.
> The case statement above are based upon the text in a label being changed because of a button
Thats not what the code above is doing :)
> I would still need to use If statements to look at the property change
Nop, you wouldn''t need an if (or an enum). Thats just over complicating things.
Just break the Action up into seperate Action's, thats how they are meant to be used.
Thats not what the code above is doing :)
> I would still need to use If statements to look at the property change
Nop, you wouldn''t need an if (or an enum). Thats just over complicating things.
Just break the Action up into seperate Action's, thats how they are meant to be used.
ASKER
oobjectsL do me a favor and go to the oringinal question, because the code we are talking about is not what I started with in this question. PLEASE RE-READ MY FIRST POST
yes, i just was :) people far too often sidetrack q';s abnd confuse other experts. one of the many problems my students have with this site.
same principle applies to the code in your question, they are differentactions and as such should be implemented in different Action classes.
In this case you would implement it by either changing the listener of the button when the mode changed, or
make the mode your action, then in your buttonm listener just call the action
public void actionPerformed(ActionEven t e)
{
this.guiPanel.currentMode. actionPerf ormed(e);
nide and simple :)
In this case you would implement it by either changing the listener of the button when the mode changed, or
make the mode your action, then in your buttonm listener just call the action
public void actionPerformed(ActionEven
{
this.guiPanel.currentMode.
nide and simple :)
ASKER
this.guiPanel.currentMode. actionPerf ormed(e); But won't this still be just one listener I don't see the difference. If the mode is changing isn't that a propertychange? The property of the text of the label has changed. The buttons will always work the way they do, like the up, down, hour, minutes, but they will be different classes for each mode because different stuff has to happen with each on. One is for setting the amount of time for a timer, another will be for setting the time in an alarm, another will be for adjusting the date. Because for each mode i change some of the button's text and then use the text property to take action from.
I'm not getting what you are trying to get me to see, sorry.
I'm not getting what you are trying to get me to see, sorry.
> But won't this still be just one listener I don't see the difference.
when the mode changes, the listener stored with currentMode will be changed.
> One is for setting the amount of time for a timer, another will be for setting the time in an alarm, another will be for adjusting the date.
So they should be different actions. Theres no relationship between the actions so theres no reason to group them all in one action.
when the mode changes, the listener stored with currentMode will be changed.
> One is for setting the amount of time for a timer, another will be for setting the time in an alarm, another will be for adjusting the date.
So they should be different actions. Theres no relationship between the actions so theres no reason to group them all in one action.
> If the mode is changing isn't that a propertychange?
It may be a property change (am not sure how iuts implemented at that end), but it should *trigger an action change*. ie. when the mode changes, the *behavior* changes. Thus you change the acvtion that gets executed.
It may be a property change (am not sure how iuts implemented at that end), but it should *trigger an action change*. ie. when the mode changes, the *behavior* changes. Thus you change the acvtion that gets executed.
ASKER
There is a JLabel and the text is changed by it advancing through the enum which has the Modes as CONSTANTS in it. The class in the question is just for being able to adjust the minutes and hours, store the amount for the hours and minutes and then add them together to total the number of milliseconds for the timer. and then change the mode back to CLOCK when the OK button is pressed, display the time again and call another class to handle the timer and audio. I don't see why it is wrong to use it this way. Explain to me why it shoul be done another way. It seens pretty solid to be working with the CONSTANTS.
Why? Because you end up with a convoluted if/switch instead of a single method call.
Mode isn't just a constant, it defines a change in behaviour. Thats *not* what enum's are for.
Mode isn't just a constant, it defines a change in behaviour. Thats *not* what enum's are for.
If each mode needs any attrributes (eg. a String) these can also be added as properties of the Mode action
eg.
public ModeXyz extends AbstractAction
{
public ModeXyzAction(String name)
{
super(name);
}
public void actionPerformed(ActionEven t event)
{
// perform required action for mode xyz
}
}
eg.
public ModeXyz extends AbstractAction
{
public ModeXyzAction(String name)
{
super(name);
}
public void actionPerformed(ActionEven
{
// perform required action for mode xyz
}
}
ASKER
unum are just CONSTANTS right that is why they are in all CAPS. So it seens to me there id the mode type and the hour button and the minute button and the up and down buttons could be handles in the hour button action. Then there is the MInutes button action and the up and down buttons could be handled in the Minutes button action. Ok I can see that would be much cleaner code. So that way we would still be looking at the mode but with the button action as well.
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Well with the alarm when the mode is changed to alarm certain button are enabled(false) because they have nothing to do with the mode. The hour, minutes, up, down, Ok buttons are enabled. The timeDisplay which is a JLabel is were the time is displayed. The user presses the hour button which allows then to adjust the numbers in the hour display up or down, I still have to handle the am pm thing. The minute button does the same thing. Now this is true for both the alarm and timer mode. The only difference is I reset the display for the timer to 00:00:00. These 2 mode are the same with the buttons.
> when the mode is changed to alarm certain button are enabled(false) because they have nothing to do with the mode.
thats an action then
> The only difference is I reset the display for the timer to 00:00:00.
The button action could call the mode action (as I showed earlier) allowing the mode to do any specific things like resetting timer display.
how do u change mode?
thats an action then
> The only difference is I reset the display for the timer to 00:00:00.
The button action could call the mode action (as I showed earlier) allowing the mode to do any specific things like resetting timer display.
how do u change mode?
ASKER
With the mode button
so what the action for that mode button should do is change the mode instance that defines mode behaviour.
But take it one step at a time.
First take the action for a particular button and create a specific action for it. At this stage ignore mode, once the actions working we'll see what differences are needed depending on mode.
But take it one step at a time.
First take the action for a particular button and create a specific action for it. At this stage ignore mode, once the actions working we'll see what differences are needed depending on mode.
ASKER
So each button will get a new listener, ae, be, ce, de, etc or would it be better to name it so it is readable like modeaction, upaction, downaction, etc that way the code will be readable correct?
If I use the button to do the same thing over then I should use the same label to make all the changes in as well correct. That way the code stays consistent. The reason i say this is because I haven't done the date mode yet, but I could still use the same label because all it is is just different formatting. I was thinking at the beginning to use a different fram for it, but as i am learning i am realizing that more can be done with what is already there. Thanks for being patient with me, i appreciate it.
If I use the button to do the same thing over then I should use the same label to make all the changes in as well correct. That way the code stays consistent. The reason i say this is because I haven't done the date mode yet, but I could still use the same label because all it is is just different formatting. I was thinking at the beginning to use a different fram for it, but as i am learning i am realizing that more can be done with what is already there. Thanks for being patient with me, i appreciate it.
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
What I was thinking was to get the basic concepts working in a prototype version with the code that i have. I could then change the code to be cleaner and better as i go. What are you thoughts about this. I would like to get the basic pieces together and working and then make the changes so we go. I want to make this application public and give you guys credit for helping with it. I think that people can use this in their offices and at home. I would like to add to this program so that can call your cell phone or other number and play the messages you have when it is time to.
ASKER
< u can label your buttons differently if it makes your gui clearer, otherwise yes keep it consistent
I ment the JLabel, it is used for the clock, timer, alarm and can be used for the date as well.
I ment the JLabel, it is used for the clock, timer, alarm and can be used for the date as well.
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
OK you know more then me. It sounds like I might need to do some restructuring.
What I am thinking now as that i have a Controler class that monitors the modes Then their is a mode class that handles that mode and calls on other classes. That way evrything about that mode is under one roof. I can have one class that handles the button properties and if enabled or not, then a class that handles all audio calling on subclasses etc. I think this is the direction I need to go.
What I am thinking now as that i have a Controler class that monitors the modes Then their is a mode class that handles that mode and calls on other classes. That way evrything about that mode is under one roof. I can have one class that handles the button properties and if enabled or not, then a class that handles all audio calling on subclasses etc. I think this is the direction I need to go.
let me know if u have any questions along the way :)
ASKER
So with the ModeController I'm thinking to use a propertychangelistener because all it will need to do is know is when the mode has changed. One listener for one JLabel. For the ButtonControl Class I'm thinking I can use the enum because it is following the same action as the JLabel listener but not using it.
I will need to create a class for each mode and have then do what ever needs to be done. I will add new action listeners for each button with the name I shared, except for the buttons that change which are 2 i think. I will use actionCommand with them because I can use the text of the button to control the flow of what happens. So what do you think of this plan?
You said that the audio player I found is the wrong type, can i use audioclip from the applet?
I will need to create a class for each mode and have then do what ever needs to be done. I will add new action listeners for each button with the name I shared, except for the buttons that change which are 2 i think. I will use actionCommand with them because I can use the text of the button to control the flow of what happens. So what do you think of this plan?
You said that the audio player I found is the wrong type, can i use audioclip from the applet?
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
I did a rundown on all the buttons, and they have alot of differnt uses. It seemed easy to me to only have to use one listener watching the JLabel because that is the only thing that changes with the mode button. Nothing else happen until the OK button is pressed which will have it own listener, i like that idea.. It seems logical to me to do it that way. Simple and easy. As for using the enum all it is basicly is a array of CONSTANTS that don't change but can be added to and expanded very easy. I am thinking simple from my view point. So that is were my thinking is coming from.
Thanks for the audio examples.
Thanks for the audio examples.
> It seemed easy to me to only have to use one listener watching the JLabel because that is the only
> thing that changes with the mode button.
sounds like you've got it the wrong way around :) You shouldn't be listening to label changes.
Your mode button listener should handle updating the label and the current mode.
DOn't think you'll need any enums from what you've told me.
> thing that changes with the mode button.
sounds like you've got it the wrong way around :) You shouldn't be listening to label changes.
Your mode button listener should handle updating the label and the current mode.
DOn't think you'll need any enums from what you've told me.
ASKER
Well I know you are right but I'm going to need some help getting this started. Other experts from this site have made these recomadation and contributed code as well. I am not one to know if what they suggest is right. But I will say i want to learn to think in the right way in my programing. I know from experince that a way can appear to be right, but it doesn't mean that it is the right way. A right way looks from many perspectives and levels at the same time which gives it more depth.
So I am very willing to learn from you but I will need you help to get there.
OK I just got it, the mode button does one thing as well, so how will itdo all this, show me some code enough to give me enough direction to put it together.
So I am very willing to learn from you but I will need you help to get there.
OK I just got it, the mode button does one thing as well, so how will itdo all this, show me some code enough to give me enough direction to put it together.
how many modes are there?
ASKER
CLOCK, ALARM, TIMER, AUDIO, DATE, REMINDERS, CUSTOM,
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
I like the layout the way it is, I just tried the radio button but if I expand it in the future, i will have to chage the whole gui, if i keek it this way i can add as much as i want without having to change as much. I see that for the Reminders and Custom modes I will bring up another window and work from it, to much for the gui to handle.
ModeLabelUpdater updater = new ModeLabelUpdater(modeLabel );
clockRb.addActionListener( updater); What is the Rb
alarmRb.addActionListener( updater);
ModeLabelUpdater updater = new ModeLabelUpdater(modeLabel
clockRb.addActionListener(
alarmRb.addActionListener(
what are you currently using?
ASKER
But I'm not attached to it as well. I am just not very good at it so I amshying away from it. Even though i can use Netbeans which makes it really easy. Can we have text travel accross a label like a ticker tape using java, I know they have it in JavaScript. I'm just asking because i though it might be a good way of getting info to a user, what are yoyr thought. I ask this now because of the possibility of changing the GUI. Let me know
ASKER
Can you look over this audio question
https://www.experts-exchange.com/questions/22713466/Look-over-modified-audio-class.html
https://www.experts-exchange.com/questions/22713466/Look-over-modified-audio-class.html
yes you can have a ticker.
what does the user currently use to change the mode?
what does the user currently use to change the mode?
ASKER
Here is the code for the GuI so you can see what it is i am working on. it has a main
import javax.swing.*;
import java.util.ArrayList;
import javax.swing.AbstractAction ;
import java.awt.event.ActionEvent ;
import java.awt.event.ActionEvent ;
import java.lang.*;
import javax.swing.JLabel;
import java.awt.event.ActionEvent ;
import javax.swing.JLabel;
public class GuiPanel extends javax.swing.JFrame
{
enum Mode {
CLOCK, ALARM, TIMER, AUDIO, DATE, REMINDERS, CUSTOM,
};
private java.util.List<Mode> modes;
private int modeIndex;
private Mode currentMode;
boolean alarmStarted = false;
public String alarmTime;
// private/** Creates new form GuiPanel */
public GuiPanel()
{
initComponents();
initModes();
}
private void initModes()
{
modes = new java.util.ArrayList<Mode>( );
for (Mode m : Mode.values())
{
modes.add(m);
}
modeButton.setAction(new AdvanceModeAction("Mode")) ;
advanceMode(); // Advance mode to Clock
}
private class AdvanceModeAction extends javax.swing.AbstractAction
{
public AdvanceModeAction(String name)
{
super(name);
}
public void actionPerformed(java.awt.e vent.Actio nEvent e)
{
advanceMode();
enableAllButtons();
if (currentMode == Mode.ALARM)
{
recordButton.setEnabled(fa lse);
playButton.setEnabled(fals e);
stopButton.setEnabled(fals e);
fastButton.setEnabled(fals e);
alarmTempDisplay = new JLabel(timeDisplay.getText ());
alarmStarted = false;
dispProv.setDispListener(a larmTempDi splay);
}
else if (currentMode == Mode.AUDIO)
{
hourButton.setEnabled(fals e);
minutesButton.setEnabled(f alse);
}
else if (currentMode == Mode.CLOCK)
{
recordButton.setEnabled(fa lse);
playButton.setEnabled(fals e);
stopButton.setEnabled(fals e);
}
else if (currentMode == Mode.DATE)
{
recordButton.setEnabled(fa lse);
playButton.setEnabled(fals e);
stopButton.setEnabled(fals e);
}
else if (currentMode == Mode.TIMER)
{
recordButton.setEnabled(fa lse);
playButton.setEnabled(fals e);
stopButton.setEnabled(fals e);
dispProv.setDispListener(t imeDisplay );
}
}
}
private class AlarmButtonSelectAction extends javax.swing.AbstractAction
{
public final int HR = 0;
public final int MIN = 1;
int selected = -1;
public void actionPerformed(ActionEven t e)
{
String cmd = e.getActionCommand();
if (currentMode == Mode.ALARM)
{
if (cmd.equals(hourButton.get Text()))
{
selected = HR;
}
else if (cmd.equals(minutesButton. getText()) )
{
selected = MIN;
}
else if (cmd.equals(upButton.getTe xt()))
{
if (selected == HR)
{
String time = timeDisplay.getText();
String[] splitTime = time.split(":");
int hr = Integer.parseInt(splitTime [0].trim() );
time = Integer.toString(hr + 1) + ":" + splitTime[1] + ":" + splitTime[2];
timeDisplay.setText(time); //modified time
}
else if (selected == MIN)
{
String time = timeDisplay.getText();
String[] splitTime = time.split(":");
int min = Integer.parseInt(splitTime [1].trim() );
time = splitTime[0] + ":" + Integer.toString(min + 1) + ":" + splitTime[2];
timeDisplay.setText(time); //modified time
}
}
else if (cmd.equals(downButton.get Text()))
{
if (selected == HR)
{
String time = timeDisplay.getText();
String[] splitTime = time.split(":");
int hr = Integer.parseInt(splitTime [0].trim() );
time = Integer.toString(hr - 1) + ":" + splitTime[1] + ":" + splitTime[2];
timeDisplay.setText(time); //modified time
}
else if (selected == MIN)
{
String time = timeDisplay.getText();
String[] splitTime = time.split(":");
int min = Integer.parseInt(splitTime [1].trim() );
time = splitTime[0] + ":" + Integer.toString(min - 1) + ":" + splitTime[2];
timeDisplay.setText(time); //modified time
}
}
else if (cmd.equals(okButton.getTe xt()))
{
//time should be stored in alarmDisplay
alarmStarted = true;
alarmTime = timeDisplay.getText();
selected = HR;
currentMode = Mode.CLOCK;
modeDisplay.setText (currentMode.toString());
dispProv.setDispListener(t imeDisplay );
selected = -1;
}
}
}
}
private void enableAllButtons()
{
downButton.setEnabled(true );
fastButton.setEnabled(true );
hourButton.setEnabled(true );
minutesButton.setEnabled(t rue);
modeButton.setEnabled(true );
okButton.setEnabled(true);
playButton.setEnabled(true );
recordButton.setEnabled(tr ue);
stopButton.setEnabled(true );
upButton.setEnabled(true);
}
private void advanceMode()
{
currentMode = modes.get(modeIndex++ % modes.size());
modeDisplay.setText(curren tMode.toSt ring());
}
void getModeDisplay()
{
currentMode = modes.get(modeIndex++ % modes.size());
}
/** This method is called from within the constructor to
* initialize the form.
* WARNING: Do NOT modify this code. The content of this method is
* always regenerated by the Form Editor.
*/
// <editor-fold defaultstate="collapsed" desc=" Generated Code ">
private void initComponents()
{
jPanel1 = new javax.swing.JPanel();
jLabel1 = new javax.swing.JLabel();
timeDisplay = new javax.swing.JLabel();
jPanel2 = new javax.swing.JPanel();
modeDisplay = new javax.swing.JTextField();
jPanel3 = new javax.swing.JPanel();
modeButton = new javax.swing.JButton();
okButton = new javax.swing.JButton();
hourButton = new javax.swing.JButton();
minutesButton = new javax.swing.JButton();
recordButton = new javax.swing.JButton();
playButton = new javax.swing.JButton();
fastButton = new javax.swing.JButton();
stopButton = new javax.swing.JButton();
upButton = new javax.swing.JButton();
downButton = new javax.swing.JButton();
AlarmButtonSelectAction alarmButtonSelectAction = new AlarmButtonSelectAction();
setDefaultCloseOperation(j avax.swing .WindowCon stants.EXI T_ON_CLOSE );
setResizable(false);
jPanel1.setBackground(new java.awt.Color(255, 255, 255));
jLabel1.setFont(new java.awt.Font("Tahoma", 2, 18));
jLabel1.setForeground(new java.awt.Color(51, 51, 255));
jLabel1.setHorizontalAlign ment(javax .swing.Swi ngConstant s.CENTER);
jLabel1.setText("Audio Reminder Panel");
timeDisplay.setFont(new java.awt.Font("Tahoma", 0, 36));
timeDisplay.setForeground( new java.awt.Color(204, 0, 0));
timeDisplay.setHorizontalA lignment(j avax.swing .SwingCons tants.CENT ER);
timeDisplay.setText("00:00 :00");
javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jP anel1);
jPanel1.setLayout(jPanel1L ayout);
jPanel1Layout.setHorizonta lGroup(jPa nel1Layout .createPar allelGroup (javax.swi ng.GroupLa yout.Align ment.LEADI NG).addCom ponent(tim eDisplay, javax.swing.GroupLayout.DE FAULT_SIZE , 439, Short.MAX_VALUE).addCompon ent(jLabel 1, javax.swing.GroupLayout.DE FAULT_SIZE , 439, Short.MAX_VALUE));
jPanel1Layout.setVerticalG roup(jPane l1Layout.c reateParal lelGroup(j avax.swing .GroupLayo ut.Alignme nt.LEADING ).addGroup (jPanel1La yout.creat eSequentia lGroup().a ddContaine rGap().add Component( jLabel1, javax.swing.GroupLayout.PR EFERRED_SI ZE, 26, javax.swing.GroupLayout.PR EFERRED_SI ZE).addPre ferredGap( javax.swin g.LayoutSt yle.Compon entPlaceme nt.RELATED ).addCompo nent(timeD isplay, javax.swing.GroupLayout.DE FAULT_SIZE , 47, Short.MAX_VALUE).addContai nerGap())) ;
jPanel2.setBackground(new java.awt.Color(0, 0, 0));
modeDisplay.setBackground( new java.awt.Color(255, 255, 255));
modeDisplay.setEditable(fa lse);
modeDisplay.setFont(new java.awt.Font("Tahoma", 1, 12));
modeDisplay.setHorizontalA lignment(j avax.swing .JTextFiel d.CENTER);
javax.swing.GroupLayout jPanel2Layout = new javax.swing.GroupLayout(jP anel2);
jPanel2.setLayout(jPanel2L ayout);
jPanel2Layout.setHorizonta lGroup(jPa nel2Layout .createPar allelGroup (javax.swi ng.GroupLa yout.Align ment.LEADI NG).addGro up(jPanel2 Layout.cre ateSequent ialGroup() .addGap(15 2, 152, 152).addComponent(modeDisp lay, javax.swing.GroupLayout.PR EFERRED_SI ZE, 129, javax.swing.GroupLayout.PR EFERRED_SI ZE).addCon tainerGap( 158, Short.MAX_VALUE)));
jPanel2Layout.setVerticalG roup(jPane l2Layout.c reateParal lelGroup(j avax.swing .GroupLayo ut.Alignme nt.LEADING ).addCompo nent(modeD isplay, javax.swing.GroupLayout.Al ignment.TR AILING, javax.swing.GroupLayout.DE FAULT_SIZE , 33, Short.MAX_VALUE));
jPanel3.setBackground(new java.awt.Color(255, 255, 255));
modeButton.setBackground(n ew java.awt.Color(0, 0, 0));
modeButton.setFont(new java.awt.Font("Tahoma", 1, 11));
modeButton.setForeground(n ew java.awt.Color(255, 255, 255));
modeButton.setText("Mode") ;
modeButton.addActionListen er(new java.awt.event.ActionListe ner()
{
public void actionPerformed(java.awt.e vent.Actio nEvent evt)
{
event(evt);
}
});
okButton.setBackground(new java.awt.Color(0, 0, 0));
okButton.setFont(new java.awt.Font("Tahoma", 1, 11));
okButton.setForeground(new java.awt.Color(255, 255, 255));
okButton.setText("OK");
okButton.addActionListener (new java.awt.event.ActionListe ner()
{
public void actionPerformed(java.awt.e vent.Actio nEvent evt)
{
event(evt);
}
});
okButton.addActionListener (alarmButt onSelectAc tion);
hourButton.setBackground(n ew java.awt.Color(0, 0, 0));
hourButton.setFont(new java.awt.Font("Tahoma", 1, 11));
hourButton.setForeground(n ew java.awt.Color(255, 255, 255));
hourButton.setText("Hour") ;
hourButton.addActionListen er(new java.awt.event.ActionListe ner()
{
public void actionPerformed(java.awt.e vent.Actio nEvent evt)
{
event(evt);
}
});
hourButton.addActionListen er(alarmBu ttonSelect Action);
minutesButton.setBackgroun d(new java.awt.Color(0, 0, 0));
minutesButton.setFont(new java.awt.Font("Tahoma", 1, 11));
minutesButton.setForegroun d(new java.awt.Color(255, 255, 255));
minutesButton.setText("Min utes");
minutesButton.addActionLis tener(new java.awt.event.ActionListe ner()
{
public void actionPerformed(java.awt.e vent.Actio nEvent evt)
{
event(evt);
}
});
minutesButton.addActionLis tener(alar mButtonSel ectAction) ;
recordButton.setBackground (new java.awt.Color(0, 0, 0));
recordButton.setFont(new java.awt.Font("Tahoma", 1, 11));
recordButton.setForeground (new java.awt.Color(255, 255, 255));
recordButton.setText("Reco rd");
recordButton.addActionList ener(new java.awt.event.ActionListe ner()
{
public void actionPerformed(java.awt.e vent.Actio nEvent evt)
{
event(evt);
}
});
playButton.setBackground(n ew java.awt.Color(0, 0, 0));
playButton.setFont(new java.awt.Font("Tahoma", 1, 11));
playButton.setForeground(n ew java.awt.Color(255, 255, 255));
playButton.setText("Play") ;
playButton.addActionListen er(new java.awt.event.ActionListe ner()
{
public void actionPerformed(java.awt.e vent.Actio nEvent evt)
{
event(evt);
}
});
fastButton.setBackground(n ew java.awt.Color(0, 0, 0));
fastButton.setFont(new java.awt.Font("Tahoma", 1, 11));
fastButton.setForeground(n ew java.awt.Color(255, 255, 255));
fastButton.setText("Fast") ;
fastButton.addActionListen er(new java.awt.event.ActionListe ner()
{
public void actionPerformed(java.awt.e vent.Actio nEvent evt)
{
event(evt);
}
});
stopButton.setBackground(n ew java.awt.Color(0, 0, 0));
stopButton.setFont(new java.awt.Font("Tahoma", 1, 11));
stopButton.setForeground(n ew java.awt.Color(255, 255, 255));
stopButton.setText("Stop") ;
stopButton.addActionListen er(new java.awt.event.ActionListe ner()
{
public void actionPerformed(java.awt.e vent.Actio nEvent evt)
{
event(evt);
}
});
upButton.setBackground(new java.awt.Color(0, 0, 0));
upButton.setFont(new java.awt.Font("Tahoma", 1, 11));
upButton.setForeground(new java.awt.Color(255, 255, 255));
upButton.setText("Up");
upButton.addActionListener (new java.awt.event.ActionListe ner()
{
public void actionPerformed(java.awt.e vent.Actio nEvent evt)
{
event(evt);
}
});
upButton.addActionListener (alarmButt onSelectAc tion);
downButton.setBackground(n ew java.awt.Color(0, 0, 0));
downButton.setFont(new java.awt.Font("Tahoma", 1, 11));
downButton.setForeground(n ew java.awt.Color(255, 255, 255));
downButton.setText("Down") ;
downButton.addActionListen er(new java.awt.event.ActionListe ner()
{
public void actionPerformed(java.awt.e vent.Actio nEvent evt)
{
event(evt);
}
});
downButton.addActionListen er(alarmBu ttonSelect Action);
javax.swing.GroupLayout jPanel3Layout = new javax.swing.GroupLayout(jP anel3);
jPanel3.setLayout(jPanel3L ayout);
jPanel3Layout.setHorizonta lGroup(jPa nel3Layout .createPar allelGroup (javax.swi ng.GroupLa yout.Align ment.LEADI NG).addGro up(jPanel3 Layout.cre ateSequent ialGroup() .addContai nerGap().a ddGroup(jP anel3Layou t.createPa rallelGrou p(javax.sw ing.GroupL ayout.Alig nment.LEAD ING).addGr oup(jPanel 3Layout.cr eateSequen tialGroup( ).addCompo nent(modeB utton).add PreferredG ap(javax.s wing.Layou tStyle.Com ponentPlac ement.RELA TED).addCo mponent(ho urButton). addPreferr edGap(java x.swing.La youtStyle. ComponentP lacement.R ELATED).ad dComponent (recordBut ton).addPr eferredGap (javax.swi ng.LayoutS tyle.Compo nentPlacem ent.RELATE D).addComp onent(fast Button).ad dPreferred Gap(javax. swing.Layo utStyle.Co mponentPla cement.REL ATED).addC omponent(u pButton)). addGroup(j Panel3Layo ut.createS equentialG roup().add Component( okButton). addPreferr edGap(java x.swing.La youtStyle. ComponentP lacement.R ELATED).ad dComponent (minutesBu tton).addP referredGa p(javax.sw ing.Layout Style.Comp onentPlace ment.RELAT ED).addCom ponent(pla yButton).a ddPreferre dGap(javax .swing.Lay outStyle.C omponentPl acement.RE LATED).add Component( stopButton ).addPrefe rredGap(ja vax.swing. LayoutStyl e.Componen tPlacement .RELATED). addCompone nt(downBut ton))).add ContainerG ap(javax.s wing.Group Layout.DEF AULT_SIZE, Short.MAX_VALUE)));
jPanel3Layout.linkSize(jav ax.swing.S wingConsta nts.HORIZO NTAL, new java.awt.Component[]{downB utton, fastButton, hourButton, minutesButton, modeButton, okButton, playButton, recordButton, stopButton, upButton});
jPanel3Layout.setVerticalG roup(jPane l3Layout.c reateParal lelGroup(j avax.swing .GroupLayo ut.Alignme nt.LEADING ).addGroup (jPanel3La yout.creat eSequentia lGroup().a ddContaine rGap().add Group(jPan el3Layout. createPara llelGroup( javax.swin g.GroupLay out.Alignm ent.BASELI NE).addCom ponent(mod eButton).a ddComponen t(fastButt on).addCom ponent(upB utton).add Component( recordButt on).addCom ponent(hou rButton, javax.swing.GroupLayout.PR EFERRED_SI ZE, 22, javax.swing.GroupLayout.PR EFERRED_SI ZE)).addPr eferredGap (javax.swi ng.LayoutS tyle.Compo nentPlacem ent.RELATE D, 15, Short.MAX_VALUE).addGroup( jPanel3Lay out.create ParallelGr oup(javax. swing.Grou pLayout.Al ignment.BA SELINE).ad dComponent (okButton) .addCompon ent(minute sButton).a ddComponen t(playButt on).addCom ponent(sto pButton).a ddComponen t(downButt on)).addGa p(19, 19, 19)));
jPanel3Layout.linkSize(jav ax.swing.S wingConsta nts.VERTIC AL, new java.awt.Component[]{downB utton, fastButton, minutesButton, modeButton, okButton, playButton, recordButton, stopButton, upButton});
javax.swing.GroupLayout layout = new javax.swing.GroupLayout(ge tContentPa ne());
getContentPane().setLayout (layout);
layout.setHorizontalGroup( layout.cre ateParalle lGroup(jav ax.swing.G roupLayout .Alignment .LEADING). addGroup(j avax.swing .GroupLayo ut.Alignme nt.TRAILIN G, layout.createSequentialGro up().addCo ntainerGap ().addGrou p(layout.c reateParal lelGroup(j avax.swing .GroupLayo ut.Alignme nt.TRAILIN G).addComp onent(jPan el3, javax.swing.GroupLayout.Al ignment.LE ADING, javax.swing.GroupLayout.DE FAULT_SIZE , javax.swing.GroupLayout.DE FAULT_SIZE , Short.MAX_VALUE).addCompon ent(jPanel 2, javax.swing.GroupLayout.Al ignment.LE ADING, javax.swing.GroupLayout.DE FAULT_SIZE , javax.swing.GroupLayout.DE FAULT_SIZE , Short.MAX_VALUE).addCompon ent(jPanel 1, javax.swing.GroupLayout.DE FAULT_SIZE , javax.swing.GroupLayout.DE FAULT_SIZE , Short.MAX_VALUE)).addConta inerGap()) );
layout.setVerticalGroup(la yout.creat eParallelG roup(javax .swing.Gro upLayout.A lignment.L EADING).ad dGroup(lay out.create Sequential Group().ad dContainer Gap().addC omponent(j Panel1, javax.swing.GroupLayout.PR EFERRED_SI ZE, javax.swing.GroupLayout.DE FAULT_SIZE , javax.swing.GroupLayout.PR EFERRED_SI ZE).addPre ferredGap( javax.swin g.LayoutSt yle.Compon entPlaceme nt.RELATED ).addCompo nent(jPane l2, javax.swing.GroupLayout.PR EFERRED_SI ZE, javax.swing.GroupLayout.DE FAULT_SIZE , javax.swing.GroupLayout.PR EFERRED_SI ZE).addGap (14, 14, 14).addComponent(jPanel3, javax.swing.GroupLayout.PR EFERRED_SI ZE, javax.swing.GroupLayout.DE FAULT_SIZE , javax.swing.GroupLayout.PR EFERRED_SI ZE).addCon tainerGap( javax.swin g.GroupLay out.DEFAUL T_SIZE, Short.MAX_VALUE)));
pack();
}// </editor-fold>
private void event(java.awt.event.Actio nEvent evt)
{
// TODO add your handling code here:
}
/**
* @param args the command line arguments
*/
public static void main(String args[])
{
java.awt.EventQueue.invoke Later(new Runnable()
{
public void run()
{
new GuiPanel().setVisible(true );
}
});
}
// Variables declaration - do not modify
private javax.swing.JButton downButton;
private javax.swing.JButton fastButton;
private javax.swing.JButton hourButton;
private javax.swing.JLabel jLabel1;
private javax.swing.JPanel jPanel1;
private javax.swing.JPanel jPanel2;
private javax.swing.JPanel jPanel3;
private javax.swing.JButton minutesButton;
private javax.swing.JButton modeButton;
private javax.swing.JTextField modeDisplay;
private javax.swing.JButton okButton;
private javax.swing.JButton playButton;
private javax.swing.JButton recordButton;
private javax.swing.JButton stopButton;
private javax.swing.JLabel timeDisplay;
private javax.swing.JButton upButton;
private JLabel alarmTempDisplay;
// End of variables declaration
public javax.swing.JLabel getTimeDisplay()
{
return timeDisplay;
}
public void setTimeDisplay(javax.swing .JLabel timeDisplay)
{
this.timeDisplay = timeDisplay;
}
/**
* @param prn
*/
public void setDispProvider(DispTime prn)
{
dispProv = prn;
}
private DispTime dispProv;
}
import javax.swing.*;
import java.util.ArrayList;
import javax.swing.AbstractAction
import java.awt.event.ActionEvent
import java.awt.event.ActionEvent
import java.lang.*;
import javax.swing.JLabel;
import java.awt.event.ActionEvent
import javax.swing.JLabel;
public class GuiPanel extends javax.swing.JFrame
{
enum Mode {
CLOCK, ALARM, TIMER, AUDIO, DATE, REMINDERS, CUSTOM,
};
private java.util.List<Mode> modes;
private int modeIndex;
private Mode currentMode;
boolean alarmStarted = false;
public String alarmTime;
// private/** Creates new form GuiPanel */
public GuiPanel()
{
initComponents();
initModes();
}
private void initModes()
{
modes = new java.util.ArrayList<Mode>(
for (Mode m : Mode.values())
{
modes.add(m);
}
modeButton.setAction(new AdvanceModeAction("Mode"))
advanceMode(); // Advance mode to Clock
}
private class AdvanceModeAction extends javax.swing.AbstractAction
{
public AdvanceModeAction(String name)
{
super(name);
}
public void actionPerformed(java.awt.e
{
advanceMode();
enableAllButtons();
if (currentMode == Mode.ALARM)
{
recordButton.setEnabled(fa
playButton.setEnabled(fals
stopButton.setEnabled(fals
fastButton.setEnabled(fals
alarmTempDisplay = new JLabel(timeDisplay.getText
alarmStarted = false;
dispProv.setDispListener(a
}
else if (currentMode == Mode.AUDIO)
{
hourButton.setEnabled(fals
minutesButton.setEnabled(f
}
else if (currentMode == Mode.CLOCK)
{
recordButton.setEnabled(fa
playButton.setEnabled(fals
stopButton.setEnabled(fals
}
else if (currentMode == Mode.DATE)
{
recordButton.setEnabled(fa
playButton.setEnabled(fals
stopButton.setEnabled(fals
}
else if (currentMode == Mode.TIMER)
{
recordButton.setEnabled(fa
playButton.setEnabled(fals
stopButton.setEnabled(fals
dispProv.setDispListener(t
}
}
}
private class AlarmButtonSelectAction extends javax.swing.AbstractAction
{
public final int HR = 0;
public final int MIN = 1;
int selected = -1;
public void actionPerformed(ActionEven
{
String cmd = e.getActionCommand();
if (currentMode == Mode.ALARM)
{
if (cmd.equals(hourButton.get
{
selected = HR;
}
else if (cmd.equals(minutesButton.
{
selected = MIN;
}
else if (cmd.equals(upButton.getTe
{
if (selected == HR)
{
String time = timeDisplay.getText();
String[] splitTime = time.split(":");
int hr = Integer.parseInt(splitTime
time = Integer.toString(hr + 1) + ":" + splitTime[1] + ":" + splitTime[2];
timeDisplay.setText(time);
}
else if (selected == MIN)
{
String time = timeDisplay.getText();
String[] splitTime = time.split(":");
int min = Integer.parseInt(splitTime
time = splitTime[0] + ":" + Integer.toString(min + 1) + ":" + splitTime[2];
timeDisplay.setText(time);
}
}
else if (cmd.equals(downButton.get
{
if (selected == HR)
{
String time = timeDisplay.getText();
String[] splitTime = time.split(":");
int hr = Integer.parseInt(splitTime
time = Integer.toString(hr - 1) + ":" + splitTime[1] + ":" + splitTime[2];
timeDisplay.setText(time);
}
else if (selected == MIN)
{
String time = timeDisplay.getText();
String[] splitTime = time.split(":");
int min = Integer.parseInt(splitTime
time = splitTime[0] + ":" + Integer.toString(min - 1) + ":" + splitTime[2];
timeDisplay.setText(time);
}
}
else if (cmd.equals(okButton.getTe
{
//time should be stored in alarmDisplay
alarmStarted = true;
alarmTime = timeDisplay.getText();
selected = HR;
currentMode = Mode.CLOCK;
modeDisplay.setText (currentMode.toString());
dispProv.setDispListener(t
selected = -1;
}
}
}
}
private void enableAllButtons()
{
downButton.setEnabled(true
fastButton.setEnabled(true
hourButton.setEnabled(true
minutesButton.setEnabled(t
modeButton.setEnabled(true
okButton.setEnabled(true);
playButton.setEnabled(true
recordButton.setEnabled(tr
stopButton.setEnabled(true
upButton.setEnabled(true);
}
private void advanceMode()
{
currentMode = modes.get(modeIndex++ % modes.size());
modeDisplay.setText(curren
}
void getModeDisplay()
{
currentMode = modes.get(modeIndex++ % modes.size());
}
/** This method is called from within the constructor to
* initialize the form.
* WARNING: Do NOT modify this code. The content of this method is
* always regenerated by the Form Editor.
*/
// <editor-fold defaultstate="collapsed" desc=" Generated Code ">
private void initComponents()
{
jPanel1 = new javax.swing.JPanel();
jLabel1 = new javax.swing.JLabel();
timeDisplay = new javax.swing.JLabel();
jPanel2 = new javax.swing.JPanel();
modeDisplay = new javax.swing.JTextField();
jPanel3 = new javax.swing.JPanel();
modeButton = new javax.swing.JButton();
okButton = new javax.swing.JButton();
hourButton = new javax.swing.JButton();
minutesButton = new javax.swing.JButton();
recordButton = new javax.swing.JButton();
playButton = new javax.swing.JButton();
fastButton = new javax.swing.JButton();
stopButton = new javax.swing.JButton();
upButton = new javax.swing.JButton();
downButton = new javax.swing.JButton();
AlarmButtonSelectAction alarmButtonSelectAction = new AlarmButtonSelectAction();
setDefaultCloseOperation(j
setResizable(false);
jPanel1.setBackground(new java.awt.Color(255, 255, 255));
jLabel1.setFont(new java.awt.Font("Tahoma", 2, 18));
jLabel1.setForeground(new java.awt.Color(51, 51, 255));
jLabel1.setHorizontalAlign
jLabel1.setText("Audio Reminder Panel");
timeDisplay.setFont(new java.awt.Font("Tahoma", 0, 36));
timeDisplay.setForeground(
timeDisplay.setHorizontalA
timeDisplay.setText("00:00
javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jP
jPanel1.setLayout(jPanel1L
jPanel1Layout.setHorizonta
jPanel1Layout.setVerticalG
jPanel2.setBackground(new java.awt.Color(0, 0, 0));
modeDisplay.setBackground(
modeDisplay.setEditable(fa
modeDisplay.setFont(new java.awt.Font("Tahoma", 1, 12));
modeDisplay.setHorizontalA
javax.swing.GroupLayout jPanel2Layout = new javax.swing.GroupLayout(jP
jPanel2.setLayout(jPanel2L
jPanel2Layout.setHorizonta
jPanel2Layout.setVerticalG
jPanel3.setBackground(new java.awt.Color(255, 255, 255));
modeButton.setBackground(n
modeButton.setFont(new java.awt.Font("Tahoma", 1, 11));
modeButton.setForeground(n
modeButton.setText("Mode")
modeButton.addActionListen
{
public void actionPerformed(java.awt.e
{
event(evt);
}
});
okButton.setBackground(new
okButton.setFont(new java.awt.Font("Tahoma", 1, 11));
okButton.setForeground(new
okButton.setText("OK");
okButton.addActionListener
{
public void actionPerformed(java.awt.e
{
event(evt);
}
});
okButton.addActionListener
hourButton.setBackground(n
hourButton.setFont(new java.awt.Font("Tahoma", 1, 11));
hourButton.setForeground(n
hourButton.setText("Hour")
hourButton.addActionListen
{
public void actionPerformed(java.awt.e
{
event(evt);
}
});
hourButton.addActionListen
minutesButton.setBackgroun
minutesButton.setFont(new java.awt.Font("Tahoma", 1, 11));
minutesButton.setForegroun
minutesButton.setText("Min
minutesButton.addActionLis
{
public void actionPerformed(java.awt.e
{
event(evt);
}
});
minutesButton.addActionLis
recordButton.setBackground
recordButton.setFont(new java.awt.Font("Tahoma", 1, 11));
recordButton.setForeground
recordButton.setText("Reco
recordButton.addActionList
{
public void actionPerformed(java.awt.e
{
event(evt);
}
});
playButton.setBackground(n
playButton.setFont(new java.awt.Font("Tahoma", 1, 11));
playButton.setForeground(n
playButton.setText("Play")
playButton.addActionListen
{
public void actionPerformed(java.awt.e
{
event(evt);
}
});
fastButton.setBackground(n
fastButton.setFont(new java.awt.Font("Tahoma", 1, 11));
fastButton.setForeground(n
fastButton.setText("Fast")
fastButton.addActionListen
{
public void actionPerformed(java.awt.e
{
event(evt);
}
});
stopButton.setBackground(n
stopButton.setFont(new java.awt.Font("Tahoma", 1, 11));
stopButton.setForeground(n
stopButton.setText("Stop")
stopButton.addActionListen
{
public void actionPerformed(java.awt.e
{
event(evt);
}
});
upButton.setBackground(new
upButton.setFont(new java.awt.Font("Tahoma", 1, 11));
upButton.setForeground(new
upButton.setText("Up");
upButton.addActionListener
{
public void actionPerformed(java.awt.e
{
event(evt);
}
});
upButton.addActionListener
downButton.setBackground(n
downButton.setFont(new java.awt.Font("Tahoma", 1, 11));
downButton.setForeground(n
downButton.setText("Down")
downButton.addActionListen
{
public void actionPerformed(java.awt.e
{
event(evt);
}
});
downButton.addActionListen
javax.swing.GroupLayout jPanel3Layout = new javax.swing.GroupLayout(jP
jPanel3.setLayout(jPanel3L
jPanel3Layout.setHorizonta
jPanel3Layout.linkSize(jav
jPanel3Layout.setVerticalG
jPanel3Layout.linkSize(jav
javax.swing.GroupLayout layout = new javax.swing.GroupLayout(ge
getContentPane().setLayout
layout.setHorizontalGroup(
layout.setVerticalGroup(la
pack();
}// </editor-fold>
private void event(java.awt.event.Actio
{
// TODO add your handling code here:
}
/**
* @param args the command line arguments
*/
public static void main(String args[])
{
java.awt.EventQueue.invoke
{
public void run()
{
new GuiPanel().setVisible(true
}
});
}
// Variables declaration - do not modify
private javax.swing.JButton downButton;
private javax.swing.JButton fastButton;
private javax.swing.JButton hourButton;
private javax.swing.JLabel jLabel1;
private javax.swing.JPanel jPanel1;
private javax.swing.JPanel jPanel2;
private javax.swing.JPanel jPanel3;
private javax.swing.JButton minutesButton;
private javax.swing.JButton modeButton;
private javax.swing.JTextField modeDisplay;
private javax.swing.JButton okButton;
private javax.swing.JButton playButton;
private javax.swing.JButton recordButton;
private javax.swing.JButton stopButton;
private javax.swing.JLabel timeDisplay;
private javax.swing.JButton upButton;
private JLabel alarmTempDisplay;
// End of variables declaration
public javax.swing.JLabel getTimeDisplay()
{
return timeDisplay;
}
public void setTimeDisplay(javax.swing
{
this.timeDisplay = timeDisplay;
}
/**
* @param prn
*/
public void setDispProvider(DispTime prn)
{
dispProv = prn;
}
private DispTime dispProv;
}
I'd suggest using a set of Radio buttons, or a JComboBox to allow the user to select mode
ASKER
I hate java layout, I'm going to bed talk with you next time. thanks for all the help.
JComboBox solves some of the layout issues (as you only have a single control to place).
Also allows you to store Mode objects directly in model
pieces u would need would be:
// create your model, containing all your modes
private ComboBoxModel modes = new DefaultComboBoxModel(new Object[] {
new ClockMode(),
new AlarmMode(), .... });
// create a combo to display your modes, allowing user to change mode
JComboBox modes = new JComboBox(modes);
// add a listener to update label when mode changes
modes.addActionListener(ne w ModeLabelUpdater(modeLabel ));
// add a method to return the current mode
public Mode getMode()
{
return (Mode) modes.getSelectedItem();
}
// the listener class to update the label
public class ModeLabelUpdater implements ActionListener
{
private JLabel label = null;
private ModeLabelUpdater(JLabel label)
{
this.label = label;
}
public void actionPerformed(ActionEven t event)
{
label.setText(getMode().ge tLabel());
}
}
Also allows you to store Mode objects directly in model
pieces u would need would be:
// create your model, containing all your modes
private ComboBoxModel modes = new DefaultComboBoxModel(new Object[] {
new ClockMode(),
new AlarmMode(), .... });
// create a combo to display your modes, allowing user to change mode
JComboBox modes = new JComboBox(modes);
// add a listener to update label when mode changes
modes.addActionListener(ne
// add a method to return the current mode
public Mode getMode()
{
return (Mode) modes.getSelectedItem();
}
// the listener class to update the label
public class ModeLabelUpdater implements ActionListener
{
private JLabel label = null;
private ModeLabelUpdater(JLabel label)
{
this.label = label;
}
public void actionPerformed(ActionEven
{
label.setText(getMode().ge
}
}
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Hello objects you are not going to like this but i don't like the layout that i am coming up with. Either I stick with what I have or I am going to have to come up with a whole different GUI. I don't really see the way it is as being a problem with people interfacing with. People are not that stupid. I have a plan for help that will make it very easy to learn to use.
There's absolutely no need to tear up your already working code. As it happens, the shortish case statement with enum is one of the more readable sections IMO ;-)
ASKER
Hi CEHJ: I wondered about this myself. I did like the idea of using different listeners for the different buttons, because i could get rid of some of the IF else statements. I would like so help to clean up the exisiting code. What do you think about using the listeners for the up, down, hour, minutes buttons because they do the same things always. I feel a little lost now about what to do. I don't want to use radioButton or combobox for the modes, I think the mode button with the OK button is fine. I like the way the GUI looks now. Give me your feedback, I'm learning on this end and you guys are the teachers.
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
The code you gave me was for the button Enabling, not for changing the hours and minutes of the time. If what is being looked at is just the text of the mode there isn't really anything happening really as it would be with a listener, So isn't this a pretty secure approach? I included the code you gave me below.
private class AdvanceModeAction extends javax.swing.AbstractAction
{
public AdvanceModeAction(String name)
{
super(name);
}
public void actionPerformed(java.awt.e vent.Actio nEvent e)
{
advanceMode();
enableAllButtons();
switch (currentMode)
{
case Alarm:
recordButton.setEnabled(fa lse);
playButton.setEnabled(fals e);
stopButton.setEnabled(fals e);
fastButton.setEnabled(fals e);
alarmTempDisplay = new JLabel(timeDisplay.getText ());
alarmStarted = false;
dispProv.setDispListener(a larmTempDi splay);
break;
case Audio:
hourButton.setEnabled(fals e);
minutesButton.setEnabled(f alse);
break;
case Clock:
recordButton.setEnabled(fa lse);
playButton.setEnabled(fals e);
stopButton.setEnabled(fals e);
break;
case Date:
recordButton.setEnabled(fa lse);
playButton.setEnabled(fals e);
stopButton.setEnabled(fals e);
break;
case Timer:
recordButton.setEnabled(fa lse);
stopButton.setText("Reset" );
fastButton.setEnabled(true ); // changes like these
fastButton.setText("Reset" ); // changes like these
playButton.setEnabled(fals e);
stopButton.setEnabled(fals e);
dispProv.setDispListener(t imeDisplay );
break;
dispProv.setDispListener(t imeDisplay );
break;
}
}
}
If you look at the code in the question it is looking at the text of the current mode. If I used a listener for the hourButton, minutesButton, upButton and DownButton events then I could get rid of some of the If and else statements and wouldn't that make the code more readable as well? It is important to me that i approach this project with as much consciousness and awareness as possible. This way i am doing in action what is the right way to approach object programing. I already approached the beginning of the project from object modeling from my understanding of it, which came from the book "Beginning Java Objects from concepts to code" So even my layout of the GUI came from me trying to be in the users point of view. I don't want to waste anybodies time or energy here at E.E. but i also want to be able to draw upon you experience as a collective, not any individual here. I know that everyone has their own approach to things but to be set upon any direction is to cut ourselves off from learning. I want all of you that help me with this project to be present and real with what you feel and why in your communication in the threads we are in. This will help expand my understanding in the real world of code writing which will help me to be able to think in ways that i might not be able to if i hadn't went through these experiences with you. So please help me in what i am trying to do and support me to be a good programmer.
private class AdvanceModeAction extends javax.swing.AbstractAction
{
public AdvanceModeAction(String name)
{
super(name);
}
public void actionPerformed(java.awt.e
{
advanceMode();
enableAllButtons();
switch (currentMode)
{
case Alarm:
recordButton.setEnabled(fa
playButton.setEnabled(fals
stopButton.setEnabled(fals
fastButton.setEnabled(fals
alarmTempDisplay = new JLabel(timeDisplay.getText
alarmStarted = false;
dispProv.setDispListener(a
break;
case Audio:
hourButton.setEnabled(fals
minutesButton.setEnabled(f
break;
case Clock:
recordButton.setEnabled(fa
playButton.setEnabled(fals
stopButton.setEnabled(fals
break;
case Date:
recordButton.setEnabled(fa
playButton.setEnabled(fals
stopButton.setEnabled(fals
break;
case Timer:
recordButton.setEnabled(fa
stopButton.setText("Reset"
fastButton.setEnabled(true
fastButton.setText("Reset"
playButton.setEnabled(fals
stopButton.setEnabled(fals
dispProv.setDispListener(t
break;
dispProv.setDispListener(t
break;
}
}
}
If you look at the code in the question it is looking at the text of the current mode. If I used a listener for the hourButton, minutesButton, upButton and DownButton events then I could get rid of some of the If and else statements and wouldn't that make the code more readable as well? It is important to me that i approach this project with as much consciousness and awareness as possible. This way i am doing in action what is the right way to approach object programing. I already approached the beginning of the project from object modeling from my understanding of it, which came from the book "Beginning Java Objects from concepts to code" So even my layout of the GUI came from me trying to be in the users point of view. I don't want to waste anybodies time or energy here at E.E. but i also want to be able to draw upon you experience as a collective, not any individual here. I know that everyone has their own approach to things but to be set upon any direction is to cut ourselves off from learning. I want all of you that help me with this project to be present and real with what you feel and why in your communication in the threads we are in. This will help expand my understanding in the real world of code writing which will help me to be able to think in ways that i might not be able to if i hadn't went through these experiences with you. So please help me in what i am trying to do and support me to be a good programmer.
An if and a switch are the same thing :-D
suggestion to use a JComboBox was just for your interest as you appeared to be struggling with layouts, and a combo can greatluy simplify a guis layout.
Where you need work is in you gui's wiring, how it looks to the user is up to u :)
You still haven't explained what gui elements you are using to allow user to change mode. Let me that and I'll show you how best to wire it up.
Where you need work is in you gui's wiring, how it looks to the user is up to u :)
You still haven't explained what gui elements you are using to allow user to change mode. Let me that and I'll show you how best to wire it up.
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
I am a little lost with what to do with this question. We have cover things that are not in this question, how should I handle this? I raised the points to 500 because of so many answers. Give me your feedback OK.
split between all involved and start a new question for any specific questions you have.
ASKER
objects: what is meant here, please exlain it, i have looked but can't find anything that explains it to be. I know what a source file is it is the written code in a file uncompiled..
CEHJ:To ensure accessibility it would probably be better to compile
public enum Mode {
Clock, Date, Alarm, Timer, Audio, Custom,
}
in its own source files
CEHJ:To ensure accessibility it would probably be better to compile
public enum Mode {
Clock, Date, Alarm, Timer, Audio, Custom,
}
in its own source files
He's saying put the enum in its own file, but as I've explained you don't even need an enum. It just results in a proliferation of if/switch statements and offers no real benefits.
ASKER
That was what I thought but it said it didn't need tobe wrapped in a class because it was a class. But I didn't see any other way to compile it. I want to know how to handle this now that it has come to my awareness.
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
objects:
I am finally getting what you mean about the use of listeners. I see that if a different listener is with each mode the action of the button changes as well because it is dealing with another listener. That was what i was having trouble getting. They are different actions because the relationship with the mode is different. I sure hope i got it. This keeps the code simple and very readable as long as you make the names of your listeners clear. This was a little more advanced then for a beginner i think, am i right? I enjoy working with you, I will learn what is important from you which will have a big impact on me being able to write good code. Thanks for all you help and time, it is much appreciated. By the way my name is Christopher
I am finally getting what you mean about the use of listeners. I see that if a different listener is with each mode the action of the button changes as well because it is dealing with another listener. That was what i was having trouble getting. They are different actions because the relationship with the mode is different. I sure hope i got it. This keeps the code simple and very readable as long as you make the names of your listeners clear. This was a little more advanced then for a beginner i think, am i right? I enjoy working with you, I will learn what is important from you which will have a big impact on me being able to write good code. Thanks for all you help and time, it is much appreciated. By the way my name is Christopher
:-)