It is a small problem Java thought

import java.awt.Graphics;
import javax.swing.JFrame;
import javax.swing.JPanel;
public class DrawCircle extends JFrame {
	private final int OVAL_WIDTH = 80;// Circular width
	private final int OVAL_HEIGHT = 80;// The circular high
	public DrawCircle() {
		initialize();// Calls an initialization method
	// Initialization method
	private void initialize() {
		this.setSize(300, 200);// Set the window size
		setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);// Set the form off mode
		setContentPane(new DrawPanel());// Set the form panel for the drawing panel objects
		this.setTitle("The drawing examples "); // 2 set the window title
	public static void main(String[] args) {
		new DrawCircle().setVisible(true);
	// Create a drawing board
	class DrawPanel extends JPanel {
		public void paint(Graphics g) {
			g.drawOval(10, 10, OVAL_WIDTH, OVAL_HEIGHT);	// Draw 1 circles

I would like to ask, what is the two super statement this code inside the function? Delete, seems to be running results no change! Use what do?

Started by Jonathan at February 08, 2016 - 7:57 PM

And super is to call the parent class paint (Graphics g) method, with no word is called subclass.
Here without super. I do not believe you program not error. Significant death cycle
public void paint(Graphics g) {
g.drawOval(10, 10, OVAL_WIDTH, OVAL_HEIGHT); // Draw 1 circles

Posted by Ellen at February 14, 2016 - 8:55 PM

The first row only the constructor is super or this, you don't add words, automatic super compiler();

Posted by Miya at February 22, 2016 - 9:48 PM

The first super is in the DrawCircle construction., So the effect is parameterless constructor call the parent class, The second super in the paint method of the DrawPanel class., And super.paint (g) is call the parent class's paint method, You said no changes after removal of the operation results, Can DrawCircle be paint method for constructing method and the DrawPanel of the parent class for your results may just have no effect, For example, the first super is calling the superclass constructor, There is a void method, It won't tell you the results, Methods of using super is that the execution of the parent class

Posted by William at November 10, 2016 - 1:51 PM

Try to know~

Posted by Jonathan at November 18, 2016 - 2:30 PM

Posted by Ellen at November 19, 2016 - 2:44 PM

Inside the program first construction method, here with and without all of it doesn't matter, but the second if you don't add words must be wrong, because you are using a method of the parent class

Posted by Angus at November 25, 2016 - 3:27 PM

Feel shy, I mean to remove super.paint (g); this sentence
I just want to know, with or without can, why? Is it right? What skills

Posted by Jonathan at December 03, 2016 - 4:08 PM

I just want to know, with or without can, why? Is it right? What skills

Posted by Jonathan at December 09, 2016 - 4:32 PM

The add.,
Even without super, when the constructor execution will default first execute the parent class constructor.

Posted by Ellen at December 11, 2016 - 4:49 PM

With the super is to call the parent class method, not is completely override this method

Posted by Lucine at December 14, 2016 - 4:57 PM

My head is dizzy. We are going to learn,

Posted by Carol at December 15, 2016 - 4:58 PM

super()Effect: create a subclass object, creates a superclass object, super () is equivalent to call the parent class's default constructor, you don't add on the constructor execution will let you create a parent object

Posted by Claude at December 29, 2016 - 5:22 PM

Indeed, but in this code, did not see any meaning.

Posted by Jonathan at January 09, 2017 - 6:13 PM

When the class inheritance relationship,
Subclasses of new objects, first of all to have a look what data to initialize the parent class, because the subclass to superclass data used, so should be put in the first row of the constructor. We all know that the system will default to provide a default constructor with no parameters, when the parent class constructor without parameters, subclasses of new objects, you write with super (not write), are never mind, because the system provides. When a parent class constructors with arguments, which is a subclass of new object, according to your needs to specify the parent any parameter constructor, parameterless constructor to display the writing colleagues parent class, otherwise the compiler error.

Posted by Fannie at January 09, 2017 - 7:19 PM

super.paint(g); That's because the parent class (paint) had no effect on the class

Posted by Lucine at January 11, 2017 - 6:47 PM


Posted by Derek at January 13, 2017 - 6:16 PM