meltyrain
Junior Member
- Joined
- Jun 30, 2013
- Messages
- 6
- Reaction score
- 0
This was asked:
a. Write an application that extends JFrame and that displays a yellow smiling face on
the screen. Save the file as JSmileFace.java.
b. Add a JButton to the JSmileFace program so the smile changes to a frown when
the user clicks the JButton. Save the file as JSmileFace2.java.
and my code for JSmileFace
// JSmileFace.java
import javax.swing.*;
import java.awt.*;
public class JSmileFace{
public static void main(String[] args) {
JSmileFace j = new JSmileFace();
}
public JSmileFace(){
JFrame frame = new JFrame("JSmileFace");
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.getContentPane().add(new MyComponent());
frame.setSize(400,400);
frame.setVisible(true);
}
public class MyComponent extends JComponent{
public void paint(Graphics g){
g.setColor(Color.yellow);
g.drawOval(100, 50, 200, 200);
g.setColor(Color.yellow);
g.fillOval(100,50,200,200);
g.setColor(Color.BLACK);
g.fillOval(155, 100, 10, 20);
g.fillOval(230, 100, 10, 20);
g.setColor(Color.BLACK);
g.drawArc(150, 160, 100, 50, 180, 180);
}}
}
public static void main(String[] args)
{
}
Now, my problem is the JSmileFace2 I have no idea on how I would start with it.
I need advice, ideas on how I will solve this problem and tips also where I need to learn about this that
can be applied also out here.
Thank you
a. Write an application that extends JFrame and that displays a yellow smiling face on
the screen. Save the file as JSmileFace.java.
b. Add a JButton to the JSmileFace program so the smile changes to a frown when
the user clicks the JButton. Save the file as JSmileFace2.java.
and my code for JSmileFace
// JSmileFace.java
import javax.swing.*;
import java.awt.*;
public class JSmileFace{
public static void main(String[] args) {
JSmileFace j = new JSmileFace();
}
public JSmileFace(){
JFrame frame = new JFrame("JSmileFace");
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.getContentPane().add(new MyComponent());
frame.setSize(400,400);
frame.setVisible(true);
}
public class MyComponent extends JComponent{
public void paint(Graphics g){
g.setColor(Color.yellow);
g.drawOval(100, 50, 200, 200);
g.setColor(Color.yellow);
g.fillOval(100,50,200,200);
g.setColor(Color.BLACK);
g.fillOval(155, 100, 10, 20);
g.fillOval(230, 100, 10, 20);
g.setColor(Color.BLACK);
g.drawArc(150, 160, 100, 50, 180, 180);
}}
}
public static void main(String[] args)
{
}
Now, my problem is the JSmileFace2 I have no idea on how I would start with it.
I need advice, ideas on how I will solve this problem and tips also where I need to learn about this that
can be applied also out here.
Thank you