关于paintComponent问题

来源:百度知道 编辑:UC知道 时间:2024/05/13 02:49:56
一个小程序,各位大侠帮忙看看为什么不显示Line呢?
package programmingPractice;
import javax.swing.*;
import java.awt.*;

public class Section1310 extends JFrame{
public Section1310(){
//setTitle("Cylinder");
add(new Cylinder());
}

class Cylinder extends JPanel{
protected void paintComponet(Graphics g){
super.paintComponent(g);
/*g.drawOval((int)(getSize().width/4), (int)(getSize().height/8),
(int)(getSize().width/2), (int)(getSize().height/4));
g.drawLine((int)(.25*getWidth()), (int)(.25*this.getHeight()),
(int)(.25*getWidth()), (int)(.875*this.getHeight()));
*/
g.drawLine(0, 0, 50, 50);
}
}
public static void main(String arg[]){
Section1310 frame= new Section1310();
frame.setSize(300,200);
frame.setTitle("Cylinder");
frame.setLocationRelativeTo(null);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
fra

class Cylinder extends JPanel {
@Override
public void paint(Graphics g) {
super.paint(g);
g.drawLine(0, 0, 50, 50);
}
}
//你应该Override这个方法,而不是
protected void paintComponet(Graphics g){
}