My circle isn't visible

+1 Lester Ramos · February 22, 2015
My circle isn't visible and i have the same exact code that you have on all 3 classes

Post a Reply

Replies

Oldest  Newest  Rating
+1 Neil Cannon · February 22, 2015
Try changing the colour?
0 Lester Ramos · February 22, 2015
bucky doesn't include a constructor for the oval. 
You can only change the color f the background. 
These are in the java intermediate lessons vid 25
0 Lester Ramos · February 22, 2015
Here is my code:
import javax.swing.*;

import java.awt.*;

//@SuppressWarnings("serial")
public class DrawOval extends JPanel {

private int d = 10;

public void paintComponet(Graphics g) {
super.paintComponent(g);
g.fillOval(10, 10, d, d);

}

public void setD(int newD) {
d = (newD >= 0 ? newD : 10); 
repaint();
}

public Dimension getPreferredSize(){
return new Dimension(200,200);
}

public Dimension getMinimumSize(){
return getPreferredSize();
}
}

**********************************************************************************
import java.awt.BorderLayout;
import java.awt.Color;

import javax.swing.JFrame;
import javax.swing.JSlider;
import javax.swing.SwingConstants;
import javax.swing.event.ChangeEvent;
import javax.swing.event.ChangeListener;


//@SuppressWarnings("serial")
public class TheWindow extends JFrame {

private JSlider slider;
private DrawOval myPanel;


public TheWindow(){
super("The title");
myPanel = new DrawOval();
myPanel.setBackground(Color.BLUE);


slider = new JSlider(SwingConstants.HORIZONTAL,0,200,10);
slider.setMajorTickSpacing(10);
slider.setPaintTicks(true);

slider.addChangeListener(
new ChangeListener(){
public void stateChanged(ChangeEvent e ){
myPanel.setD(slider.getValue());
}
}

);

add(slider, BorderLayout.SOUTH);
add(myPanel, BorderLayout.NORTH);
}



}
**********************************************************************************

import javax.swing.*;


public class OvalMain {

public static void main(String[] args) {
// TODO Auto-generated method stub

TheWindow w = new TheWindow();
w.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
w.setSize(230,280);
w.setVisible(true);

}

}
  • 1

Java / Android Development

107,255 followers
About

Very popular language used to create desktop applications, website applets, and Android apps.

Links
Moderators
Bucky Roberts Administrator