新人求助~·一个关于JAVA图形界面小程序中的BUG~·~·本人在线等着~·
新人求助~本人第一次发帖·一个关于JAVA图形界面小程序中的BUG~·~·调了好久都未解决~·求好心人帮助提醒~·本人在线等着~·
问题描述:
这个程序中为什么在面板上会画两次点和线呢~·paint()方法被调用了两次?前几天调了好久都没答案~·求各位能帮我解决~~·
以下是我的小程序代码:
import java.awt.*;
import java.io.*;
import java.awt.event.*;
import javax.swing.*;
import javax.imageio.*;
import java.awt.event.MouseListener;
public class JieMian5 extends JFrame implements ActionListener {
JPanel jp1, jp3, jp4, jp5;
public static JLabel jlb;
public static JTextArea jta;
JScrollPane jsp = null;
JButton jb1, jb2, jb3;
JSplitPane jsp1;
public static void main (String[] args){
JieMian5 jiemian5 = new JieMian5();
}
public JieMian5() {
int w = Toolkit.getDefaultToolkit().getScreenSize().width;
int h = Toolkit.getDefaultToolkit().getScreenSize().height;
jta = new JTextArea();
jta.setLineWrap(true);
jta.setWrapStyleWord(true);
jta.setBackground(Color.YELLOW);
jsp = new JScrollPane(jta);
jp1 = new JPanel();
jp3 = new JPanel();
jp4 = new JPanel();
jp5 = new JPanel(new BorderLayout());
//jp5.setb
jb1 = new JButton("原理概述");
jb1.addActionListener(this);
jb2 = new JButton("清空");
jb2.addActionListener(this);
jb3 = new JButton("图文演示");
jb3.addActionListener(this);
// 做一个拆分窗口,分别存取p2,p3.
jsp1 = new JSplitPane(JSplitPane.HORIZONTAL_SPLIT, true, jp1, jsp);
// 指定左边的面板占多大
jsp1.setDividerLocation(w - 780);
jsp1.setDividerSize(0);
jlb = new JLabel(new ImageIcon("image/081020091722_0.jpg"));
jp5.add(jlb);
jp3.add(jb1);
jp3.add(jb2);
jp3.add(jb3);
jp1.setLayout(new BorderLayout());
jp1.add(jp5, BorderLayout.CENTER);
jp1.add(jp3, BorderLayout.SOUTH);
// 从JFrame中取得Container
//Container ct = this.getContentPane();
// 把Panel加入JFrame
this.add(jsp1);
// ct.add(jp4,BorderLayout.SOUTH);
System.out.print("11111");
this.setSize(w, 486);
this.setTitle("山大老校校园导航系统");
this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
this.setVisible(true);
}
public void paint(Graphics g) {
Graphic G = new Graphic();
super.paint(g);
g.setColor(Color.BLUE);
for (int ii = 0; ii < 13; ii++) {
g.fillOval(G.vexs[ii].getX(), G.vexs[ii].getY(), 10, 10);
try {
Thread.sleep(500);
} catch (InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
g.drawLine(G.vexs[0].getX(), G.vexs[0].getY(), G.vexs[12].getX(),
G.vexs[12].getY());try {
Thread.sleep(1000);
} catch (InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}