I am currently trying to create a piano keyboard and wanted to include themes, i figured the best way to do that was present the option on startup, to ask the question of what theme to use, tried and the radio buttons were not working and I have kinda deduced it down to the initComponents() method of the class KeyboardGUIClassic not functioning when being called, any help, tips or suggestions on the problem or even the program would be helpful.
The only direct modification I did to try and solve the issue of initComponents(), was to change it to public but it is not working,I also used a try and catch block to determine what was not working. I feel that it is something to do with the fact that NetBeans autogenerates it through the GUI Editor, but I cannot switch IDEs due to the fact that this is a summative assignment.
Code:
public class Startup extends javax.swing.JFrame {
public Startup() {
initComponents();
}
/**
* 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() {
btnG = new javax.swing.ButtonGroup();
jLabel1 = new javax.swing.JLabel();
btnTheme1 = new javax.swing.JRadioButton();
btnTheme2 = new javax.swing.JRadioButton();
btnTheme3 = new javax.swing.JRadioButton();
btnLaunch = new javax.swing.JButton();
setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
jLabel1.setFont(new java.awt.Font("Segoe UI", 0, 36)); // NOI18N
jLabel1.setText("Select Theme:");
btnG.add(btnTheme1);
btnTheme1.setText("Classic");
btnG.add(btnTheme2);
btnTheme2.setText("Barebones");
btnG.add(btnTheme3);
btnTheme3.setText("Instructional");
btnLaunch.setText("Ok");
btnLaunch.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
btnLaunchActionPerformed(evt);
}
});
javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
getContentPane().setLayout(layout);
layout.setHorizontalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addGap(37, 37, 37)
.addComponent(jLabel1))
.addGroup(layout.createSequentialGroup()
.addGap(95, 95, 95)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(btnTheme2, javax.swing.GroupLayout.PREFERRED_SIZE, 98, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(btnTheme1, javax.swing.GroupLayout.PREFERRED_SIZE, 98, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(btnTheme3, javax.swing.GroupLayout.PREFERRED_SIZE, 98, javax.swing.GroupLayout.PREFERRED_SIZE)))
.addGroup(layout.createSequentialGroup()
.addGap(103, 103, 103)
.addComponent(btnLaunch)))
.addContainerGap(37, Short.MAX_VALUE))
);
layout.setVerticalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addContainerGap()
.addComponent(jLabel1)
.addGap(18, 18, 18)
.addComponent(btnTheme1)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(btnTheme2)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(btnTheme3)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(btnLaunch)
.addContainerGap(20, Short.MAX_VALUE))
);
pack();
}// </editor-fold>
private void btnLaunchActionPerformed(java.awt.event.ActionEvent evt) {
KeyboardGUIClassic KeyboardGUIClassic = new KeyboardGUIClassic();
KeyboardGUIBarebones guiBarebones = new KeyboardGUIBarebones();
KeyboardGUIInstructional guiInstruct = new KeyboardGUIInstructional();
KeyboardGUIClassic.initComponents();
/*
if (btnTheme1.isSelected()) {
guiClassic.GUICall();
System.exit(0);
}
else if (btnTheme2.isSelected()) {
guiBarebones.GUICall();
System.exit(0);
}
else if (btnTheme3.isSelected()) {
guiInstruct.GUICall();
System.exit(0);
}
*/
}
public class KeyboardGUIClassic extends javax.swing.JFrame {
public void GUICall() {
try {
initComponents();
System.out.println("calling");
}
catch (Exception e) {
System.out.println("not calling");
}
}
/**
* 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">
public void initComponents() {
// too much to put in post but guts are here, this function is not being called upon
}
Just in case the info is needed, these are across two seperate files, named by
Oxi is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.