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 -
import javax.swing.*;
-
import java.awt.*;
-
import java.awt.event.*;
-
import java.awt.event.*;
-
-
-
-
public class Face extends JFrame implements ActionListener
-
{
-
-
FacePanel mmp = new FacePanel();
-
private JButton smile = new JButton ("Smile");
-
private JButton sad = new JButton ("Sad");
-
-
-
public Face()
-
{
-
JPanel p1 = new JPanel();
-
p1.setLayout(new GridLayout(4,2));
-
add(mmp);
-
JButton smile = new JButton("Smile");
-
add(smile);
-
smile.addActionListener(this);
-
-
// The applet has a "Sad" button
-
JButton sad = new JButton("Sad");
-
add(sad);
-
sad.addActionListener(this);
-
-
setTitle("Smiley Face");
-
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
-
setSize(600, 400);
-
setVisible(true);
-
}
-
-
public void actionPerformed(ActionEvent e);
-
{
-
String cmd = e.getActionCommand();
-
-
if (cmd.equals("Smile")) { // "Smile" was pressed
-
SMILE = true;
-
setBackground(Color.yellow);
-
repaint();
-
}
-
else if (cmd.equals("Sad")) { // "Sad"
-
SMILE = false;
-
setBackground(Color.lightGray);
-
repaint();
-
}
-
-
if (smile) {
-
g.drawArc(70, 95, 60, 60, 225, 90);
-
}
-
else {
-
g.drawArc(70, 145, 60, 60, 45, 90);
-
}
-
-
-
-
-
}
-
-
-
-
-
}
-
-
-
public class FaceDriver
-
{
-
public static void main(String args[])
-
{
-
Face smiley = new Face();
-
-
}
-
}
-
-
-
import java.awt.* ;
-
import javax.swing.* ;
-
-
class FacePanel extends JPanel
-
{
-
public void paintComponent(Graphics g)
-
{
-
//smiley face
-
final int MID=150;
-
final int TOP=50;
-
-
g.setColor (Color.red);
-
g.drawOval(100,25,175,175);
-
g.setColor(Color.black);
-
g.drawOval(135,75,25,25);
-
g.setColor(Color.black);
-
g.drawOval(200,75,25,25);
-
g.drawArc(MID+10,TOP+100,60,20,190,175);
-
-
-
-
}
-
}
4 21757 horace1 1,510
Recognized Expert Top Contributor
you have a ; on the of the line -
public void actionPerformed(ActionEvent e);
-
which makes the compiler think there is no code for the method
i've changed that but still have an error it says that my face class is not abstract
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 -
Face.java:42: cannot find symbol
-
symbol : variable SMILE
-
location: class Face
-
SMILE = true;
-
^
-
the corrected one... - import javax.swing.*;
-
import java.awt.*;
-
import java.awt.event.*;
-
import java.awt.event.*;
-
-
-
-
class Face extends JFrame implements ActionListener
-
{
-
int a1,a2,a3,a4,a5,a6,b1,b2,b3,b4,b5,b6;
-
FacePanel mmp = new FacePanel();
-
private JButton smile = new JButton ("Smile");
-
private JButton sad = new JButton ("Sad");
-
boolean smilee;
-
-
public Face()
-
{
-
JPanel p1 = new JPanel();
-
p1.setLayout(new GridLayout(4,2));
-
add(mmp);
-
// JButton smile = new JButton("Smile");
-
add(smile);
-
smile.addActionListener(this);
-
-
// The applet has a "Sad" button
-
// JButton sad = new JButton("Sad");
-
add(sad);
-
sad.addActionListener(this);
-
-
setTitle("Smiley Face");
-
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
-
setSize(600, 400);
-
setVisible(true);
-
}
-
-
public void actionPerformed(ActionEvent e)
-
{
-
String cmd = e.getActionCommand();
-
-
if (cmd.equals("Smile")) { // "Smile" was pressed
-
smilee = true;
-
setBackground(Color.yellow);
-
repaint();
-
}
-
else if (cmd.equals("Sad")) { // "Sad"
-
smilee = false;
-
setBackground(Color.lightGray);
-
repaint();
-
}
-
-
if (smilee) {
-
// g.drawArc(70, 95, 60, 60, 225, 90);
-
a1=70;a2=95;a3=a4=60;a5=225;a6=90;
-
-
}
-
else {
-
//g.drawArc(70, 145, 60, 60, 45, 90);
-
b1=70;b2=145;b3=b4=60;b5=45;b6=90;
-
}
-
}
-
public void paint(Graphics g){
-
g.drawArc(a1,a2,a3,a4,a5,a6);
-
g.drawArc(b1,b2,b3,b4,b5,b6);
-
}
-
-
-
-
}
-
-
-
-
-
-
-
-
public class examplesmiley
-
{
-
public static void main(String args[])
-
{
-
Face smiley = new Face();
-
-
}
-
}
-
-
-
-
-
class FacePanel extends JPanel
-
{
-
public void paintComponent(Graphics g)
-
{
-
//smiley face
-
final int MID=150;
-
final int TOP=50;
-
-
g.setColor (Color.red);
-
g.drawOval(100,25,175,175);
-
g.setColor(Color.black);
-
g.drawOval(135,75,25,25);
-
g.setColor(Color.black);
-
g.drawOval(200,75,25,25);
-
g.drawArc(MID+10,TOP+100,60,20,190,175);
-
-
-
-
}
-
}
Sign in to post your reply or Sign up for a free account.
Similar topics |
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>
|
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...
|
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
|
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
|
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?
| |
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...
|
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
|
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
|
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
|
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...
|
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,...
| |
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...
|
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...
|
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...
|
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...
|
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
|
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
| |
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...
| |