 |
AppletTalk.com Java discussions newsgroups
|
| View previous topic :: View next topic |
| Author |
Message |
Kevin Guest
|
Posted: Thu Mar 24, 2005 4:05 am Post subject: "AssignmentOperator ArrayInitializer" error |
|
|
Hi! I'm typing in a program from a magazine and I'm pretty sure I've
typed it in correctly. However, I'm getting an error in one section of
the program, the class SizeListener. The error is: "Syntax error,
insert 'AssignmentOperator ArrayInitializer' to complete Expression."
I have no idea what this is trying to tell me. Can anyone look at the
code below and tell what's wrong with it?
Thanks!
public class SizeListener implements ItemListener {
public void itemStateChanged(ItemEvent e) {
if(e.getStateChange() == ItemEvent.SELECTED) {
String item = (String)e.getItem() ;
JViewport viewport ;
int size ;
if("2x2".equals(item))
size = 2 ;
else if("4x4".equals(item))
size = 4 ;
else if("8x8".equals(item))
size = 8 ;
else
size = 16 ;
board.setBoardSize(size, size) ;
viewport = boardContainer.getViewport() ;
viewport.setViewPosition(new Point(0, 0)) ;
repaint() ;
}
}
}
|
|
| Back to top |
|
 |
Roland Guest
|
Posted: Thu Mar 24, 2005 3:13 pm Post subject: Re: "AssignmentOperator ArrayInitializer" error |
|
|
On 24-3-2005 5:05, Kevin wrote:
| Quote: | Hi! I'm typing in a program from a magazine and I'm pretty sure I've
typed it in correctly. However, I'm getting an error in one section of
the program, the class SizeListener. The error is: "Syntax error,
insert 'AssignmentOperator ArrayInitializer' to complete Expression."
I have no idea what this is trying to tell me. Can anyone look at the
code below and tell what's wrong with it?
Thanks!
public class SizeListener implements ItemListener {
public void itemStateChanged(ItemEvent e) {
if(e.getStateChange() == ItemEvent.SELECTED) {
String item = (String)e.getItem() ;
JViewport viewport ;
int size ;
if("2x2".equals(item))
size = 2 ;
else if("4x4".equals(item))
size = 4 ;
else if("8x8".equals(item))
size = 8 ;
else
size = 16 ;
board.setBoardSize(size, size) ;
viewport = boardContainer.getViewport() ;
viewport.setViewPosition(new Point(0, 0)) ;
repaint() ;
}
}
}
|
I've copied your code into the Eclipse source editor, but there's no
syntax error in the class above. However, the variables 'board',
'boardContainer', and the method 'repaint' are undefined.
Are you sure that the syntax error is in the code you've shown us? How
did you compile it? Does the error message show a line number?
--
Regards,
Roland de Ruiter
___ ___
/__/ w_/ /__/
/ /_/ /
|
|
| Back to top |
|
 |
