J'ai créé ce code qui est censé dessiner certaines choses quand j'ai sélectionné un bouton radio sur un JForm, j'ai utilisé NetBeans pour créer l'interface graphique. Lorsque je sélectionne un bouton radio, rien ne se passe. J'ai essayé de comprendre ce qui ne va pas pendant un moment, mais je n'arrive toujours pas à trouver une solution, c'est pourquoi je suis venu ici. Si quelqu'un pouvait repérer une erreur, je serais reconnaissant.Dessiner des formes sur un JForm java
public class DrawShapesGUI extends javax.swing.JFrame {
private int figureID;
public DrawShapesGUI() {
initComponents();
repaint();
}
@SuppressWarnings("unchecked")
// <editor-fold defaultstate="collapsed" desc="Generated Code"></editor-fold>
private void lineButtonActionPerformed(java.awt.event.ActionEvent evt) {
int figureID = 1;
repaint();
}
private void rectButtonActionPerformed(java.awt.event.ActionEvent evt) {
int figureID = 2;
repaint();
}
private void ovalButtonActionPerformed(java.awt.event.ActionEvent evt) {
int figureID = 3;
repaint();
}
private void arcButtonActionPerformed(java.awt.event.ActionEvent evt) {
int figureID = 4;
repaint();
}
private void polygonButtonActionPerformed(java.awt.event.ActionEvent evt) {
int figureID = 5;
repaint();
}
public static void main(String args[]) {
/* Set the Nimbus look and feel */
//<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) ">
/* If Nimbus (introduced in Java SE 6) is not available, stay with the default look and feel.
* For details see http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html
*/
try {
for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {
if ("Nimbus".equals(info.getName())) {
javax.swing.UIManager.setLookAndFeel(info.getClassName());
break;
}
}
} catch (ClassNotFoundException ex) {
java.util.logging.Logger.getLogger(DrawShapesGUI.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
} catch (InstantiationException ex) {
java.util.logging.Logger.getLogger(DrawShapesGUI.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
} catch (IllegalAccessException ex) {
java.util.logging.Logger.getLogger(DrawShapesGUI.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
} catch (javax.swing.UnsupportedLookAndFeelException ex) {
java.util.logging.Logger.getLogger(DrawShapesGUI.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
}
//</editor-fold>
/* Create and display the form */
java.awt.EventQueue.invokeLater(new Runnable() {
public void run() {
new DrawShapesGUI().setVisible(true);
}
});
}
@Override
public void paint(Graphics g) {
super.paint(g);
g.setColor(Color.red);
if (figureID == 1) {
g.drawLine(50, 50, 100, 100);
} else if (figureID == 2) {
g.fillRect(50, 50, 100, 100);
} else if (figureID == 3) {
g.fillOval(100, 100, 100, 60);
} else if (figureID == 4) {
g.drawArc(50, 50, 200, 200, 90, 30);
} else if (figureID == 5) {
Polygon poly = new Polygon();
poly.addPoint(100, 50);
poly.addPoint(150, 50);
poly.addPoint(200, 100);
poly.addPoint(150, 150);
poly.addPoint(100, 150);
poly.addPoint(50, 100);
g.fillPolygon(poly);
}
}
* "Si quelqu'un pouvait repérer une erreur que je serais reconnaissant. "* Un' JFrame' fait partie de Java. Un JForm est connu uniquement de votre IDE. Parlez Java, pas Netbeans. –