[問題] repaint沒能即時印出
最近練習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
→
04/01 23:08, , 1F
04/01 23:08, 1F
→
04/01 23:16, , 2F
04/01 23:16, 2F
→
04/02 01:17, , 3F
04/02 01:17, 3F
→
04/02 10:33, , 4F
04/02 10:33, 4F
→
04/02 10:46, , 5F
04/02 10:46, 5F