import java.awt.*;
import javax.swing.*;
import java.awt.Color;
import java.awt.event.*;
import javax.swing.event.*;
import java.io.File;
import java.util.*;
/*
<Applet Code="MyPaint.class" width=400 height=400>
</Applet>
*/
public class MyPaint extends JFrame
{
/* Declaring the variables.*/
JPanel panel;
JPanel textAreaPanel;
JTextArea drawTextArea;
JScrollPane drawScrollPane;
JLabel line, color, paint,kid,cil;
JButton circle, rect, poly, ellipse;
JComboBox cbLine, cbFill;
GridBagLayout g;
GridBagConstraints gbc;
public void init()
{
g=new GridBagLayout();
gbc=new GridBagConstraints();
panel= (JPanel)getContentPane();
panel.setLayout(g);
paint = new JLabel("My Paint Application");
gbc.anchor= GridBagConstraints.NORTH;
gbc.gridx =2;
gbc.gridy = 0;
g.setConstraints(paint,gbc);
panel.add(paint);
rect = new JButton("Rectangle");
gbc.ipadx = 2;
gbc.ipady = 2;
gbc.gridy = 1;
gbc.gridx = 1;
g.setConstraints(rect,gbc);
panel.add(rect);
circle = new JButton("Circle");
gbc.ipadx = 2;
gbc.ipady = 2;
gbc.gridy = 1;
gbc.gridx = 2;
g.setConstraints(circle,gbc);
panel.add(circle);
poly = new JButton("Polygon");
gbc.ipadx = 2;
gbc.ipady = 2;
gbc.gridy = 1;
gbc.gridx = 3;
g.setConstraints(poly,gbc);
panel.add(poly);
ellipse = new JButton("Ellipse");
gbc.ipadx = 2;
gbc.ipady = 2;
gbc.gridy = 1;
gbc.gridx = 4;
g.setConstraints(ellipse,gbc);
panel.add(ellipse);
line = new JLabel("select line color");
gbc.ipadx = 4;
gbc.ipady = 4;
gbc.gridy = 2;
gbc.gridx = 1;
g.setConstraints(line,gbc);
panel.add(line);
kid = new JLabel("");
gbc.ipadx = 4;
gbc.ipady = 4;
gbc.gridy = 2;
gbc.gridx = 2;
g.setConstraints(kid,gbc);
panel.add(kid);
color = new JLabel("select Fill color");
gbc.ipadx = 4;
gbc.ipady = 4;
gbc.gridy = 2;
gbc.gridx = 3;
g.setConstraints(color,gbc);
panel.add(color);
String Line[]={"choose the color","Red","Yellow","Green","Blue","Cyan","Mangeta","Orange"};
cbLine = new JComboBox(Line);
gbc.fill= GridBagConstraints.BOTH;
gbc.insets=new Insets(5,5,5,5);
gbc.ipadx = 4;
gbc.ipady = 4;
gbc.gridy = 3;
gbc.gridx = 1;
g.setConstraints(cbLine,gbc);
panel.add(cbLine);
cil = new JLabel("");
gbc.ipadx = 4;
gbc.ipady = 4;
gbc.gridy = 3;
gbc.gridx = 2;
g.setConstraints(cil,gbc);
panel.add(cil);
String Fill[]={"choose the color","Red","Yellow","Green","Blue","Cyan","Mangeta","Orange"};
cbFill = new JComboBox(Fill);
gbc.fill= GridBagConstraints.BOTH;
gbc.insets=new Insets(5,5,5,5);
gbc.ipadx = 4;
gbc.ipady = 4;
gbc.gridy = 3;
gbc.gridx = 3;
g.setConstraints(cbFill,gbc);
panel.add(cbFill);
Color c =new Color(250,100,100);
Container contentpane= getContentPane();
textAreaPanel = new JPanel(new GridLayout(2,1,5,5));
drawTextArea = new JTextArea();
drawScrollPane = new JScrollPane(drawTextArea);
textAreaPanel.add(drawScrollPane);
textAreaPanel.setLayout(g);
textAreaPanel= (JPanel)getContentPane();
contentpane.add(textAreaPanel,BorderLayout.SOUTH);
}
public static void main(String[] args)
{
MyPaint mp = new MyPaint();
mp.setSize(700,500);
mp.setVisible(true);
}
}

That isn't an applet. It's a JFrame. You cannot run a JFrame as an applet.

when i changed it to JApplet. it gives the same problem. pls, assist

