作者sn153246 (sn153246)
看板java
标题[问题] repaint没能即时印出
时间Fri Apr 1 20:04:41 2011
最近练习GUI
我用按键改变panel
可是没办法即时印出 要改变frame大小才可以
以下是大概的程式码
public class DrawPolygon extends JFrame
{
private PolygonsPanel Poly = new PolygonsPanel(); //呼叫Panel
class increasePoly implements ActionListener //假设呼叫了这两个class
{
public void actionPerformed(ActionEvent e)
{
Poly.increase();
}
}
class decreasePoly implements ActionListener
{
public void actionPerformed(ActionEvent e)
{
Poly.decrease();
}
}
}
class PolygonsPanel extends JPanel
{
private static int times = 5;
public void increase() //这边改了times 可是要改frame大小才会重印
{
times++;
repaint();
}
public void decrease()
{
times--;
repaint();
}
protected void paintComponent(Graphics g) //N边形的Polygon
{
super.paintComponent(g);
/* 以下不重要 */
}
}
为什麽不能即时印出来呢?
--
※ 发信站: 批踢踢实业坊(ptt.cc)
◆ From: 123.193.0.248
1F:→ corevalue:validate(); ?? 04/01 23:08
2F:→ sn153246:加过了...没有效 04/01 23:16
3F:→ lui:你的PolygonsPanel是直接放在JFrame里吗 还是还有一层? 04/02 01:17
4F:→ sn153246:是另一层,因为我想把times设成静态 04/02 10:33
5F:→ sn153246:先谢谢各位的回答,我已经成功了 04/02 10:46