LBryant777
IS-IT--Management
Here I am again:
This time, I am attempting to create a smiley face (done) with a button that will change the smile from a frown (my problem). I believe I'm almost there, but I'm missing something that is probably relatively simple...
My code:
I know it is the code in the ActionPerformed() method that is my problem, but I don't know what to change. Can someone tell me what I am doing wrong? I appreciate all responses, provided you give comments also so that I can learn from my mistakes! Thanks in advance!
This time, I am attempting to create a smiley face (done) with a button that will change the smile from a frown (my problem). I believe I'm almost there, but I'm missing something that is probably relatively simple...
My code:
Code:
import java.applet.*;
import java.awt.*;
import java.awt.event.*;
public class SmileFace_me extends Applet implements ActionListener {
Button moodChange = new Button("Change my mood...");
private boolean Mood = true;
public void init() {
add(moodChange);
moodChange.addActionListener(this);
}
public void paint(Graphics g) {
g.setColor(Color.yellow);
g.fillOval(130, 100, 150, 150);
g.setColor(Color.black);
g.fillOval(180, 130, 15, 25);
g.fillOval(220, 130, 15, 25);
g.drawArc(155, 160, 100, 60, 180, 180);
}
public void actionPerformed(ActionEvent e) {
if (Mood){
Mood = false;
e.drawArc(155, 190, 100, 60, 180, -180);
}
else {
Mood = true;
e.drawArc(155, 160, 100, 60, 180, 180);
}
}
}
I know it is the code in the ActionPerformed() method that is my problem, but I don't know what to change. Can someone tell me what I am doing wrong? I appreciate all responses, provided you give comments also so that I can learn from my mistakes! Thanks in advance!