Topic: Frame和 Panel中drawString()的用法问题

  Print this page

1.Frame和 Panel中drawString()的用法问题 Copy to clipboard
Posted by: songbenlijia
Posted on: 2004-11-01 00:00

{请您尽快修改您的贴名------------already changed }

DrawNoCanvas.java
运行结果特别的奇怪,各位研究一下
源代码如下:
import java.awt.*;
import java.awt.event.*;

public class DrawNoCanvas
extends Frame {
private Button button = new Button("draw");

private class WindowCloser
extends WindowAdapter {
public void windowClosing(WindowEvent e) {
System.exit(0);
}
}

public DrawNoCanvas() {
super("NoCanvas");

Panel panel = new Panel();
panel.setLayout(new FlowLayout());
panel.add(button);
setLayout(new BorderLayout());
add("Center", panel);
setSize(150, 150);
setVisible(true);
addWindowListener(new WindowCloser());
}

public void paint(Graphics g) {
for (int i = 12; i < getSize().height; i = +12) {
g.drawString("y location: " + i, 10, i);
}
}

public static void main(String argv []) {
DrawNoCanvas drawNoCanvas=new DrawNoCanvas();
}
}

2.Re:这个问题够奇怪的,请各位天才进来看看啊! [Re: songbenlijia] Copy to clipboard
Posted by: littledeer1974
Posted on: 2004-11-01 09:04

请您在一天之内更改您的贴名,否则删除
{贴名没有反应出贴子内容,或与贴子内容无关}
有任何疑问请查看[加贴须知]

#你说说你的程序为什么奇怪,你不说明,别人还以为你的[症状]就是你要的[效果]呢,把你想实现的效果也描述一下,还有就是你的思路什么的,这样也能多给大家一些帮助你的线索,你觉得呢,拜托了,谢谢

3.Re:这个问题够奇怪的,请各位天才进来看看啊! [Re: littledeer1974] Copy to clipboard
Posted by: 牛老板
Posted on: 2004-11-01 09:08

小LU哥,你还是帮他改一下标题吧,下次他就明白了.

这样,可能会吓到楼主啊...

4.Re:这个问题够奇怪的,请各位天才进来看看啊! [Re: 牛老板] Copy to clipboard
Posted by: littledeer1974
Posted on: 2004-11-01 09:13

恩,你说的也对,就是想让他知道嘛,他肯定没有好好看[加贴须知]
这样,有[法]不依,没有意义嘛
最终,其实是不利于大家讨论,不利于论坛发展,真心的希望大家遵守呀

------------------------------------------------------------------------------------------------------------
你看这个是不是你想要的呀,不符合你要求的,你可以自己改一改(编译,执行通过)


import java.awt.*;
import java.awt.event.*;

public class DrawNoCanvas extends Frame {
  private Button button;

  private class WindowCloser extends WindowAdapter {
    public void windowClosing(WindowEvent e) {
      System.exit(0);
    }
  }

  public DrawNoCanvas() {
    super("NoCanvas");
    button = new Button("Draw");
    final Panel panel = new Panel();

    final Graphics g = panel.getGraphics();
    button.addActionListener(new ActionListener() {

      public void actionPerformed(ActionEvent arg0) {
        paint(panel.getGraphics());

      }
    });

    this.add("South", button);

    this.add("Center", panel);

    setSize(450, 450);
    setVisible(true);
    addWindowListener(new WindowCloser());
  }

  public void paint(Graphics g) {
    for (int i = 12; i < 240; i = i + 12) {
      g.drawString("test", 240 - i, 100 - i);
    }
  }

  public static void main(String argv[]) {
   new DrawNoCanvas();
  }
}


   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