为啥画不出来?# Java - 爪哇娇娃
y*i
1 楼
正在学习用java进行简单画图,下面这个程序该怎么改?谢谢指教。
编译报错信息:
paintComponent(java.awt.Graphics) in javax.swing.JComponent cannot be
applied to (Graphics)
cannot find symbol method drawLine(int,int,int,int)
import java.awt.*;
import javax.swing.*;
import java.util.*;
public class Graphics extends JFrame {
private Paint newPaint= new Paint();
public Graphics()
{add(newPaint);
}
class Paint extends JPanel
{ public Paint(){};
// @Override
protected void paintComponent(Graphics g)
{ super.paintComponent(g);
g.drawLine(1,1,10,15);
}
}
public static void main(String[] arg)
{
JFrame frame=new Graphics();
frame.setVisible(true);
}
}
编译报错信息:
paintComponent(java.awt.Graphics) in javax.swing.JComponent cannot be
applied to (Graphics)
cannot find symbol method drawLine(int,int,int,int)
import java.awt.*;
import javax.swing.*;
import java.util.*;
public class Graphics extends JFrame {
private Paint newPaint= new Paint();
public Graphics()
{add(newPaint);
}
class Paint extends JPanel
{ public Paint(){};
// @Override
protected void paintComponent(Graphics g)
{ super.paintComponent(g);
g.drawLine(1,1,10,15);
}
}
public static void main(String[] arg)
{
JFrame frame=new Graphics();
frame.setVisible(true);
}
}