Win a copy of Mastering Corda: Blockchain for Java Developers this week in the Cloud/Virtualization forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Paul Clapham
  • Ron McLeod
  • Bear Bibeault
  • Liutauras Vilda
Sheriffs:
  • Jeanne Boyarsky
  • Tim Cooke
  • Junilu Lacar
Saloon Keepers:
  • Tim Moores
  • Tim Holloway
  • Stephan van Hulst
  • Jj Roberts
  • Carey Brown
Bartenders:
  • salvin francis
  • Frits Walraven
  • Piet Souris

Compiler tells me to insert { to complete block and Syntax error on token ";", { expected

 
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello

Iam quite new to programming, so iam learning a little about OOP in general and started off with java.
I have been doing a program that takes in system time and converts it to analog time which I plot on
the monitor with graphics class and the appropriate functions.
The program is still far away from finished, but i get stucked and don't know how to continue.

there are four different classes:
Frame3 that's my main class.
GraphicsPlot is where I want to plot all the graphics.
MakeGUI from here I make the GUI to control the program flow.
TimeTick handles the Timer and TimerTask, to control the timing.

Iam programming with eclipse on my ubuntu 12.04 and I got various error messages from the IDE
all the time.

see the code below =

----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

package clock;

import java.awt.*;
import java.awt.BorderLayout;
import java.awt.Container;
import java.awt.Toolkit;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.*;
import java.util.Timer;

import javax.swing.*;

//Class handles the GUI, for control flow of program.
public class MakeGUI extends JFrame
{

static int height, width;

JButton Enter;
JButton Set;
JButton StartTimer;
JButton StartClock;
JTextField TextField;
Timer tick;
JPanel pane;


Boolean clocksw; // Syntax error on token ";", { expected after this token, clocksw will function as a switch between timer or clock function


pane = new JPanel();
Enter = new JButton("Enter Value");
Set = new JButton("Set Value");
StartTimer = new JButton("Start Timer");



[size=18]S[tt]tartClock = new JButton("Start Clock"); //Syntax error, insert "}" to complete Block


public MakeGUI()
{
super("My Timer");
Toolkit toolkit = Toolkit.getDefaultToolkit();
height = toolkit.getScreenSize().height;
width = toolkit.getScreenSize().width;

setBounds(height/8, width/8, height/4, height/4);
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
setVisible(true);
}

public int getMonitorHeight()
{
return height;
}

public int getMonitorWidth()
{
return width;
}



public void createGUI()
{



StartTimer.addActionListener(new ActionListener(){

public void actionPerformed(ActionEvent e)
{
clocksw = false;
}
});

StartClock.addActionListener(new ActionListener(){

public void actionPerformed(ActionEvent e)
{
clocksw = true;
}
});

Set.addActionListener(new ActionListener(){

public void actionPerformed(ActionEvent e)
{

}
});

Enter.addActionListener(new ActionListener(){

public void actionPerformed(ActionEvent e)
{

}
});


}

}

----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
 
Bartender
Posts: 3323
86
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The compiler is telling you need to insert curly braces around the block of assignments as they must be either on the same line as the variable declaration or within an initializer block, constructor or method body.
See http://docs.oracle.com/javase/tutorial/java/javaOO/initial.html
 
Christian Halme
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks for your reply.
I have been trying with the curly brackets also, but it wont compile anyway.
I never needed the curly bracketws before in my programming when declaring an boolean
variable or instantiating JButton's, I believe there has to be some compiler error going on.
 
Christian Halme
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello

Just wanted to say that I managed to get it work.
The compiler wont complain at all if I instantiate by=
JButton button = new JButton();
but if I wright
JButton button;
button = new JButton();
the compiler starts complaining about insert curlybrackets and or missing ;
in the end of line, even if everything is OK.
now I believe there's some bugs on eclipse for ubuntu,
anyone who has experienced something similar?
 
lowercase baba
Posts: 12954
65
Chrome Java Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
First, please read UseCodeTags. I've put them around your code - see how much easier it is to read?

Next, you can't have executable code that is not in a method. your line "pane = new JPanel();" (and a few more) have to be inside a method.

 
Marshal
Posts: 67496
173
Mac Mac OS X IntelliJ IDE jQuery Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

fred rosenberger wrote:
Next, you can't have executable code in a method.


I believe that fred meant "outside a method"
 
fred rosenberger
lowercase baba
Posts: 12954
65
Chrome Java Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Bear Bibeault wrote:

fred rosenberger wrote:
Next, you can't have executable code in a method.


I believe that fred meant "outside a method"


oops - yes of course.
 
Tony Docherty
Bartender
Posts: 3323
86
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Christian Halme wrote:I never needed the curly bracketws before in my programming when declaring an boolean
variable or instantiating JButton's, I believe there has to be some compiler error going on.


But the compiler isn't complaining about you declaring a variable. It's complaining about you try to assign a value to a variable outside of a code block. The link I supplied explains this fully, I suggest you read it again.

Just wanted to say that I managed to get it work.
The compiler wont complain at all if I instantiate by=
JButton button = new JButton();


That's because you are declaring the variable and initializing it on the same line - read the link I supplied previously.

now I believe there's some bugs on eclipse for ubuntu,


Even if you were the only person to have ever used Eclipse on Ubuntu I seriously doubt you would find such a fundamental bug. Don't get me wrong I'm sure there are loads of bugs in Eclipse but there is such much testing done before a release such basic compiler bugs are extremely unlikely. I know when you start out programming some things just don't appear to make sense and so after staring at the problem for many hours the obvious answer is it must be a bug in the tools you are using. But as a beginner you are very unlikely to come across any bugs in the tools you are using as you will only be doing the most basic of things.
 
Christian Halme
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Ok thanks I read your link and I understand that I can have more arguments or methods when im initialize instances, now i understand why it wont work
 
Enjoy the full beauty of the english language. Embedded in this tiny ad:
the value of filler advertising in 2020
https://coderanch.com/t/730886/filler-advertising
reply
    Bookmark Topic Watch Topic
  • New Topic