( IM USING NETBEANS FOR JAVA GUI )
I have 2 Jframe. Mainmenu and Purchase.
In the Mainmenu Jframe, i have put a button and named it “Continue”. (with some other things, ofc)
Inside the “Continue Button” i used this code:
Purchase purchase = new Purchase();
//--------------Toyota---------------
if(InputTinnova.isSelected())
{
String mobil = "Toyota Innova";
Purchase.Onamamobil.setText(mobil);
}
if(InputTavanza.isSelected())
{
String mobil = "Toyota Avanza";
}
if(InputTalphard.isSelected())
{
String mobil = "Toyota Alphard";
}
if(InputTsupra.isSelected())
{
String mobil = "Toyota Supra";
}
//--------------NISSAN---------------
if(InputNlivina.isSelected())
{
String mobil = "Nissan Livina";
}
if(InputNserena.isSelected())
{
String mobil = "Nissan Serena";
}
if(InputNterra.isSelected())
{
String mobil = "Nissan Terra";
}
if(InputNgtr.isSelected())
{
String mobil = "Nissan GTR";
}
//--------------Mazda---------------
if(InputMcx.isSelected())
{
String mobil = "Mazda CX";
}
if(InputMmx.isSelected())
{
String mobil = "Mazda MX";
}
if(InputM3.isSelected())
{
String mobil = "Mazda 3";
}
if(InputMrx.isSelected())
{
String mobil = "Mazda RX";
}
purchase.show();
dispose();
the variable Onamamobil is the Jlabel i want to change, but it keeps giving me an error saying “Non static variable Onamamobil cannot be referenced from a static content”. i made the Onamamobil a public Jlabel text, too.
I want the code from Mainmenu jframe
String mobil = "Toyota Innova";
Purchase.Onamamobil.setText(mobil);
changes the jlabel Onamamobil in the jframe Purchase.
02_Andhika Farizky Mansyur is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.