I am writing a paint program like the MSpaint, and my instructor specifically asked us to use the older methods in Java and the buttons must not be from the awt package. I am having trouble since the textbook demonstrated double buffering and the author says the flicker problem will disappear after adding the update method; but I am still having the flicker problem. Plus my program isn't fuctioning when I click the color buttons. Can anyone give my some hints on what I'm doing wrong here?

import java.applet.Applet;
import java.awt.*;
public class test2 extends Applet
 
{
	Image virtualMem;
	Graphics gBuffer;
	int oldX, oldY, newX, newY;
	int appletWidth;
	int appletHeight;
	int boxWidth;
	int boxHeight;
 
	Rectangle box;
	Rectangle color;         //UI click box for Color selection)
	Rectangle red;			 
	Rectangle yellow;		 
	Rectangle blue;			
	Rectangle green;
	Rectangle black;
	Rectangle pen;			 //UI click box for Pen tool
	int numColor, numTool, xClick, yClick;
 
public void init()
{
	setSize(1024,768);
	repaint();
	boxWidth = 700;
	boxHeight = 500;
	virtualMem = createImage(boxWidth,boxHeight);
	gBuffer = virtualMem.getGraphics();
	gBuffer.setColor(Color.white);
	gBuffer.fillRect(0,0,boxWidth,boxHeight);
 
 
 
 
 
	numColor = 1;							//sets default color&tool
	numTool = 1;
 
	box = new Rectangle(0,0,700,500);
 
	color = new Rectangle(5,5,55,280);		 //initiate UI click box for Colors
	red = new Rectangle(10,10,45,45);
	yellow = new Rectangle(10,60,45,45);
	blue = new Rectangle(10,110,45,45);
	green = new Rectangle(10,160,45,45);
	black = new Rectangle(10,210,45,45);
 
	pen = new Rectangle(10,290,45,60);	
}
public void paint(Graphics g)
{
	gBuffer.setColor(Color.black);
	gBuffer.drawLine(oldX,oldY,newX,newY);
	g.drawImage(virtualMem,0,0,this);
 
 
 
 
 
 
	g.drawRect(0, 0, 700, 500);
 
	g.drawRect(705, 5, 55, 280);			 //UI text Color
	g.drawString("Color", 717, 275);
 
	g.setColor(Color.red);				 //UI text Red, yellow, ...
	g.fillRect(710, 10, 45, 45);
	g.setColor(Color.yellow);
	g.fillRect(710, 60, 45, 45);
	g.setColor(Color.blue);
	g.fillRect(710, 110, 45, 45);
	g.setColor(Color.green);
	g.fillRect(710, 160, 45, 45);
	g.setColor(Color.black);
	g.fillRect(710, 210, 45, 45);
 
	g.setColor(Color.black);
	g.drawRect(710,290,45,60);
 
 
	switch (numColor) {					//Action when clicking each Color
	case 1:
		g.setColor(Color.red);
		break;
	case 2:
		g.setColor(Color.yellow);
		break;
	case 3:
		g.setColor(Color.blue);
		break;
	case 4:
		g.setColor(Color.green);
		break;
	case 5:
		g.setColor(Color.black);
		break;
	}
 
	switch (numTool) {					// Action when selected Tool (Pen, erase...)
	case 1:
		g.fillRect(xClick, yClick, 2, 2);
		break;
	case 2:
		g.fillRect(xClick, yClick, 2, 2);
		break;
	case 3:
		g.fillRect(xClick, yClick, 2, 2);
		break;
	case 4:
		g.fillRect(xClick, yClick, 2, 2);
		break;
	case 5:
		g.fillRect(xClick, yClick, 2, 2);
		break;
	}
}
public boolean mouseDown(Event e, int x, int y)
{
	if (color.inside(x, y)){								// If mouse inside color control area, initiate following selections
 
		if (red.inside(x, y)) {
		numColor = 1;
		}
		else if (yellow.inside(x, y)) {
		numColor = 2;
		}
		else if (blue.inside(x, y)) {
		numColor = 3;
		}
		else if (green.inside(x, y)) {
		numColor = 4;
		}
		else if (black.inside(x, y)) {
		numColor = 5;
		}			
	}
	else if (pen.inside(x, y)){
		newX = x;
		newY = y;
	}
 
	xClick = x;
	yClick = y;
	repaint();
	return true;
}
public boolean mouseDrag(Event e, int x, int y)
{
	newX = x;
	newY = y;
	oldX = newX;
	oldY = newY;
	repaint();
	return true;
}
public void update(Graphics g)
{
	paint(g);
}
}