Monday, 15 September 2014

java - Cannot find symbol error on compile. -


I am doing a project for class and cleaning my indentation and doing something in my code Can not see the forest for trees and can also help. When I compile, I can get an error. Here's the code.

  JFrame applies public class traffic lights ItemListener {Personal JRadioButton jrbRed; Private JRDObuton JRBIL; Private JRDObutton JR Bgreen; Private button group btg = new button group (); Private Traffic Lights Light light = new traffic lights Light (); // ^ 1 error is here ^ Error 2 Here the public static is zero main (string [] args) {traffic lights frame = new traffic lights;); Frame.setDefaultCloseOperation (3); Frame.setSize (200, 200); Frame.setLocationRelativeTo (zero); Frame.setVisible (true); } Public Traffic Lights () {setTitle ("Traffic Light Signal"); JPNEL P1 = new zpn (); P1.setLayout (New Flow Layout (1)); P1.add (this.light); Jpnell p2 = new zpn (); P2.setLayout (New Flow Layout ()); P2.add (this.jrbRed = New JRadioButton ("Red")); P2.add (this.jrbYellow = New Gerada button ("Yellow")); P2.add (this.jrbGreen = New Geributton ("Green")); This.jrbRed.setMnemonic ('R'); This.jrbYellow.setMnemonic ('Y'); This.jrbGreen.setMnemonic ('g'); This.btg.add (this.jrbRed); This.btg.add (this.jrbYellow); This.btg.add (this.jrbGreen); Set layout (new border layout ()); Plus (p1, "center"); Plus (p2, "south"); This.jrbRed.addItemListener (this); This.jrbYellow.addItemListener (this); This.jrbGreen.addItemListener (this); This.jrbGreen.setSelected (true); This.light.turnOnGreen (); } Public Zero ItemState Change (Item Event E) {if (this.jrbRed.is selected) {this.light.turnOnRed (); } If (this.jrbYellow.isseelected ()) {this.light.turnOnYellow (); } If (this.jrbGreen.is selected) {this.light.turnOnGreen (); } Class LightJePnelle {Private Boolean Lal; Private boolean yellow; Private boolean green; Public Light () {} Public Zero Current Onrade () {this.red = true; This.yellow = false; This.green = false; Repaint (); } Turn on Public Zero () {this.red = false; This.yellow = True; This.green = false; Repaint (); } Public Zero Opening Open Green () {this.red = false; This.yellow = false; This.green = true; Repaint (); } Safe Wired Paint Comonant (Graphics G) {SuperpuntConant (G); If (this.red) {g.setColor (Color.red); Jiphil (10, 10, 20, 20); G.setColor (Color.black); G.draw oval (10, 35, 20, 20); G.draw oval (10, 60, 20, 20); G.drawRect (5, 5, 30, 80); } And if (this.yellow) {g.setColor (Color.yellow); Jiphil (10, 35, 20, 20); G.setColor (Color.black); G.drawRect (5, 5, 30, 80); G.draw oval (10, 10, 20, 20); G.draw oval (10, 60, 20, 20); } And if (this.green) {g.setColor (Color.green); Jiphil (10, 60, 20, 20); G.setColor (Color.black); G.drawRect (5, 5, 30, 80); G.draw oval (10, 10, 20, 20); G.draw oval (10, 35, 20, 20); } And {G. Set color (black color); G.drawRect (5, 5, 30, 80); G.draw oval (10, 10, 20, 20); G.draw oval (10, 35, 20, 20); G.draw oval (10, 60, 20, 20); }} Public dimension getPrefercedSize () {Return new dimension (100, 100); }}}}}    

This is a problem - I have indented the code to be created It is clear ...

  Public Zero Itemstate Change (Item Event E) {if (this.jrbRed.isSelected ()) {this.light.turnOnRed (); } If (this.jrbYellow.isseelected ()) {this.light.turnOnYellow (); } If (this.jrbGreen.is selected) {this.light.turnOnGreen (); } Class LightJePnelle {Private Boolean Lal; Private boolean yellow; Private boolean green; ...   

You are currently declaring the light class inside the itemStateChanged method. I do not think you mean to do this.

In addition, I ask whether you really need Lite should be an internal or nested class. I suggest making it a high level class - at least with the introduction

I also strongly suggest that you are trying to keep your indentation all the time. If your rest of the code is already good, it is easy to see that when someone goes wrong, IDEs like Eclipse are able to indent all your code for you at the touch of a button - I will use you to use that feature Advice to do

No comments:

Post a Comment