fatjoy25 0 Newbie Poster
import java.awt.*;
import java.lang.Math;
import javax.swing.*;
import javax.swing.event.*;
import java.awt.event.*;
import java.awt.Graphics;
import java.applet.Applet;
/*
<APPLET
CODE=draw.class
WIDTH=600
HEIGHT=200 >
</APPLET>
*/
public class draw extends JApplet implements 

ActionListener, MouseListener,
MouseMotionListener {
Button bDraw,bOval, bRect, bRounded,bHeading;
Point dot[] = new Point[1000];
JComboBox cbLine,cbFill;
Point start, end;
int dots = 0;
boolean mouseUp = false;
boolean draw = false;
boolean line = false;
boolean oval = false;
boolean rectangle = false;
boolean rounded = false;
Font font;

public void init()
{
getContentPane();
font= new Font("Monospaced", Font.BOLD, 24);
bHeading = new Button("MY   PAINT   APPLICATION");
bHeading.setSize(500,40);
bHeading.setLocation(300,40);
bHeading.setFont(font);
bHeading.setForeground(Color.white.brighter());
bHeading.setBackground(Color.blue.brighter());
getContentPane();
bOval = new Button("Circle");
bOval.setSize(100,30);
bOval.setLocation(300,100);
bOval.setForeground(Color.green.brighter());
bOval.setFont(new Font("Arial", Font.BOLD, 16));
bRect = new Button("Rectangles");
bRect.setSize(100,30);
bRect.setLocation(500,100);
bRect.setForeground(Color.red.brighter());
bRect.setFont(new Font("Arial", Font.BOLD, 16));
bRounded = new Button("Ellipse");
bRounded .setSize(100,30);
bRounded .setLocation(700,100);
bRounded.setForeground(Color.blue.brighter());
bRounded.setFont(new Font("Arial", Font.BOLD, 16));
bDraw = new Button("Polygon");
bDraw.setSize(100,30);
bDraw.setLocation(900,100);
bDraw.setForeground(Color.yellow.brighter());
bDraw.setFont(new Font("Arial", Font.BOLD, 16));
setLayout(null);
String Line[]={"choose the 

color","Red","Yellow","Green","Blue","Cyan","Manget

a","Orange"};
cbLine = new JComboBox(Line);
cbLine.setSize(200,30);
cbLine.setLocation(220,170);
cbLine.setForeground(Color.white.brighter());
cbLine.setBackground(Color.green.brighter());
cbLine.setFont(new Font("Arial", Font.BOLD, 16));
String Fill[]={"choose the 

color","Red","Yellow","Green","Blue","Cyan","Manget

a","Orange"};
cbFill = new JComboBox(Fill);
cbFill.setSize(200,30);
cbFill.setLocation(500,170);
cbFill.setForeground(Color.white.brighter());
cbFill.setBackground(Color.green.brighter());
cbFill.setFont(new Font("Arial", Font.BOLD, 16));
add(bLine);
add(bOval);
add(bRect);
add(bRounded);
add(bDraw);
add(cbLine);
add(cbFill);
add(bHeading);
bLine.addActionListener(this);
bOval.addActionListener(this);
bRect.addActionListener(this);
bRounded.addActionListener(this);
bDraw.addActionListener(this);
addMouseListener(this);
addMouseMotionListener(this);
}
public void mousePressed(MouseEvent e)
{
mouseUp = false;
start = new Point(e.getX(), e.getY());
}
public void mouseReleased(MouseEvent e)
{
if(line){
end = new Point(e.getX(), e.getY());
} else {
end = new Point(Math.max(e.getX(), start.x),
Math.max(e.getY(), start.y));
start = new Point(Math.min(e.getX(), start.x),
Math.min(e.getY(), start.y));
}
mouseUp = true;
repaint();
}
public void mouseDragged(MouseEvent e)
{
if(draw){
dot[dots] = new Point(e.getX(), e.getY());
dots++;
repaint();
}
}
public void mouseClicked(MouseEvent e){}
public void mouseEntered(MouseEvent e){}
public void mouseExited(MouseEvent e){}
public void mouseMoved(MouseEvent e){}
public void paint (Graphics g)
{
if (mouseUp) {
int width = end.x - start.x;
int height = end.y - start.y;
if(line){
g.drawLine(start.x, start.y, end.x, end.y);
}
else if(oval){
g.drawOval(start.x, start.y, width, height);
}
else if(rectangle){
g.drawRect(start.x, start.y, width, height);
}
else if(rounded){
g.drawRoundRect(start.x, start.y, width, height, 

10, 10);
}
else if(draw){
for(int loop_index = 0; loop_index < dots - 1;
loop_index++){
g.drawLine(dot[loop_index].x, dot[loop_index].y,
dot[loop_index + 1].x, dot[loop_index + 1].y);
}
}
}
}
public void actionPerformed(ActionEvent e)
{
setFlagsFalse();
if(e.getSource() == bDraw)draw = true;
if(e.getSource() == bLine)line = true;
if(e.getSource() == bOval)oval = true;
if(e.getSource() == bRect)rectangle = true;
if(e.getSource() == bRounded)rounded = true;
}
void setFlagsFalse()
{
rounded = false;
line = false;
oval = false;
rectangle = false;
draw = false;
}
}

This is comment given by the command prompt, pls, help.

C:\z>appletviewer draw.java
java.lang.Error: Do not use draw.setLayout() use draw.getContentPane().setLayout
() instead
        at javax.swing.JApplet.createRootPaneException(JApplet.java:200)
        at javax.swing.JApplet.setLayout(JApplet.java:261)
        at draw.init(draw.java:61)
        at sun.applet.AppletPanel.run(AppletPanel.java:348)
        at java.lang.Thread.run(Thread.java:536)
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.