I was trying to put a yellow smiley face in my program just for fun. I'm trying to put it in JPane, but the template I used for the face was from a JApplet example. I didn't know if the code was specific to JApplet or if it should work if I put it in the right place. Please don't bother helping me with this unless you're really bored. I can remove this if I need to, but I just thought it would be fun and fill some empty space in the pane. My current code returns the following error:
SquiresDriver.java:41: cannot find symbol
symbol : constructor SquiresDriver()
location: class SquiresDriver
SquiresDriver guiWithPanel = new SquiresDriver();
Here's the code:
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
import java.text.*;
/**
Simple demonstration of putting buttons in a panel.
*/
public class SquiresDriver extends JFrame implements ActionListener
{
public static final int WIDTH = 600;
public static final int HEIGHT = 200;
//window parameters
public static final int FACE_DIAMETER = 200;
public static final int X_FACE = 100;
public static final int Y_FACE = 50;
//face dimensions
public static final int EYE_WIDTH = 10;
public static final int EYE_HEIGHT = 20;
public static final int X_RIGHT_EYE = 155;
public static final int Y_RIGHT_EYE = 95;
public static final int X_LEFT_EYE = 230;
public static final int Y_LEFT_EYE = Y_RIGHT_EYE;
//eyes
public static final int NOSE_DIAMETER = 10;
public static final int X_NOSE = 195;
public static final int Y_NOSE = 135;
//nose
public static final int MOUTH_WIDTH = 100;
public static final int MOUTH_HEIGHT = 50;
public static final int X_MOUTH = 150;
public static final int Y_MOUTH =175;
public static final int MOUTH_START_ANGLE = 180;
public static final int MOUTH_DEGREES_SHOWN = 180;
//mouth
double num1, num2, num3, mean, range, variance, smallest, largest, sumOfSquares;
String num1String, num2String, num3String;
DecimalFormat df = new DecimalFormat("#.##");
public static void main(String[] args)
{
SquiresDriver guiWithPanel = new SquiresDriver();
guiWithPanel.setVisible(true);
}
SquiresProject4 method = new SquiresProject4();
public SquiresDriver(Graphics canvas)
{
setSize(WIDTH, HEIGHT);
addWindowListener(new WindowDestroyer( ));
setTitle("Calculator of Dreams");
Container contentPane = getContentPane( );
contentPane.setBackground(Color.ORANGE);
contentPane.setLayout(new BorderLayout( ));
JPanel buttonPanel = new JPanel( );
buttonPanel.setBackground(Color.WHITE);
buttonPanel.setLayout(new FlowLayout( ));
JButton meanButton = new JButton("Calculate MEAN");
meanButton.setBackground(Color.GRAY);
meanButton.addActionListener(this);
buttonPanel.add(meanButton);
JButton rangeButton = new JButton("Calculate RANGE");
rangeButton.setBackground(Color.RED);
rangeButton.addActionListener(this);
buttonPanel.add(rangeButton);
JButton varianceButton = new JButton("Calculate Variance");
varianceButton.setBackground(Color.GREEN);
varianceButton.addActionListener(this);
buttonPanel.add(varianceButton);
canvas.setColor(Color.YELLOW);
canvas.fillOval(X_FACE, Y_FACE, FACE_DIAMETER, FACE_DIAMETER);
canvas.setColor(Color.BLACK);
canvas.drawOval(X_FACE, Y_FACE, FACE_DIAMETER, FACE_DIAMETER);
//draws face
canvas.setColor(Color.BLUE);
canvas.fillOval(X_RIGHT_EYE, Y_RIGHT_EYE, EYE_WIDTH, EYE_HEIGHT);
canvas.fillOval(X_LEFT_EYE, Y_LEFT_EYE, EYE_WIDTH, EYE_HEIGHT);
//draws eyes
canvas.setColor(Color.BLACK);
canvas.fillOval(X_NOSE, Y_NOSE, NOSE_DIAMETER, NOSE_DIAMETER);
//draws nose
canvas.setColor(Color.RED);
canvas.drawArc(X_MOUTH, Y_MOUTH, MOUTH_WIDTH, MOUTH_HEIGHT, MOUTH_START_ANGLE, MOUTH_DEGREES_SHOWN);
//draws mouth
contentPane.add(buttonPanel, BorderLayout.SOUTH);
}
public void actionPerformed(ActionEvent e)
{
Container contentPane = getContentPane( );
if (e.getActionCommand( ).equals("Calculate MEAN"))
{
method.getInput();
JOptionPane.showMessageDialog( null, "The mean is: " +df.format(method.getMean()));
}
else if (e.getActionCommand( ).equals("Calculate RANGE"))
{
method.getInput();
JOptionPane.showMessageDialog( null, "The range is: " +df.format(method.getRange()));
}
else if (e.getActionCommand( ).equals("Calculate Variance"))
{
method.getInput();
JOptionPane.showMessageDialog( null, "The variance is: " +df.format(method.getVariance()));
}
else
System.out.println("Error in button interface.");
}
}