- import java.awt.*;
-
import java.applet.Applet;
-
import java.awt.event.*;
-
-
public class Smiley extends Applet implements ActionListener
-
{
-
/**
-
*
-
*/
-
private static final long serialVersionUID = 1L;
-
private boolean SMILE = true;
-
private final Font f = new Font("Helvetica", Font.PLAIN, 9);
-
-
public void init() { // Define the GUI
-
-
// The applet has a "Smile" button
-
final Button smileButton = new Button("Smile"); // create button
-
add(smileButton); // add to applet's GUI
-
smileButton.addActionListener(this); // register event listener
-
-
// The applet has a "Sad" button
-
final Button sadButton = new Button("Sad");
-
add(sadButton);
-
sadButton.addActionListener(this);
-
-
// set initial background
-
setBackground(Color.lightGray);
-
-
} // end of init
-
-
public void actionPerformed(final ActionEvent e) { // The event handler
-
-
// Get the command (which button was pressed?)
-
final String cmd = e.getActionCommand();
-
-
if (cmd.equals("Smile")) { // "Smile" was pressed
-
SMILE = true;
-
setBackground(Color.lightGray);
-
repaint();
-
}
-
else if (cmd.equals("Sad")) { // "Sad"
-
SMILE = false;
-
setBackground(Color.lightGray);
-
repaint();
-
}
-
-
} // end of actionPerformed
-
-
-
public void paint( final Graphics g ) {
-
// draw the face
-
-
g.setColor( Color.YELLOW );
-
g.fillOval( 10, 10, 200, 200 );
-
-
-
-
// draw the eyes
-
-
g.setColor( Color.BLACK );
-
g.fillOval( 55, 65, 30, 30 );
-
-
// draw the mouth
-
-
g.fillOval( 135, 65, 30, 30 );
-
g.fillOval( 50, 110, 120, 60 );
-
-
-
-
// Draw smiley or sad
-
if (SMILE) {
-
-
// "touch up" the mouth into a smile
-
g.setColor( Color.YELLOW );
-
g.fillRect( 50, 110, 120, 30 );
-
g.fillOval( 50, 120, 120, 40 );
-
-
}
-
else {
-
// "touch up" the mouth into a smile to get sad face
-
g.setColor( Color.YELLOW );
-
g.fillRect( 50, 110, 120, 30 );
-
g.fillOval( 50, 120, 120, 40 );
-
}
-
-
// SIGNATURE: Write signature
-
g.setFont(f);
-
g.drawString("Applet by Deepak.", 1, 199);
-
} // end of paint
-
} // end of class Smiley
1 3084
part to be touch up to get the sad face - // "touch up" the mouth into a smile
-
g.setColor( Color.YELLOW );
-
g.fillRect( 50, 110, 120, 30 );// touch up here
-
g.fillOval( 50, 120, 120, 40 ); // touch up here
Sign in to post your reply or Sign up for a free account.
Similar topics
by: Sean Kessinger |
last post by:
Thanks, John. Here is the article:
http://support.microsoft.com/default.aspx?scid=kb;;821546
I tried the suggestions from this article but still the same problem.
No-touch deployment works on...
| |
by: George Hester |
last post by:
Best done using Microsoft Internet Explorer but I believe Netscape may do OK not sure. I have one itsy bitsy little problem here. The tabbing? No forget that I got a few gray hairs with that and...
|
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...
|
by: tatata9999 |
last post by:
Currently my site is not using CSS. The thing I want to do with it
is, I think, it needs a face lift, otherwise, it may look boring,
target audience seems very much into visual stuff, flushy,...
|
by: eternity |
last post by:
hello need to know hw oracle databese works. how it can be used.plse need help urgent to get started.
|
by: hani |
last post by:
hi. i'm a newbie on c# and asp.net.
sorry if this is a stupid questions.
a. i put a treeview in my parent page. called 'TreeView1'
b. i need to add a new tree node inside TreeView1
Is it...
|
by: Dansmith122 |
last post by:
Hi
I have been working on the java script for my website and I need help with the out put variables. I need to know how to add more variable for each row in my survey. I am very lost
...
|
by: Phillis2013 |
last post by:
#include <stdlib.h>
#include <stdio.h>
#include <ctime>
#include <string>
#include <iostream>
using namespace std;
int main()
{
srand ( time(NULL) );
|
by: yanalvine |
last post by:
import java.util.Scanner; // program uses class Scanner
import java.awt.Color;
import java.awt.Graphics;
import javax.swing.JPanel;
public class person {
private String firstName;...
|
by: ryjfgjl |
last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
|
by: emmanuelkatto |
last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud.
Please let me know.
Thanks!
Emmanuel
|
by: BarryA |
last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
|
by: Sonnysonu |
last post by:
This is the data of csv file
1 2 3
1 2 3
1 2 3
1 2 3
2 3
2 3
3
the lengths should be different i have to store the data by column-wise with in the specific length.
suppose the i have to...
|
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,...
|
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...
|
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,...
|
by: Hystou |
last post by:
Overview:
Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
|
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...
| |