我在Windows上的NetBeans 7.3.1使用Java SE開發7.javax.swing.JFrame中被覆蓋
我的Java的主要方法有以下電話
static Vector<Point2D> acceptedByFilter, coords;
// Some code to read the coords from a file
// Some code to filter coords and produce a subset called acceptedByFilter
DisplayInputPoints();
DisplayPointsAcceptedByFilter();
這些方法的定義如下
static protected void DisplayPointsAcceptedByFilter(){
Panel panel=new Panel();
panel.DisplayInputPoints(acceptedByFilter, xMin, xMax, yMin, yMax, true, "Points accepted by filter");
}
static void DisplayInputPoints(){
Panel panel=new Panel();
panel.DisplayInputPoints(coords, xMin, xMax, yMin, yMax, true, "Original Points");
}
Panel.DisplayInputPoints定義如下
import javax.swing.JFrame;
import javax.swing.JPanel;
public
class Panel extends JPanel
{
public static void DisplayInputPoints(Vector<Point2D> coords, double xMin, double xMax, double yMin,
double yMax, boolean invert, String label){
JFrame frame = new JFrame(label);
Panel panel = new Panel();
panel.setPreferredSize(new Dimension((int)Math.round(xMax-xMin) + 10,
(int)Math.round(yMax-yMin) + 10));
panel.loadPoints(coords);
frame.setContentPane(panel);
frame.pack();
frame.setVisible(true);
frame.repaint();
}
}
當我打電話
DisplayInputPoints();
第一幀出現,它顯示在COORDS矢量的點。當我打電話
DisplayPointsAcceptedByFilter();
我得到另一個框架並在acceptedByFilter點出現在都幀。也就是說,第一幀被第二幀中的顯示覆蓋。
什麼是最好的方法來阻止第一幀被應該只在第二幀中被覆蓋?
請參閱[使用多個JFrames,好/壞實踐?](http://stackoverflow.com/a/9554657/418556) –