package awt;
import java.awt.*;
public class GraphicPanel extends Panel {
	GraphicPanel() {
		setBackground(Color.black);
	}
	public void paint(Graphics g) {
		g.setColor(new Color(0,255,0));
		g.setFont(new Font("Helvetical", Font.PLAIN,14));
		g.drawString("Pusyy Cat Program!", 300, 100);
		g.drawOval(150,200,50,50);
		g.drawOval(200,200,30,30);
		g.setColor(new Color(1.0f,0,0));
		g.fillRect(30,100,150,10);
	}
	public static void main(String[] args) {
		Frame f = new Frame("Pussy Cat Window");
		GraphicPanel gp = new GraphicPanel();
		f.add(gp);
		f.setSize(300,300);
		f.setVisible(true);
	}
}

//Here is my problem in java using awt.........please help me to create a simple Mouse(animal) using awt..Thnx...............

Dani AI

Generated

Brief practical plan: two simple routes exist — paint the mouse from primitive shapes (ovals/arcs/lines) or draw a pre-made image. As suggested, an image is quickest; drawing with AWT is better for learning and for easy scaling/animation. called out an error; common display problems in these examples are coordinates outside the component, misspelled font names, and not handling window closing. 's request for clarification suggests a concise, reproducible recipe will help.

How to compose a mouse from shapes (no full code here, just a clear recipe):

  • Decide a drawing area and use relative coordinates (percent of width/height) so the mouse scales when the window is resized.
  • Draw a large filled oval for the body, a smaller filled oval offset for the head, two small filled ovals or arcs at the top of the head for ears, small filled ovals for eyes, a small filled oval/triangle for the nose, short lines radiating for whiskers, and an arc/curved line for the tail.
  • Use Graphics2D and enable antialiasing for smoother curves and text.
  • Keep all shape coordinates inside the component bounds (use getWidth()/getHeight() to compute positions).

Small, practical checks and fixes:

  • Avoid naming the app package awt (it conflicts conceptually with java.awt).
  • Verify color constructors (use new Color(255,0,0) for ints or new Color(1f,0f,0f) for floats).
  • For flicker in AWT, either override update(Graphics) to call paint(g) or draw to an offscreen image and blit it (double buffering).
  • Always add a WindowListener so the Frame actually closes.

Enable antialiasing example:

Graphics2D g2 = (Graphics2D) g;
g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING,
                    RenderingHints.VALUE_ANTIALIAS_ON);

Reference reading: Oracle Java painting concepts and the Graphics2D API are useful starting points: Painting in AWT/Swing and Graphics2D Javadoc.

Recommended Answers

All 4 Replies

Ismael_Jay,
(0) Error Found.

what do u exactly want us to do?

You could download a picture of a mouse and then paint that image. Or, you could always get some mice from under my stove - I think that's where they're all hiding.

how to make a simple mouse(animal)with a head.body,ears..................................setting the graphic panel

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.