我创建了一个小示例程序:
public class Test extends JFrame {
public Test() {
this.setPreferredSize(new Dimension(400, 400));
this.pack();
this.setVisible(true);
this.setDefaultCloseOperation(EXIT_ON_CLOSE);
}
@Override
public void paint(Graphics g) {
super.paint(g);
// define the position
int locX = 200;
int locY = 200;
// draw a line (there is no drawPoint..)
g.drawLine(locX, locY, locX, locY);
}
public static void main(String[] args) {
Test test = new Test();
}
}
Run Code Online (Sandbox Code Playgroud)
您也可以使用更好或更好的paintComponents方法.但是你必须确保它被调用.如果你遇到问题并且没有被调用,你可以使用以下解决方案:为什么paint()/ paintComponent()从未被调用过?
| 归档时间: |
|
| 查看次数: |
28127 次 |
| 最近记录: |