Topic: 一个神奇的错误,谁可改正?(有关repaint)

  Print this page

1.一个神奇的错误,谁可改正?(有关repaint) Copy to clipboard
Posted by: java_ee
Posted on: 2005-11-14 00:17

我发现一个神奇的错误,请求高手指导

在下面简短机行的代码中,运行后我所加的标签和文本域居然显示不出来
只有在双击使其最大化的后才可以显示出来!如果将其最小化后在打开又是什么都看不见了,然后再双击使其最大化又可以看不见了!请问这是什么原因呢?
怎样改正,才可以让其运行后,就正常显示了呢?
谢谢
代码如下;

import java.awt.*;
import javax.swing.*;

public class Test extends JApplet
{
JTextField xfield1 ;
JLabel xLabel1 ;
Container con;
public void init()
{
con=getContentPane();
con.setLayout(new FlowLayout());
xfield1 = new JTextField(6);
xLabel1 = new JLabel("请输入X1坐标");
con.add(xLabel1);
con.add(xfield1);

}
public void paint(Graphics g)
{
g.drawLine(20,20,50,100);

}
}

2.Re:一个神奇的错误,谁可改正? [Re: java_ee] Copy to clipboard
Posted by: albert_1030
Posted on: 2005-11-15 07:12


import java.awt.*;
import javax.swing.*;

public class Test extends JApplet
{
JTextField xfield1 ;
JLabel xLabel1 ;
Container con;
public void init()
{
con=getContentPane();
con.setLayout(new FlowLayout());
xfield1 = new JTextField(12);
xLabel1 = new JLabel("请输入X1坐标");
con.add(xLabel1);
con.add(xfield1);

}
public void paintComponent(Graphics g) // not paintComponet -- why
{
super.paintComponent(g); // not paintComponents,
// and I don't think JApplet has paintComponent(Graphics) -- why

g.drawLine(20,20,50,100);

}
}


你这是马虎! // then how about yourself -- why;-)

3.Re:一个神奇的错误,谁可改正? [Re: java_ee] Copy to clipboard
Posted by: bukaoyan
Posted on: 2005-11-15 14:45

呵呵
神奇!!!

4.Re:一个神奇的错误,谁可改正? [Re: java_ee] Copy to clipboard
Posted by: wangyabing
Posted on: 2005-12-30 14:48

还是不能运行呀朋友

5.Re:一个神奇的错误,谁可改正? [Re: java_ee] Copy to clipboard
Posted by: 漫步云端
Posted on: 2006-01-01 19:17

運行不了呀.要怎麼樣改呢.謝謝了.

6.Re:一个神奇的错误,谁可改正? [Re: java_ee] Copy to clipboard
Posted by: ranchgirl
Posted on: 2006-01-02 12:08

漫步云端 wrote:
運行不了呀.要怎麼樣改呢.謝謝了.


It something does not work, you don't know what it does, why waste your time on it????

There are tons of garbage on the Internet, are you going to pick all of them up, and do research on each of them???

Who cares it is called "神奇的错误" or not?

Forget it! Throw it into GC!

Thanks!

7.Re:一个神奇的错误,谁可改正? [Re: java_ee] Copy to clipboard
Posted by: ranchgirl
Posted on: 2006-01-03 00:02

To java_ee

According to your description, it is very possible a repaint problem. Call the component updateUI() method on the proper time will solve your problem.

Good luck!

8.Re:一个神奇的错误,谁可改正? [Re: java_ee] Copy to clipboard
Posted by: 0078chen
Posted on: 2006-01-06 00:45


import java.awt.*;
import javax.swing.*;
public class Test1 extends JApplet{
JTextField xfield1 ;
JLabel xLabel1 ;
Container con;

public void init() {
con=getContentPane();
con.setLayout(new FlowLayout());
xfield1 = new JTextField(6);
xLabel1 = new JLabel("X1");
con.add(xLabel1);
con.add(xfield1);
repaint();
}

public void paint(Graphics g)
{
super.paint(g);
g.drawLine(220,220,50,100);
}
}

9.Re:一个神奇的错误,谁可改正?(有关repaint) [Re: java_ee] Copy to clipboard
Posted by: xuwensheng
Posted on: 2006-01-11 20:05

setSize()?
setVisible()?


   Powered by Jute Powerful Forum® Version Jute 1.5.6 Ent
Copyright © 2002-2021 Cjsdn Team. All Righits Reserved. 闽ICP备05005120号-1
客服电话 18559299278    客服信箱 714923@qq.com    客服QQ 714923