public class AnaMetod {
public static void main(String[] args) {
Grafik2D g2 = new Grafik2D(10, 50, "StackOverFlow");
}
}
package kibAr2D;
import java.awt.Graphics;
import javax.swing.JFrame;
import javax.swing.JPanel;
public class Grafik2D extends JPanel {
public static int a, b = 0;
public static String c = "";
public Grafik2D(int a, int b, String c) {
this.a = a;
this.b = b;
this.c = c;
JFrame j = new JFrame();
j.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
j.setTitle("kibAr");
j.setBounds(150, 200, 613, 253);
j.setVisible(true);
}
public void paintComponent(Graphics g){
super.paintComponents(g);
g.drawString(c, a, b);
}
}
我不明白爲什麼paint方法不會調用?也許當JFrame創建然後automaticaly paintComponent和繪製方法調用..那麼我怎麼可以代替這個問題?Java PaintComponent not Called
索裏我的英文不好..
:
2)你應該刪除呼叫到
paintComponents
或更正拼寫? – 2013-03-14 16:08:59我沒有看到你將'Grafik2D'面板添加到'JFrame'中。 – mre 2013-03-14 16:09:29
okey我解決了問題j.add(this);謝謝 – kibar 2013-03-14 16:11:09