java - Button Function Not Working? -
Then I'm trying to write a program using swing components, whenever a user clicks on a button , Appears in a different word in the text box I say, "The temporary method button () can not be referred to by a static reference" I received an error saying, "I checked other answers that it was the same How to fix with error, l Q: I still can not understand it. Here it appears:
color.buttons ();
And this is my code:
import java AWT *. Import java.awt.event. *; Import javax.swing. *; The color of the public class {Private JFrame f; Private JLL label; Personal zipal control panel; Private Pocket button 1; Personal pocket button 2; Personal pocket button 3; Private JTextField text box; Public color () {readyGUI;} Public static zero main (string AGR []) {color C = new color (); color. Buttons ();} private Zero preparedGUI () {f = new JFrame ("color"); F.setSize (400, 400); F.addWindowListener (New Window Adapter) {Public Zero Window Closure (Window Event Window Event) {System.exit (0);}}); Label = new JLabel ("", JLabel CA.); the label. Setbound (20, 105, 200, 25); Textbox = new JTextField ("", JTextField.CENTER); Textbox.setBounds (20, 75, 125, 50); F.add (label); F.add (text box); F.setVisible (true); } Private Zero button () {label.setText ("Click on a button to reveal text"); Textbox.setText ("Which Color?"); Pocket button 1 = new pocket ("blue"); Button 1 Setbound (10, 305, 120, 75); Pocket button 2 = new pocket ("red"); Button 2 .Setbound (140, 305, 120, 75); Jebton Button 3 = New Pocket ("Yellow"); Button 3 Setbound (270, 305, 120, 75); Button1.addActionListener (new executable () {PublicExchange Evt} {textbox.setText ("Blue");}}); Button2.addActionListener (new executable () {Executed public zero action} {textbox.setText ("Red");}}); Button3.addActionListener (new exclamationist) {ActionEvent evt} {textbox.setText ("Yellow");}}); ControlPanel.add (Button1); ControlPanel.add (Button2); ControlPanel.add (Button3); F.setVisible (true); }}
you c.buttons ();
instead of color.buttons (); As non-static methods can not be referred directly to
, you need an object to do so.
Where if the method is stable, then you color.buttons ();
.
Comments
Post a Comment