我是一個沒有經驗的人(除非你計算在70年代早期的PDP-8)程序員在封閉類中的重繪方法掙扎。在JPanel中重畫查詢
該課程旨在顯示當地的航空地圖,然後在地圖上繪製小圓圈以繪製飛機通道。隨着時間的推移,地圖將顯示飛機在當地機場降落後使用的最常用路徑。
問題是,經過一天的努力,我仍然無法進行重繪工作。
的Class關心Graphics是:
package com.slatter.radarboxconnect;
import java.awt.*;
import java.awt.image.BufferedImage;
import java.io.File;
import java.io.IOException;
import javax.imageio.ImageIO;
import javax.swing.*;
/**
* A RADAR Plotting Frame
*/
public class DrawPanel extends JPanel {
public static BufferedImage img = null; // Create a BufferedImage object
public int cx = 700,cy = 500,cdia = 70; // Aircraft Echo parameters
public DrawPanel() {
// Create Graphic of map
try {
img = ImageIO.read(new File("full.jpeg")); //Get the map
} catch (IOException e){
}
}
@Override
public void paintComponent(Graphics g) {
super.paintComponent(g);
//Draw the Map and a sample red dot
g.drawImage(img, 0, 0, 1400, 1000, 0, 0, 1400, 1000, null);
g.setColor(Color.red);
g.drawOval(cx,cy, cdia, cdia);
g.fillOval(cx,cy, cdia, cdia);
}
public void DpPlotEcho(int x, int y, int pdia) {
cx=x;
cy=y;
cdia=pdia;
repaint(cx,cy,cdia,cdia);
}
}
我創建此面板在一個單獨的幀,並調用從App的主體上的DpPlotEcho()方法。
地圖和屏幕中央的小紅點顯示正確,但未嘗試通過DpPlotEcho()方法重新繪製更新。
所以兩個問題:
- 我如何說服重繪工作(主要的問題)和
- 我如何確保所有的點在屏幕上停留。
非常感謝您的幫助。非常感激。我會探索。 – 2013-03-26 12:48:18