看板 java 關於我們 聯絡資訊
最近練習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
corevalue:validate(); ?? 04/01 23:08
sn153246:加過了...沒有效 04/01 23:16
lui:你的PolygonsPanel是直接放在JFrame裡嗎 還是還有一層? 04/02 01:17
sn153246:是另一層,因為我想把times設成靜態 04/02 10:33
sn153246:先謝謝各位的回答,我已經成功了 04/02 10:46