为什么Jpanel不能显示画线?高手请解答一下

importjava.awt.FlowLayout;importjava.awt.Graphics;importjava.awt.Point;importjava.awt... import java.awt.FlowLayout;
import java.awt.Graphics;
import java.awt.Point;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;

import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JPanel;

public class JieMian extends JFrame {
Mypanel p = null;

public JieMian(String title) {
super(title);
p = new Mypanel();
p.setBounds(30, 30, 220, 220);
this.setLayout(null);
this.add(p);
this.setBounds(300, 300, 300, 300);
this.addWindowListener(new WindowAdapter() {
@Override
public void windowClosing(WindowEvent e) {
System.exit(0);
}
});
this.setVisible(true);
}
}

class Mypanel extends JPanel {

private DrawGrid dg = null;
JButton b = new JButton("画");

public Mypanel() {
super();
dg = new DrawGrid(new Point(10, 10), new Point(80, 80));
this.setLayout(new FlowLayout());
this.add(b);
b.addActionListener(new Monitor());
}

class Monitor implements ActionListener {
public void actionPerformed(ActionEvent e) {
dg = new DrawGrid(new Point(50, 50), new Point(80, 80));
repaint();

}
}
public void Paint(Graphics g) {
dg.drawline(g);

}
}

public class DrawGrid {
private Point startP;
private Point endP;
public DrawGrid(Point startP,Point endP){
this.startP = startP;
this.endP = endP;
}
public void drawline(Graphics g){
g.drawLine(startP.x, startP.y, endP.x, endP.y);
}
}

public class Test {
public static void main(String[] args) {
new JieMian("TETRIS");

}

}
新手,请大哥们帮帮忙。谢谢
展开
 我来答
skyyks0001
2010-02-18 · TA获得超过430个赞
知道小有建树答主
回答量:228
采纳率:100%
帮助的人:398万
展开全部
那个
public void Paint(Graphics g) {
dg.drawline(g);

}
中的Paint改成paint即可
推荐律师服务: 若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询

为你推荐:

下载百度知道APP,抢鲜体验
使用百度知道APP,立即抢鲜体验。你的手机镜头里或许有别人想知道的答案。
扫描二维码下载
×

类别

我们会通过消息、邮箱等方式尽快将举报结果通知您。

说明

0/200

提交
取消

辅 助

模 式