Eu to tentando editar a cor de fundo do meu programa, com o usuario entrando com a quantidade de vermelho, verde e azul (r,g,b)
Eu as variaveis do tipo int assim:
public static int r, g, b;
E minha variavel color assim:
public static Color coredF = new Color (r , g ,b);
Se eu crio elas assim, tudo bem, nenhum erro. Mas o netbeans me volta um warning: “Uso de variavel estatica nao final durante a inicialização”
Isso eu entendi, as variaveis r, g, b tem que ser declaradas como final. Mas ai eu nao posso editar elas. Por exemplo:
botao1.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent e){
r = Integer.parseInt(redF.getText());
g = Integer.parseInt(greenF.getText());
b = Integer.parseInt(blueF.getText());
}
Clicando no botao1 as variaveis r, g, b receberiam os valores dos respectivos textfields. Mas se eu faço isso, sem declara-las final, o netbeans volta o seguinte erro:
Exception in thread “AWT-EventQueue-0” java.lang.NumberFormatException: For input string: “”
at java.lang.NumberFormatException.forInputString(NumberFormatException.java:48)
at java.lang.Integer.parseInt(Integer.java:470)
at java.lang.Integer.parseInt(Integer.java:499)
at wallpapers.Wallpaper$1.actionPerformed(Wallpaper.java:329)
at javax.swing.AbstractButton.fireActionPerformed(AbstractButton.java:1995)
at javax.swing.AbstractButton$Handler.actionPerformed(AbstractButton.java:2318)
at javax.swing.DefaultButtonModel.fireActionPerformed(DefaultButtonModel.java:387)
at javax.swing.DefaultButtonModel.setPressed(DefaultButtonModel.java:242)
at javax.swing.plaf.basic.BasicButtonListener.mouseReleased(BasicButtonListener.java:236)
at java.awt.Component.processMouseEvent(Component.java:6263)
at javax.swing.JComponent.processMouseEvent(JComponent.java:3267)
at java.awt.Component.processEvent(Component.java:6028)
at java.awt.Container.processEvent(Container.java:2041)
at java.awt.Component.dispatchEventImpl(Component.java:4630)
at java.awt.Container.dispatchEventImpl(Container.java:2099)
at java.awt.Component.dispatchEvent(Component.java:4460)
at java.awt.LightweightDispatcher.retargetMouseEvent(Container.java:4574)
at java.awt.LightweightDispatcher.processMouseEvent(Container.java:4238)
at java.awt.LightweightDispatcher.dispatchEvent(Container.java:4168)
at java.awt.Container.dispatchEventImpl(Container.java:2085)
at java.awt.Window.dispatchEventImpl(Window.java:2478)
at java.awt.Component.dispatchEvent(Component.java:4460)
at java.awt.EventQueue.dispatchEvent(EventQueue.java:599)
at java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:269)
at java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:184)
at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:174)
at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:169)
at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:161)
at java.awt.EventDispatchThread.run(EventDispatchThread.java:122)
Pelo que eu entendi é porque o valor “default” do textfield ta sendo declarado como “”;
Mais como eu resolvo isso? porque se eu declaro com algum numero ele nao da erro, mais nao muda a cor quando eu digito os valores.