这是我的程序,我想在Frame 窗口被其他窗口覆盖后(即不是活动窗口),再重新返回成为活动窗口时,Frame上的内容不会丢失.
我是初学者,弄了一天也没整明白, 小弟是初学者,请大家帮帮忙,谢谢~~~@!!!!!! 
import java.awt.*;
class FrameTest extends Frame //extends Frame
{
FrameTest(String str)
{
super(str);
}
public static void main(String [] args) //throws Exception
{
FrameTest f=new FrameTest("Frame Test!");
Panel pl=new Panel();
f.setSize(1000,800);
f.setLayout(null);
pl.setSize(200,300);
pl.setBackground(Color.yellow);f.setVisible(true);
f.add(pl);
pl.setVisible(true);
for(int i=0;i<=1000;i=i+50)
{
f.getGraphics().drawString("13213",i,i);
}}}

解决方案 »

  1.   

    import java.awt.*;
    class FrameTest extends Frame //extends Frame
    {
      FrameTest(String str)
      { 
        super(str);
        Panel pl=new Panel();
        setSize(1000,800);
        setLayout(null);
        pl.setSize(200,300);
        pl.setBackground(Color.yellow);
        f.add(pl);
        for(int i=0;i<=1000;i=i+50)
        {
          getGraphics().drawString("13213",i,i);
        }
      }  public static void main(String [] args) //throws Exception
      {
        FrameTest f=new FrameTest("Frame Test!");
        f.setVisible(true);
      }
    }
      

  2.   

    你可以运行一下程序,当"Frame"界面显示内容后,你再点击别的窗口(任何别的都可以)这时你点击的窗口会盖住那个"Frame"窗口的全部或部分,这时被盖住的部分就不在"Frame"里窗口显示了,即使再点击"Frame"窗口也不会显示出原来的内容.我的意思是说:怎么能让它显示出来.谢谢!!
      

  3.   

    你可以试着加个事件监听,这样做其实不好,建议你用Applet
    import java.awt.*;
    import java.applet.*;
    public class Test extends Applet //extends Frame
    {
    public void init()
    {Panel pl=new Panel();
    setSize(1000,800);
    setLayout(null);
    pl.setSize(200,300);
    pl.setBackground(Color.yellow);setVisible(true);
    add(pl);
    pl.setVisible(true);
    }
    public void paint(Graphics g)//throws Exception
    {for(int i=0;i<=1000;i=i+50)
    {
    g.drawString("13213",i,i);
    }}}
      

  4.   

    import java.awt.*;
    import java.awt.event.*;
    class FrameTest extends Frame //extends Frame
    {
    FrameTest(String str)
    {
    super(str);
    addWindowListener(new WindowAdapter()
                      {
                       public void windowClosing(WindowEvent e)
                       {
                        System.exit(0);
                       }
                       });   // 窗口关闭
     }
    public static void main(String [] args) //throws Exception
    {
    FrameTest f=new FrameTest("Frame Test!");
    Panel pl=new Panel();
    f.setSize(1000,800);
    f.setLayout(null);
    pl.setSize(200,300);
    pl.setBackground(Color.yellow);f.setVisible(true);
    f.add(pl);
    pl.setVisible(true);  //这个没必要的,Panel会随Frame一起显示的
    }public void paint(Graphics g)
    {
    for(int i=0;i<=1000;i=i+50)
     g.drawString("13213",i,i);
    }}
    加了些代码,这样就可以了,参考下
      

  5.   

    import java.awt.*;
    public class Test extends Frame //extends Frame
    {
    Test(String str)
    {
    super("Frame Test");}public static void main(String args[])
    {
    Test f=new Test("jjj");
    Panel pl=new Panel();
    f.setSize(1000,800);
    f.setLayout(null);
    pl.setSize(200,300);
    pl.setBackground(Color.yellow);f.setVisible(true);
    f.add(pl);
    pl.setVisible(true);
    }
    public void paint(Graphics g){
    for(int i=0;i<=1000;i=i+50)
    {
    g.drawString("13213",i,i);
    }
    }
    }
    这样可以
      

  6.   

    上面写错了。你看看是不是这个的问题。
    public void repaint(int x,
                        int y,
                        int width,
                        int height)
      

  7.   

    还有,我想问一下楼上 gongyali2005(JAVA 民工)  说的 repaint() 怎么用啊,能给我举个例子吗谢啦~~
      

  8.   

    有谁能告诉我,  repaint()   updata()   方法的用法 ? 谢谢~~!~!!!!
      

  9.   

    为了响应对 repaint 的调用,AWT 调用 update 方法, update 方法再调用此组件的 paint 方法来重绘此组件。查查JDK文档有详细说明
      

  10.   

    调用repaint()其实就是程序自动先调用 updata()清除掉画面,再重新调用paint().,执行重画。