473,487 Members | 2,711 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

smiley face

30 New Member
Hi i have a homework on drawing a smiley face then pressing a button to draw a sad face i have some code but nothing works i keep getting an error on my action performed method. can you please look and give me some tips thanx
Expand|Select|Wrap|Line Numbers
  1. import javax.swing.*;
  2. import java.awt.*;
  3. import java.awt.event.*;
  4. import java.awt.event.*;
  5.  
  6.  
  7.  
  8. public class Face extends JFrame implements ActionListener 
  9. {
  10.  
  11.   FacePanel mmp = new FacePanel();
  12.   private JButton smile = new JButton ("Smile");
  13.   private JButton sad = new JButton ("Sad");
  14.  
  15.  
  16.   public Face() 
  17.   {
  18.       JPanel p1 = new JPanel();
  19.        p1.setLayout(new GridLayout(4,2));
  20.     add(mmp);
  21.     JButton smile = new JButton("Smile");    
  22.         add(smile);                            
  23.         smile.addActionListener(this);        
  24.  
  25.         // The applet has a "Sad" button
  26.         JButton sad = new JButton("Sad");        
  27.         add(sad);
  28.         sad.addActionListener(this);
  29.  
  30.     setTitle("Smiley Face");
  31.     setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
  32.     setSize(600, 400);
  33.     setVisible(true);
  34.   }
  35.  
  36.   public void actionPerformed(ActionEvent e);
  37.   {
  38.       String cmd = e.getActionCommand();
  39.  
  40.         if (cmd.equals("Smile")) {            // "Smile" was pressed
  41.             SMILE = true;
  42.             setBackground(Color.yellow);
  43.             repaint();
  44.         }
  45.         else if (cmd.equals("Sad")) {        // "Sad" 
  46.                 SMILE = false;
  47.                 setBackground(Color.lightGray);
  48.                 repaint();
  49.         }
  50.  
  51.   if (smile) {
  52.             g.drawArc(70, 95, 60, 60, 225, 90);
  53.         } 
  54.         else {
  55.             g.drawArc(70, 145, 60, 60, 45, 90);
  56.         }
  57.  
  58.  
  59.  
  60.  
  61.   }
  62.  
  63.  
  64.  
  65.  
  66. }
  67.  
  68.  
  69. public class FaceDriver
  70. {
  71.   public static void main(String args[])
  72.   {
  73.     Face smiley = new Face();
  74.  
  75.   }
  76. }
  77.  
  78.  
  79. import java.awt.* ;
  80. import javax.swing.* ;
  81.  
  82. class FacePanel extends JPanel
  83. {
  84.   public void paintComponent(Graphics g)
  85.   {
  86.           //smiley face
  87.         final int MID=150;
  88.         final int TOP=50;
  89.  
  90.           g.setColor (Color.red);
  91.         g.drawOval(100,25,175,175);
  92.         g.setColor(Color.black);
  93.         g.drawOval(135,75,25,25);
  94.         g.setColor(Color.black);
  95.         g.drawOval(200,75,25,25);
  96.         g.drawArc(MID+10,TOP+100,60,20,190,175);
  97.  
  98.  
  99.  
  100.   }
  101. }
Mar 25 '07 #1
4 21726
horace1
1,510 Recognized Expert Top Contributor
you have a ; on the of the line
Expand|Select|Wrap|Line Numbers
  1.   public void actionPerformed(ActionEvent e);
  2.  
which makes the compiler think there is no code for the method
Mar 25 '07 #2
cazconv2007
30 New Member
i've changed that but still have an error it says that my face class is not abstract
Mar 25 '07 #3
horace1
1,510 Recognized Expert Top Contributor
i've changed that but still have an error it says that my face class is not abstract
if I remove the ; and recompile the message about the abstract class goes away and I get a few more messages starting with
Expand|Select|Wrap|Line Numbers
  1. Face.java:42: cannot find symbol
  2. symbol  : variable SMILE
  3. location: class Face
  4.                         SMILE = true;
  5.                         ^
  6.  
Mar 25 '07 #4
mdsalmanhussain
1 New Member
the corrected one...