How are you trying to run it and what is the exact text of the message. Remember that you cannot run applets with the normal "java MyPaint" command.

don't forget code tags either
send us updated code too

I also got samely problem, so heres two applet codes, fist works and the second doesn't, I need the second one to work, I guess code has no matter with this stuff, It gives no error, but once I run it appletviewer window "Start: applet not initialized."
please respond anyone as soon as possible
thanks

import java.awt.*;
import java.applet.*;
import java.awt.event.*;

/*
<applet code = "WindowEvents" width =400 height = 290>
</applet>
*/
class Cords{
	public int X;
	public int Y;
}


public class WindowEvents extends Applet
implements MouseListener, MouseMotionListener{
	String msg = "";
	int count = 1;
	Cords cords[] = new Cords[count];
	int mouseX = 200, mouseY = 200;
	public void init(){
		addMouseListener(this);
		addMouseMotionListener(this);
	}
	public void stop(){
	}
	public void start(){
	}
	public void mouseClicked(MouseEvent me){
	
	}
	
	public void mouseEntered(MouseEvent me){
		//mouseX = 0;
		//mouseY = 24;
		//repaint();
	}
	//handle mouse exited.
	public void mouseExited(MouseEvent me){
		//mouseX = 0;
		//mouseY = 24;
		//repaint();
	}
	public void mousePressed(MouseEvent me){
		mouseX = me.getX();
		mouseY = me.getY();
		repaint();
	}
	public void mouseReleased(MouseEvent me){
		//mouseX = me.getX();
		//mouseY = me.getY();
		//repaint();
	}
	public void mouseDragged(MouseEvent me){
		//mouseX = me.getX();
		//mouseY = me.getY();
		//repaint();
	}
	public void mouseMoved(MouseEvent me){
		//movX = me.getX();
		//movY = me.getY();
		//repaint(0,0,100,20);
	}
	public void paint(Graphics g){
		for(int i = 0; i < 5; i++){
			mouseX += 50 * -1;
			mouseY += 50 * -1;
			g.fillOval(mouseX-5, mouseY-5, 10, 10);
		}
	}
}

^this is first .. that is running without error...

import java.awt.*;
import java.applet.*;
import java.awt.event.*;


/*
<applet code = "WindowEvents" width =400 height = 290>
</applet>
*/



public class WindowEvents extends Applet
implements MouseListener, MouseMotionListener{
	String msg = "";
	int count = 1, i = 0;
	Cords cords[] = new Cords[count];
	int mouseX = 200, mouseY = 200;
	public void init(){
		cords[0].X = cords[0].Y = mouseX;
		this.addMouseListener(this);
		this.addMouseMotionListener(this);
		//setBackground(Color.red);
	}
	public void stop(){
	}
	public void start(){
	}
	public void mouseClicked(MouseEvent me){
		if (me.getClickCount() == 2){
    			count++;
    			Cords crds[] = new Cords[count];
    			for(i = 0; i < count-1; i++){
    				crds[i].X = cords[i].X;
    				crds[i].Y = cords[i].Y;
    			}
    			cords = new Cords [count];
    			for(i = 0; i < count-1; i++){
    				cords[i].X = crds[i].X;
    				cords[i].Y = crds[i].Y;
    			}
    		}else{
    			boolean b = false;	
    		}
    		repaint();
	}
	
		public void mouseEntered(MouseEvent me){
		//mouseX = 0;
		//mouseY = 24;
		//repaint();
	}
	//handle mouse exited.
	public void mouseExited(MouseEvent me){
		//mouseX = 0;
		//mouseY = 24;
		//repaint();
	}
	public void mousePressed(MouseEvent me){
		mouseX = me.getX();
		mouseY = me.getY();
		repaint();
	}
	public void mouseReleased(MouseEvent me){
		//mouseX = me.getX();
		//mouseY = me.getY();
		//repaint();
	}
	public void mouseDragged(MouseEvent me){
		//mouseX = me.getX();
		//mouseY = me.getY();
		//repaint();
	}
	public void mouseMoved(MouseEvent me){
		//movX = me.getX();
		//movY = me.getY();
		//repaint(0,0,100,20);
	}
	public void paint(Graphics g){
		for(i = 0; i < cords.length; i++){
			g.fillOval(cords[i].X-5, cords[i].Y-5, 10, 10);
		}
	}
}

and this is second one

Look in the browser's java console for an error message.

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.