473,614 Members | 2,352 Online
Bytes | Software Development & Data Engineering Community
+ 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 21757
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
26519
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 face=arial size=3>line3</font></td></tr> </table>
4
4238
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 Win XP development machine as both the browser and Web server. However if I try to display the same page from another machine (Mac OS X, Win 2000, or Win XP) using the Win XP development machine as the Web server then I get the default font...
32
3932
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 Latin-1 on your page. The reference test page is http://www.unics.uni-hannover.de/nhtcapri/temp/arial.html This http://www.unics.uni-hannover.de/nhtcapri/temp/face-arial.gif is the horrible result in Mozilla 1.3 on Mac OS 9.1 when I do
20
12398
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. http://www.aczoom.com/isongs/0/t_ff.html is the test page - that has shows the line "This is using CSS to specify xdvng:" show up with the default english font instead of xdvng. Internet Explorer works as expected - both CSS and FONT FACE use of
34
2404
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 Bill Gate$ selling his stock in droves. 2. Linux marketshare is eating up windos. So when all is said and done, the wogs won't have much left for them, will they?
3
3056
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 the comments work etc and everything is intergrated nicely in the database. Now im parsing the comments back out to the user and replacing string like :) with emoticons etc. It works perfectly and i'm seriously pleased with myself (ok ok remember i...
3
18424
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
1516
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
1247
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 need above functionality. Regards
0
8198
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8142
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8642
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
8591
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
7115
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
4058
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
2575
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 we have to send another system
1
1758
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
1438
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 can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.