0
我正在使用NetBeans GUI生成器,並試圖創建一種「Geogebra」。我對paintComponent的定義有問題。我想在我的組件中使用幾何圖形的數組列表,這是我的JFrame的一個屬性。但是,似乎java不識別數組列表。 這裏那裏的問題的部分代碼:在paintComponent方法中使用屬性
public GUI() {
initComponents();
}
public List<Figure> Liste = new ArrayList<Figure>();
/**
* This method is called from within the constructor to initialize the form.
* WARNING: Do NOT modify this code. The content of this method is always
* regenerated by the Form Editor.
*/
@SuppressWarnings("unchecked")
// <editor-fold defaultstate="collapsed" desc="Generated Code">
private void initComponents() {
jDialog1 = new javax.swing.JDialog();
lblx = new javax.swing.JLabel();
lbly = new javax.swing.JLabel();
txtx = new javax.swing.JTextField();
txty = new javax.swing.JTextField();
btnOkPoint = new javax.swing.JButton();
jDialog2 = new javax.swing.JDialog();
jLabel1 = new javax.swing.JLabel();
jLabel2 = new javax.swing.JLabel();
lblx1 = new javax.swing.JLabel();
lbly1 = new javax.swing.JLabel();
lblx2 = new javax.swing.JLabel();
lbly2 = new javax.swing.JLabel();
txtx1 = new javax.swing.JTextField();
txty1 = new javax.swing.JTextField();
txtx2 = new javax.swing.JTextField();
txty2 = new javax.swing.JTextField();
btnoksegment = new javax.swing.JButton();
MainPan = new javax.swing.JPanel();
GraphPan = new javax.swing.JPanel(){
@Override
public void paintComponent(Graphics g) {
for (int i = 0; i < this.Liste.size(); i++) {
if(this.Liste.get(i) instanceof Pts){
Pts p = (Pts)this.Liste.get(i);
g.fillOval((int)Math.round(p.x),(int)Math.round(p.y), 10, 10);
}
if(this.Liste.get(i) instanceof Segment) {
Segment s = (Segment)this.Liste.get(i) ;
Segment s = (Segment) this.Liste.get(i);
g.drawLine(s.debut.x, s.debut.y, s.fin.x, s.fin.y);
}
}
}
};
謝謝,它的工作原理:d – Omar6995 2014-12-03 21:48:09