drawString在我当前窗口的屏幕快照上打印字符串 [英] drawString prints string over a screenshot of my current window
本文介绍了drawString在我当前窗口的屏幕快照上打印字符串的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
当我在Eclipse中运行此代码时,我在新窗口中获得了字符串和行打印,但是它不是空白窗口,而是我当前窗口的屏幕快照,设置为我声明的大小.
When I run this code in Eclipse I get a the string and line printing in a new windows, but instead of a blank window it simply is a screenshot of my current window, set to the size I declare.
http://i.imgur.com/nWFN9YJ.png
关于我在做什么错的任何建议?
Any suggestions on what I'm doing wrong?
import java.awt.Graphics;
import javax.swing.JFrame;
public class EmptyFrame2 extends JFrame
{
public static void main(String args[])
{
EmptyFrame2 JF=new EmptyFrame2();
JF.setSize(1000,500);
JF.setVisible(true);
}
public void paint(Graphics g)
{
g.drawString("Hello",50,50);
//g.drawLine(50-2, 50+2, 50+70, 50+2);
}
如果这太含糊,请告诉我,我将对其进行更改或添加您需要的其他任何内容.
If this is too vague let me know and I'll change it or add whatever else you need.
推荐答案
- 避免覆盖顶级组件的
paint
- 避免打破油漆链,让您超级称呼
super.paintXxx
- 改用
JPanel
之类的paintComponent
代替 - Avoid overriding
paint
of top level components - Avoid breaking the paint chain, making super you call
super.paintXxx
- Override
paintComponent
of something likeJPanel
instead
请参见执行自定义绘画
这篇关于drawString在我当前窗口的屏幕快照上打印字符串的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文