java小画板问题

importjava.awt.*;importjava.awt.event.*;importjavax.swing.*;classPainPanel2extendsJPa... import java.awt.*;
import java.awt.event.*;
import javax.swing.*;

class PainPanel2 extends JPanel implements MouseMotionListener, MouseListener {
private Point startPoint = new Point(-1,-1);
private Point endPoint = new Point(-1,-1);

public PainPanel2() {
super();
addMouseMotionListener(this);
addMouseListener(this);
}
public void paint(Graphics g) {
super.paintComponent(g);
Graphics2D g2d = (Graphics2D)g;
g2d.setStroke(new BasicStroke(3.0F));
g2d.setPaint(Color.BLACK);
g2d.drawLine(startPoint.x, startPoint.y,
endPoint.x, endPoint.y);
repaint();
//startPoint = endPoint;
}
public void mouseDragged(MouseEvent e) {
endPoint = e.getPoint();
repaint();
}
public void mousePressed(MouseEvent e) {
startPoint = e.getPoint();
}

public void mouseMoved(MouseEvent e) {}
public void mouseExited(MouseEvent e) {}
public void mouseEntered(MouseEvent e) {}
public void mouseReleased(MouseEvent e) {}
public void mouseClicked(MouseEvent e) {}
}
public class MainPanel extends JPanel{
public MainPanel() {
super(new BorderLayout());
add(new PaintPanel());
setPreferredSize(new Dimension(320, 240));
}
public static void createAndShowGUI() {
JFrame frame = new JFrame("PanitPanel");
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
//frame.getContentPane().add(new MainPanel());
frame.setContentPane(new MainPanel());
frame.setResizable(false);
frame.pack();
frame.setLocationRelativeTo(null);
frame.setVisible(true);
}

public static void main(String[] args) {
javax.swing.SwingUtilities.invokeLater(new Runnable() {
public void run() {
createAndShowGUI();
}
});
}
}
简单的类似画笔的程序,如何解决窗口最小化的时候,画板重置的问题,谢谢了
public void paint(Graphics g) {
//super.paintComponent(g);
Graphics2D g2d = (Graphics2D)g;
g2d.setStroke(new BasicStroke(3.0F));
g2d.setPaint(Color.BLACK);
g2d.drawLine(startPoint.x, startPoint.y,
endPoint.x, endPoint.y);
repaint();
startPoint = endPoint;
}
这一段复制错了无效了super无效了可以正常运行,super有效可以避免重置问题,但是不能绘画了,开始point一直变成结束point

就是最小化了以后再还原时,画的东西都没了
展开
 我来答
君子好美女
2010-07-18 · TA获得超过255个赞
知道答主
回答量:932
采纳率:0%
帮助的人:279万
展开全部
不明白
推荐律师服务: 若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询

为你推荐:

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

类别

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

说明

0/200

提交
取消

辅 助

模 式