本文介绍了了解drawLine如何工作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
给定以下代码: import javax.swing。*;
import java.awt。*;
public class NewClass extends JPanel {
public void paintComponent(Graphics g){
g.drawLine(0,0,90,90);
public static void main(String [] args){
JFrame jf = new JFrame();
jf.add(new NewClass());
jf.setSize(500,500);
jf.setVisible(true);
$ b $ p $为什么如果方法 drawLine
是抽象的,因为我设法理解,抽象方法没有定义?
预先感谢!
解决方案 的paintComponent()
得到一个非抽象子类的图形
,它实现 drawLine()
。它必须得到一个非抽象的子类,因为抽象类不能被实例化。
Given the following code:
import javax.swing.*;
import java.awt.*;
public class NewClass extends JPanel {
public void paintComponent(Graphics g) {
g.drawLine(0, 0, 90, 90);
}
public static void main(String[] args) {
JFrame jf = new JFrame();
jf.add(new NewClass());
jf.setSize(500, 500);
jf.setVisible(true);
}
}
Why does it draw a line if the method drawLine
is abstract and, as I managed to understand, an abstract method has no definition?
Thank you in advance!
解决方案 paintComponent()
gets a non-abstract sub-class of Graphics
, which implements drawLine()
. It must get a non-abstract sub-class, since an abstract class cannot be instantiated.
这篇关于了解drawLine如何工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!