Kevin Guest
|
Posted: Fri Mar 25, 2005 12:02 am Post subject: Re: "AssignmentOperator ArrayInitializer" error |
|
|
Roland wrote:
| Quote: | On 24-3-2005 5:05, Kevin wrote:
Hi! I'm typing in a program from a magazine and I'm pretty sure I've
typed it in correctly. However, I'm getting an error in one section
of the program, the class SizeListener. The error is: "Syntax error,
insert 'AssignmentOperator ArrayInitializer' to complete Expression."
I have no idea what this is trying to tell me. Can anyone look at the
code below and tell what's wrong with it?
Thanks!
public class SizeListener implements ItemListener {
public void itemStateChanged(ItemEvent e) {
if(e.getStateChange() == ItemEvent.SELECTED) {
String item = (String)e.getItem() ;
JViewport viewport ;
int size ;
if("2x2".equals(item))
size = 2 ;
else if("4x4".equals(item))
size = 4 ;
else if("8x8".equals(item))
size = 8 ; else
size = 16 ;
board.setBoardSize(size, size) ;
viewport = boardContainer.getViewport() ;
viewport.setViewPosition(new Point(0, 0)) ;
repaint() ;
}
}
}
I've copied your code into the Eclipse source editor, but there's no
syntax error in the class above. However, the variables 'board',
'boardContainer', and the method 'repaint' are undefined.
Are you sure that the syntax error is in the code you've shown us? How
did you compile it? Does the error message show a line number?
Roland, |
Hi! I'm using Eclipse to type this program in. Here is the entire
source code. Sorry for the formatting. The lines appear to be wrapping
, throwing off the format. By the way, I'm not getting that error any
longer. I'm not sure what the problem was because when I saved the
source last night, I didn't change anything. When I loaded it just now,
there was no error! Very strange...
Thanks!
Kevin
package example ;
import java.awt.* ;
import java.awt.event.* ;
import javax.swing.* ;
public class JavaCheckerboard extends JPanel {
public static class BoardPanel extends JPanel {
int width, height, tileWidth, tileHeight ;
int[] initX ;
public BoardPanel(int width, int height,
int tileWidth, int tileHeight) {
initX = new int[2] ;
setBoardSize(width, height, tileWidth, tileHeight) ;
}
public void setBoardSize( int width, int height, int tileWidth, int
tileHeight)
{
this.tileWidth = tileWidth ;
this.tileHeight = tileHeight ;
initX[0] = 0 ;
initX[1] = tileWidth ;
setBoardSize(width, height) ;
}
public void setBoardSize(int height, int width) {
Dimension size ;
this.width = width * tileWidth ;
this.height = height*tileHeight ;
size = new Dimension(this.width, this.height) ;
setPreferredSize(size) ;
}
private void paintTiles (Graphics g, int firstTile, Color color)
{
int x, y = 0, dx = 2*tileWidth ;
g.setColor(color) ;
while(y < height) {
x = initX[firstTile] ;
while(x < width) {
g.fillRect(x, y, tileWidth, tileHeight);
x+=dx ;
}
y+=tileHeight ;
firstTile ^= 1 ;
}
}
public void paint(Graphics g) {
paintTiles(g, 0, Color.WHITE) ;
paintTiles(g, 1, Color.BLACK) ;
}
}
BoardPanel board ;
JScrollPane boardContainer ;
public class SizeListener implements ItemListener {
public void itemStateChanged(ItemEvent e) {
if(e.getStateChange() == ItemEvent.SELECTED) {
String item = (String)e.getItem() ;
JViewport viewport ;
int size ;
if("2x2".equals(item))
size = 2 ;
else if("4x4".equals(item))
size = 4 ;
else if("8x8".equals(item))
size = 8 ;
else
size = 16 ;
board.setBoardSize(size, size) ;
viewport = boardContainer.getViewport() ;
viewport.setViewPosition(new Point(0, 0)) ;
repaint() ;
}
}
}
public JavaCheckerboard() {
JComboBox boardSize ;
board = new BoardPanel(8, 8, 50, 50) ;
boardContainer = new JScrollPane() ;
boardContainer.setViewportView(board) ;
boardSize = new JComboBox() ;
boardSize.addItem("2x2") ;
boardSize.addItem("4x4") ;
boardSize.addItem("8x8") ;
boardSize.addItem("16x16") ;
boardSize.setSelectedIndex(2) ;
boardSize.addItemListener(new SizeListener()) ;
setLayout(new BorderLayout()) ;
add(boardContainer) ;
add(boardSize, BorderLayout.NORTH) ;
}
public static final void main(String args) {
JFrame frame = new JFrame("Fun and Games") ;
frame.getContentPane().add(new JavaCheckerboard()) ;
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE) ;
frame.setSize(400, 400) ;
frame.setVisible(true) ;
}
}
|
|
| Back to top |
|
 |
Roland Guest
|
Posted: Fri Mar 25, 2005 8:51 am Post subject: Re: "AssignmentOperator ArrayInitializer" error |
|
|
On 25-3-2005 1:02, Kevin wrote:
| Quote: | Roland wrote:
On 24-3-2005 5:05, Kevin wrote:
Hi! I'm typing in a program from a magazine and I'm pretty sure I've
typed it in correctly. However, I'm getting an error in one section
of the program, the class SizeListener. The error is: "Syntax error,
insert 'AssignmentOperator ArrayInitializer' to complete Expression."
I have no idea what this is trying to tell me. Can anyone look at
the code below and tell what's wrong with it?
Thanks!
public class SizeListener implements ItemListener {
public void itemStateChanged(ItemEvent e) {
if(e.getStateChange() == ItemEvent.SELECTED) {
String item = (String)e.getItem() ;
JViewport viewport ;
int size ;
if("2x2".equals(item))
size = 2 ;
else if("4x4".equals(item))
size = 4 ;
else if("8x8".equals(item))
size = 8 ; else
size = 16 ;
board.setBoardSize(size, size) ;
viewport = boardContainer.getViewport() ;
viewport.setViewPosition(new Point(0, 0)) ;
repaint() ;
}
}
}
I've copied your code into the Eclipse source editor, but there's no
syntax error in the class above. However, the variables 'board',
'boardContainer', and the method 'repaint' are undefined.
Are you sure that the syntax error is in the code you've shown us? How
did you compile it? Does the error message show a line number?
Roland,
Hi! I'm using Eclipse to type this program in. Here is the entire
source code. Sorry for the formatting. The lines appear to be wrapping
, throwing off the format. By the way, I'm not getting that error any
longer. I'm not sure what the problem was because when I saved the
source last night, I didn't change anything. When I loaded it just now,
there was no error! Very strange...
Thanks!
Kevin
[snip] |
Sometimes Eclipse's error markers seem to stick, even when you have
changed and saved the source. Especially with the 3.1M* versions
(haven't seen it in 3.0.1). Closing the editor and reopening the file
seems to clear it, or, if that fails, a complete restart of Eclipse.
--
Regards,
Roland de Ruiter
___ ___
/__/ w_/ /__/
/ /_/ /
|
|
| Back to top |
|
 |
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
|