I am making a simple drawling program and the drawling panel will not show up. I don't know if it is a problem with the Circle class, or the drawingPanel class. The colorButtons and the sizeButtons do show up but the drawingPanel does not. Can you help me please, take your time and thanks in advance! P.S. I add the frames in the drawingFrame.
public class Assign72 {
public static void main(String[] args) {
DrawingFrame f= new DrawingFrame();
f.setTitle("Drawing Program");
f.setSize(462,312);
f.setLocationRelativeTo(null);
f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
f.setVisible(true);
}
public class DrawingFrame extends JFrame implements ActionListener {
private DrawingPanel drawPanel;
private JPanel panel;
private JPanel colorPanel;
private JPanel sizePanel;
private JRadioButton redRadioButton;
private JRadioButton blueRadioButton;
private JRadioButton greenRadioButton;
private JRadioButton blackRadioButton;
private JRadioButton smallRadioButton;
private JRadioButton mediumRadioButton;
private JRadioButton largeRadioButton;
private JButton eraseButton;
private ButtonGroup colorButtonGroup;
private ButtonGroup sizeButtonGroup;
final int SMALL = 4;
final int MEDIUM = 8;
final int LARGE = 10;
public DrawingFrame() {
colorPanel = new JPanel();
sizePanel = new JPanel();
redRadioButton = new JRadioButton();
redRadioButton.setText("Red");
colorPanel.add(redRadioButton);
redRadioButton.addActionListener(this);
blueRadioButton = new JRadioButton();
blueRadioButton.setText("Blue");
colorPanel.add(blueRadioButton);
blueRadioButton.addActionListener(this);
greenRadioButton = new JRadioButton();
greenRadioButton.setText("Green");
colorPanel.add(greenRadioButton);
greenRadioButton.addActionListener(this);
blackRadioButton = new JRadioButton();
blackRadioButton.setText("Black");
colorPanel.add(blackRadioButton);
blackRadioButton.addActionListener(this);
smallRadioButton = new JRadioButton();
smallRadioButton.setText("Small");
sizePanel.add(smallRadioButton);
smallRadioButton.addActionListener(this);
mediumRadioButton = new JRadioButton();
mediumRadioButton.setText("Medium");
sizePanel.add(mediumRadioButton);
mediumRadioButton.addActionListener(this);
largeRadioButton = new JRadioButton();
largeRadioButton.setText("Large");
sizePanel.add(largeRadioButton);
largeRadioButton.addActionListener(this);
colorButtonGroup = new ButtonGroup();
sizeButtonGroup = new ButtonGroup();
sizeButtonGroup.add(smallRadioButton);
sizeButtonGroup.add(mediumRadioButton);
sizeButtonGroup.add(largeRadioButton);
colorButtonGroup.add(redRadioButton);
colorButtonGroup.add(blueRadioButton);
colorButtonGroup.add(greenRadioButton);
colorButtonGroup.add(blackRadioButton);
redRadioButton.setSelected(true);
largeRadioButton.setSelected(true);
JPanel configurePanel = new JPanel();
configurePanel.add(new JButton("Configure"));
// Will be right-aligned.
// The full panel.
panel = new JPanel();
panel.setBackground(Color.YELLOW);
drawPanel = new DrawingPanel(Color.RED, LARGE);
drawPanel.setBackground( Color.WHITE );
this.add(sizePanel, BorderLayout.PAGE_START);
this.add(colorPanel, BorderLayout.PAGE_END);
this.add(drawPanel,BorderLayout.CENTER);
}
@Override
public void actionPerformed(ActionEvent e) {
// TODO Auto-generated method stub
if (redRadioButton.isSelected())
drawPanel.setCircleColor(Color.RED);
if (greenRadioButton.isSelected())
drawPanel.setCircleColor(Color.GREEN);
if (blueRadioButton.isSelected())
drawPanel.setCircleColor(Color.BLUE);
if (blackRadioButton.isSelected())
drawPanel.setCircleColor(Color.BLACK);
if (smallRadioButton.isSelected())
drawPanel.setCircleSize(SMALL);
if (mediumRadioButton.isSelected())
drawPanel.setCircleSize(MEDIUM);
if (largeRadioButton.isSelected())
drawPanel.setCircleSize(LARGE);
}
}
public class DrawingPanel extends JPanel implements MouseMotionListener {
private int circleSize;
private Color circleColor;
private Circle newCircle;
private Circle drawingCircle;
private ArrayList<Circle> circleArrayList = new ArrayList<Circle>();
DrawingPanel(Color colorValue, int size) {
addMouseMotionListener(this);
}
public void setCircleColor(Color choice) {
}
public Color getCircleColor() {
return circleColor;
}
public void setCircleDiameter(int diameter) {
}
public int getCircleSize() {
return circleSize;
}
public void paintComponent(Graphics g) {
super.paintComponents(g);
Iterator<Circle> circleIterator = circleArrayList.iterator();
Circle drawCircle;
while (circleIterator.hasNext()) {
drawCircle = (Circle) circleIterator.next();
drawCircle.draw(g);
}
}
public void mouseDragged(MouseEvent event) {
if (event.isMetaDown()) {
newCircle = new Circle(getCircleSize(), event.getPoint(),
this.getBackground());
newCircle = new Circle(getCircleSize(), event.getPoint(),
getCircleColor());
circleArrayList.add(newCircle);
repaint();
}
}
@Override
public void mouseMoved(MouseEvent arg0) {
// TODO Auto-generated method stub
}
}
public class Circle {
private int size;
private Point point;
private Color color;
public Circle(int size, Point point, Color color) {
setSize(size);
setLocation(point);
setColor(color);
}
public int getSize() {
return size;
}
public void setSize(int size) {
}
public Point getLocation() {
return point;
}
public void setLocation(Point point) {
}
public Color getColor() {
return color;
}
public void setColor(Color color) {
}
public void draw(Graphics g) {
getLocation();
setColor(color);
setSize(size);
setColor(color);
g.fillOval(point.x, point.y, size, size);
}
}