Expand|Select|Wrap|Line Numbers
  1. import javax.swing.*;
  2. import java.awt.*;
  3. import java.awt.event.*;
  4. import java.awt.event.*;
  5.  
  6.  
  7.  
  8. class Face extends JFrame implements ActionListener 
  9. {
  10.  int a1,a2,a3,a4,a5,a6,b1,b2,b3,b4,b5,b6;
  11.   FacePanel mmp = new FacePanel();
  12.   private JButton smile = new JButton ("Smile");
  13.   private JButton sad = new JButton ("Sad");
  14.  boolean smilee;
  15.  
  16.   public Face() 
  17.   {
  18.       JPanel p1 = new JPanel();
  19.        p1.setLayout(new GridLayout(4,2));
  20.     add(mmp);
  21.    // JButton smile = new JButton("Smile");    
  22.         add(smile);                            
  23.         smile.addActionListener(this);        
  24.  
  25.         // The applet has a "Sad" button
  26.      //   JButton sad = new JButton("Sad");        
  27.         add(sad);
  28.         sad.addActionListener(this);
  29.  
  30.     setTitle("Smiley Face");
  31.     setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
  32.     setSize(600, 400);
  33.     setVisible(true);
  34.   }
  35.  
  36.   public void actionPerformed(ActionEvent e)
  37.   {
  38.       String cmd = e.getActionCommand();
  39.  
  40.         if (cmd.equals("Smile")) {            // "Smile" was pressed
  41.             smilee = true;
  42.             setBackground(Color.yellow);
  43.             repaint();
  44.         }
  45.         else if (cmd.equals("Sad")) {        // "Sad" 
  46.               smilee = false;
  47.                 setBackground(Color.lightGray);
  48.                 repaint();
  49.         }
  50.  
  51.   if (smilee) {
  52.          //   g.drawArc(70, 95, 60, 60, 225, 90);
  53.             a1=70;a2=95;a3=a4=60;a5=225;a6=90;
  54.  
  55.         } 
  56.         else {
  57.             //g.drawArc(70, 145, 60, 60, 45, 90);
  58.             b1=70;b2=145;b3=b4=60;b5=45;b6=90;
  59.         }
  60.     }
  61.  public void paint(Graphics g){
  62.         g.drawArc(a1,a2,a3,a4,a5,a6);
  63.         g.drawArc(b1,b2,b3,b4,b5,b6);
  64.     }
  65.  
  66.  
  67.  
  68.   }
  69.  
  70.  
  71.  
  72.  
  73.  
  74.  
  75.  
  76. public class examplesmiley
  77. {
  78.   public static void main(String args[])
  79.   {
  80.     Face smiley = new Face();
  81.  
  82.   }
  83. }
  84.  
  85.  
  86.  
  87.  
  88. class FacePanel extends JPanel
  89. {
  90.   public void paintComponent(Graphics g)
  91.   {
  92.           //smiley face
  93.         final int MID=150;
  94.         final int TOP=50;
  95.  
  96.           g.setColor (Color.red);
  97.         g.drawOval(100,25,175,175);
  98.         g.setColor(Color.black);
  99.         g.drawOval(135,75,25,25);
  100.         g.setColor(Color.black);
  101.         g.drawOval(200,75,25,25);
  102.         g.drawArc(MID+10,TOP+100,60,20,190,175);
  103.  
  104.  
  105.  
  106.   }
  107. }
Apr 16 '13 #5

Sign in to post your reply or Sign up for a free account.

Similar topics

2
26505
by: Isaac Grover | last post by:
Hi everyone, Rather than have this construct in my pages: <table> <tr><td><font face=arial size=3>line1</font></td></tr> <tr><td><font face=arial size=3>line2</font></td></tr> <tr><td><font...
4
4226
by: Clive Everett | last post by:
I thought it would be rather fun to try out @font-face, but I cannot get it to work. I used Microsoft WEFT to generate several embedded fonts and find that the example below works when I use my...
32
3902
by: Andreas Prilop | last post by:
Here is an illustration of the warning http://ppewww.ph.gla.ac.uk/~flavell/charset/browsers-fonts.html#dont that you should not specify a typeface when you have characters outside West European...
20
12369
by: B Wooster | last post by:
There is a page that shows Firefox 1.0 render text differently for CSS as compared to FONT FACE for one particular font: http://www.aczoom.com/fonts/xdvng.ttf is the font that does not work. ...
34
2370
by: Justin Timberlake | last post by:
I was thinking about all those /Indian Outsourcing/ companies getting those .Net shops set up. 0. Nobody uses .NET in the real world, it's all java. 1. MSFT is about to collapse as witnessed by...
3
3044
by: descds | last post by:
OK im prety much a newbie at PHP but it has me hooked. Im writing a comment system for one of our modules on phpnuke. Its all going very well, well should i say WAS going very well :) Ok all...
3
18415
by: laredotornado | last post by:
Hello, is there any cross-browser html code to generate a little "Have a nice day" happy face, or any happy face? Have a nice day, - Dave
8
1508
by: studyandjobs | last post by:
Computer Industry Workers May Face Cancer Risks http://www.studyandjobs.com/Comp_worker_cancer.html or visit http://www.studyandjobs.com/Cancer.html Regards
3
1238
by: Hamed | last post by:
Hello Is it possible to get a control (e.g. a checkbox) and make a Graphics object or a Bitmap object of current face of the control? I want to implement Sparse property for a ColumnStyle so I...
0
6967
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
7137
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
7181
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
7349
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
4565
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
3071
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
1381
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
1
600
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
267
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.