### Author Topic: What am i doing wrong here?  (Read 2787 times)

0 Members and 1 Guest are viewing this topic.

• Posts: 295
• Rating: +20/-1
• Its 0x1A4 somewhere
##### What am i doing wrong here?
« on: September 16, 2011, 06:27:05 pm »
Ive tried compiling a program on 2 different computers using this code:
Code: (java) [Select]
 button1.setBounds(5, 5, 100, 60); button2.setBounds(5, 60, 100, 60);
on one computer it says "symbol not found" on setBounds (ofc i have awt.* and swing.* included)

on the other it says "illegal start of type" on the the first arg, and "<identifier> expected" after setBounds

Also, when i try to define an array, it keeps telling me that i need 2 closing brackets and that i need a semicolon inside the brackets...

#### Builderboy

• Physics Guru
• CoT Emeritus
• LV13 Extreme Addict (Next: 9001)
• Posts: 5673
• Rating: +613/-9
• Would you kindly?
##### Re: What am i doing wrong here?
« Reply #1 on: September 16, 2011, 06:33:31 pm »
It would help to see more of the code, like where you declared the buttons, and where you are trying to create the arrays.  What type of object are the buttons?

• Posts: 295
• Rating: +20/-1
• Its 0x1A4 somewhere
##### Re: What am i doing wrong here?
« Reply #2 on: September 16, 2011, 07:12:09 pm »
Code: (moar java) [Select]
import javax.swing.*;import java.awt.*;import java.awt.event.*;class herp extends JFrame { JButton button1 = new JButton("Derp"); JButton button2 = new JButton("Lolwut"); button1.setBounds(5, 5, 100, 60); button2.setBounds(5, 60, 100, 60); public herp() { super("Window"); setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); add(button1); add(button2); pack(); }}class window { public static void main(String[] args) { herp hai = new herp(); hai.setVisible(true); }}
And the arrays are in here:
Code: (arrayzz) [Select]
import java.awt.*;import javax.swing.*;import java.awt.event.*;class map extends JPanel { int mapMatrix[][] = new int[15][10]; String tiles[] = new String[2]; map() { this.setBounds(0, 25, 960, 640); for(int x = 0; x < 15; x++) { for(int y = 0; y < 10; y++) { ImageIcon tile = new ImageIcon(tiles[mapMatrix[x][y]]); tile.setBounds(((x + 1) * 64), ((y + 1) * 64), 64, 64); this.add(tile); tile.setVisible(true); this.setVisible(true); } } }}
There may be other errors but im concerned with why javac is telling me to put extra closing brackets and stuff.

EDIT: i just compiled that second one on this computer and its giving me different errors. using the same version of jdk...

Maybe im just dreaming...nothing is making any kind of sense.
« Last Edit: September 16, 2011, 07:15:48 pm by Broseph Radson »

#### Builderboy

• Physics Guru
• CoT Emeritus
• LV13 Extreme Addict (Next: 9001)
• Posts: 5673
• Rating: +613/-9
• Would you kindly?
##### Re: What am i doing wrong here?
« Reply #3 on: September 16, 2011, 07:16:29 pm »
The syntax for an array is int[] array = new int[5], not int array[] = new int[5].

The second issue is that you cannot do commands outside of a method, so you will need to move the two button.setBounds into the constructor or wherever you want them

• Posts: 295
• Rating: +20/-1
• Its 0x1A4 somewhere
##### Re: What am i doing wrong here?
« Reply #4 on: September 16, 2011, 07:21:39 pm »
Ah, ive seen arrays defined both ways before. I guess i was reading in the wrong places

I think my computer at school is just messed up as this computer doesnt give me any of those errors...
I had like 57 errors on a tiny program, on this computer it only gave me 4...

Thanks, though!

« Last Edit: September 16, 2011, 07:24:28 pm by Broseph Radson »

#### Builderboy

• Physics Guru
• CoT Emeritus
• LV13 Extreme Addict (Next: 9001)
• Posts: 5673
• Rating: +613/-9
• Would you kindly?
##### Re: What am i doing wrong here?
« Reply #5 on: September 16, 2011, 07:22:14 pm »
No problem!  You might have been seeing some C++ code, as I think thats how they define arrays o.O

• Posts: 295
• Rating: +20/-1
• Its 0x1A4 somewhere
##### Re: What am i doing wrong here?
« Reply #6 on: September 16, 2011, 07:24:44 pm »
Another issue: The second one says "cannot find symbol" on setBounds, add, and setVisible. All are within a method.

#### JL235

• LV3 Member (Next: 100)
• Posts: 57
• Rating: +13/-0
##### Re: What am i doing wrong here?
« Reply #7 on: September 16, 2011, 08:04:48 pm »
Another issue: The second one says "cannot find symbol" on setBounds, add, and setVisible. All are within a method.
Your calling those methods on the 'tile' object, which is an ImageIcon, and doesn't have those methods. In the compiler error...
Code: [Select]
map.java:19: cannot find symbolsymbol  : method setVisible(boolean)location: class javax.swing.ImageIcon                                tile.setVisible(true);... where it says 'location', that is what tells you that it is failing to find 'setVisible' in the 'javax.swing.ImageIcon' class. You also cannot add an ImageIcon directly to a JPanel.

A third thing, it's convention to start class names with a capital letter. Notice this is the case with 'JPanel' and 'ImageIcon', so I heavily advise you call your class 'Map' rather then 'map'.
Build games in the browser at PlayMyCode.com, @playmycode