Мне нужно рисовать круги с помощью graphics2D, я уже знаю, кому их рисовать, но они мне нужны внутри c JPanel. Я пробовал много способов, но они не работали, и все кнопки и другие JPanel исчезают. Класс известен как VentanaPintado, а панель для рисования внутри называется TestingPanelGraphics. Я пробовал создавать классы jPlanel, но он не работает, не знаю, сделал ли я это неправильно, но там я пишу код. Кто-нибудь может мне помочь? Спасибо! :)
public class VentanaPintado extends javax.swing.JFrame {
public VentanaPintado() {
initComponents();
this.setVisible(true);
}
@SuppressWarnings("unchecked")
private void initComponents() {
jLabel3 = new javax.swing.JLabel();
jPanel1 = new javax.swing.JPanel();
TestingPanelGraphics = new javax.swing.JPanel();
Siguiente = new javax.swing.JButton();
jLabel3.setFont(new java.awt.Font("Times New Roman", 0, 24)); // NOI18N
jLabel3.setForeground(new java.awt.Color(255, 255, 255));
jLabel3.setText("Seleccione:");
setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
jPanel1.setBackground(new java.awt.Color(68, 49, 141));
TestingPanelGraphics.setMaximumSize(new java.awt.Dimension(500, 500));
TestingPanelGraphics.setMinimumSize(new java.awt.Dimension(500, 500));
TestingPanelGraphics.setPreferredSize(new java.awt.Dimension(500, 500));
TestingPanelGraphics.setRequestFocusEnabled(false);
javax.swing.GroupLayout TestingPanelGraphicsLayout = new javax.swing.GroupLayout(TestingPanelGraphics);
TestingPanelGraphics.setLayout(TestingPanelGraphicsLayout);
TestingPanelGraphicsLayout.setHorizontalGroup(
TestingPanelGraphicsLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGap(0, 500, Short.MAX_VALUE)
);
TestingPanelGraphicsLayout.setVerticalGroup(
TestingPanelGraphicsLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGap(0, 500, Short.MAX_VALUE)
);
Siguiente.setBackground(new java.awt.Color(217, 176, 255));
Siguiente.setFont(new java.awt.Font("Tw Cen MT Condensed Extra Bold", 0, 24)); // NOI18N
Siguiente.setText("Empezar");
Siguiente.setToolTipText("");
javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
jPanel1.setLayout(jPanel1Layout);
jPanel1Layout.setHorizontalGroup(
jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(jPanel1Layout.createSequentialGroup()
.addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(jPanel1Layout.createSequentialGroup()
.addGap(221, 221, 221)
.addComponent(Siguiente, javax.swing.GroupLayout.PREFERRED_SIZE, 210, javax.swing.GroupLayout.PREFERRED_SIZE))
.addGroup(jPanel1Layout.createSequentialGroup()
.addGap(86, 86, 86)
.addComponent(TestingPanelGraphics, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)))
.addContainerGap(405, Short.MAX_VALUE))
);
jPanel1Layout.setVerticalGroup(
jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel1Layout.createSequentialGroup()
.addContainerGap()
.addComponent(TestingPanelGraphics, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addGap(35, 35, 35)
.addComponent(Siguiente, javax.swing.GroupLayout.PREFERRED_SIZE, 50, javax.swing.GroupLayout.PREFERRED_SIZE)
.addContainerGap(43, Short.MAX_VALUE))
);
javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
getContentPane().setLayout(layout);
layout.setHorizontalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(jPanel1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
);
layout.setVerticalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addComponent(jPanel1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addGap(0, 0, Short.MAX_VALUE))
);
pack();
}
public static void main(String args[]) {
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(VentanaPintado.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
} catch (InstantiationException ex) {
java.util.logging.Logger.getLogger(VentanaPintado.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
} catch (IllegalAccessException ex) {
java.util.logging.Logger.getLogger(VentanaPintado.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
} catch (javax.swing.UnsupportedLookAndFeelException ex) {
java.util.logging.Logger.getLogger(VentanaPintado.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
}
//</editor-fold>
java.awt.EventQueue.invokeLater(new Runnable() {
public void run() {
new VentanaPintado().setVisible(true);
}
});
}
private javax.swing.JButton Siguiente;
private javax.swing.JPanel TestingPanelGraphics;
private javax.swing.JLabel jLabel3;
private javax.swing.JPanel jPanel1;
}