Java GUI compilation errors

I can't see what I am doing wrong to get my compilation errors

Page 1 of 1

3 Replies - 1134 Views - Last Post: 02 December 2008 - 11:31 PM Rate Topic: -----

#1 bitterlynew2java  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 7
  • Joined: 12-November 08

Java GUI compilation errors

Posted 02 December 2008 - 10:14 PM

I am getting the following error messages for my code listed below:

TSAssn5.java:197: illegal start of expression
private void clearClientArea(){
^
TSAssn5.java:253: ';' expected
}//end main
^
TSAssn5.java:254: '}' expected
}//end class
^
3 errors


 [color=#339999]/*
 TS NU Grades GUI Interface Assignment 5
*/

import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
import java.util.*;

//#1 Implement event proceesing
public class TSNUGrades extends JFrame implements ActionListener{
  private JTextArea frameTextArea;		   //create a text area
  private Container frameContainer;		  //for the content pane
  private JScrollPane scrollForTextArea;	 //scroll bar
  private BorderLayout frameLayout;		  //default
  final int width = 640, height = 480;	   //Standard size

//#2 New attributes for data processing
  // and status bar
  private JLabel statusBar;
  private int addedNumber;

  private JMenuBar bar;
  private JMenu fileMenu, editMenu, helpMenu;
  private JMenuItem exitApp, clearText, displayText, addText,
					aboutThisApp;
  // Constructor
  public TSNUGrades(String title){
	 //Call to JFrame constructor
	 super(title);
	 //Call initialization
	 init();
	}

  public void init(){
	 //Use the TSAssn5WindowCloser Class
	 addTSAssn5WindowListener(new TSAssn5WindowCloser(this));
	 //Set up the Window for the operating system
	 setLookAndFeel();

	 //Get the content pane
	 frameContainer = getContentPane();
	 //Create an instance ofa JTextArea
	 frameTextArea = new JTextArea("",
								   18, 70);
	 frameTextArea.setEditable(true);
	 frameTextArea.setLineWrap(true);
	 //Set the text area in the scroll pane
	 scrollForTextArea = new JScrollPane(frameTextArea);

	 //Create an instance of a border layout
	 frameLayout = new BorderLayout();
	 frameContainer.setLayout(frameLayout);

//#3 Add the status bar (JLabel)
	 frameContainer.add(scrollForTextArea, BorderLayout.CENTER);
	 //create a label to use as a status bar
	 statusBar = new JLabel(" ");
	 frameContainer.add(statusBar, BorderLayout.SOUTH);

	 setSize(height, width);
	 makeMenu();
//#4 Postition the window in the center of the desktop
	 positionWindow();
	 pack();
	 setVisible(true);
  }

//----------------------------setLookAndFeel()----------------------
  //Set the look and feel for the application
  public void setLookAndFeel(){
	 try{
		String lookAndFeel = UIManager.getSystemLookAndFeelClassName();
		UIManager.setLookAndFeel(lookAndFeel);
	 }
	 catch(Exception lFE){
	   //process exception
	 }
  }

//3.1
//-----------------------setStatus()---------------------------
 private void setStatus(String msg){
	statusBar.setText("  " + msg);
 }
//----------------------------positionWindow-----------------------------
//#4.1 Position the Frame
 private void positionWindow(){
   Dimension sizeOfScreen = Toolkit.getDefaultToolkit().getScreenSize();
   Dimension sizeOfFrame = this.getSize();
   if(sizeOfFrame.height > sizeOfScreen.height){
	  sizeOfFrame.height = sizeOfScreen.height;
   }
   if(sizeOfFrame.width > sizeOfScreen.width){
	  sizeOfFrame.width = sizeOfScreen.width;
   }
   this.setLocation( (sizeOfScreen.width - sizeOfFrame.width) /2 ,
				(sizeOfScreen.height - sizeOfFrame.height) /2 );
 }

//#5----------------------------makeMenu()-----------------------------
  private void makeMenu(){
	   //Create a menu bar
	 bar = new JMenuBar();

	 //create File menu
	 fileMenu = new JMenu("File");
	 fileMenu.setMnemonic('F');
		//With menu items
		
	 //generate events and add handlers
		exitApp = new JMenuItem("Exit");
		exitApp.setMnemonic('X');
		exitApp.addActionListener(this);

		//Add the File items to File menu
		fileMenu.add(exitApp);

	 //create Edit menu
	 editMenu = new JMenu("Edit");
	 editMenu.setMnemonic('E');

	   //With menu items
	   clearText = new JMenuItem("Clear Text");
	   clearText.setMnemonic('R');
	   displayText = new JMenuItem("Display Text");
	   displayText.setMnemonic('D');
	   addText = new JMenuItem("Add Text");
	   addText.setMnemonic('A');

	   //Add the Edit items to Edit menu
	   editMenu.add(clearText);
	   clearText.addActionListener(this);
	   editMenu.add(displayText);
	   displayText.addActionListener(this);
	   editMenu.add(addText);
	   addText.addActionListener(this);

	 //create Help menu
	 helpMenu = new JMenu("Help");
	 helpMenu.setMnemonic('H');
		//With menu items
		aboutThisApp = new JMenuItem("About...");
		aboutThisApp.setMnemonic('A');
		aboutThisApp.addActionListener(this);
		//Add the Help items to Help menu
		helpMenu.add(aboutThisApp);

	
	 //Add File, Edit, and Help to bar
	 bar.add(fileMenu);
	 bar.add(editMenu);
	 bar.add(helpMenu);

	 //Add the menu bar to the content pane
	 setJMenuBar(bar);
  }//end makeMenu


//#6 Handle the events the menu generates
//-----------------------actionPerformed()-------------------------
//#6.1 Use message dialog
 public void actionPerformed(ActionEvent actionEv){
   if(actionEv.getSource() == exitApp){
	 this.setStatus("Exit");
	  int flag = JOptionPane.showConfirmDialog(
						this, "Quit Tiffany Smith's Northwestern grades?",
						"Exit Tiffany Smith's Northwestern grades",
						JOptionPane.YES_NO_OPTION,
						JOptionPane.WARNING_MESSAGE );
	  if(flag == JOptionPane.YES_OPTION){
		 System.exit(0);
	  }
   }
   else if(actionEv.getSource() == clearText){
	 setStatus("Cleared and score reset");
	 clearClientArea();
   }
   else if(actionEv.getSource() == aboutThisApp){
	 setStatus("Tiffany Smith CIS 110");
//#6.2 Use message dialog
	 JOptionPane.showMessageDialog(this, "Tiffany Smith CIS 110",
								   "Tiffany Smith CIS 110",
								   JOptionPane.INFORMATION_MESSAGE);
  }
   else if(actionEv.getSource() == displayText){
	 setStatus("Grades");
	 clearClientArea();
	 showCourse();
   }
   else if(actionEv.getSource() == addText){
	setStatus("Add Score");
 //#6.2 Use input dialog
	 addScore();
   }
//-------------------------- clearClientArea ()---------------------------
 private void clearClientArea(){
	 frameTextArea.setText("");
	 resetScore();
 }
 
 //#6.2.1
 //--------------------------addScore()---------------------------
 private void addScore(){
	 try{
	 String dialogValue =
				 JOptionPane.showInputDialog(this, "Enter final grades:",
								   "Add Score",
									JOptionPane.INFORMATION_MESSAGE);
	 frameTextArea.append("\n \t" + String.valueOf(dialogValue));
	 }catch(Exception jEx){
		  showTestDialog("No value entered.\nEnter integer values.");
	 }
 }

 //#6.2.2
 //--------------------------showTestDialog()---------------------------
 private void showTestDialog(String testItem){
	  JOptionPane.showMessageDialog(this, testItem);
 }

 //#6.2.3
 //--------------------------resetScore()---------------------------
 private void resetScore(){
	addedScore = TBD;
 }

//#7.1-----------------------showCourse()-------------------------
  private void showCourse(){
	 //Create a string
	 String CourseGrades =
					"ENGLISH  205-CN - 25   Intermediate Composition   , A- , 	ORG_BEH  301-CN - 24   Organization behavior  , A "  +
					"CIS  110-CN - 16   Introduction to Computer Programming, TBD , ORG_BEH  367-CN - 17   Strategic Planning and Management , TBD	 , "  +
					"BUS_LAW  201-CN - 14   Business Law I: Contracts and Agency, TBD , POLI_SCI  395-CN - 12   Political Research Seminar: Terrorism, Counterterrorism, and International 			  Security, TBD , ";
	 //Split the string into array elements
	 String coursesAndGrades[]  = CourseGrades.split(",\\s");

	 //Increment by 2's to see both columns
	 //Subtract 1 to allow counting by 2's
	 frameTextArea.append("\n\tCourset\t\tGrades\n");
	 for(int cntr = 0; cntr < courseAndGrades.length - 1; cntr += 2){
	   frameTextArea.append("\n\t");
	   frameTextArea.append(courseAndGrades[cntr]
							+ "\t"
							+ courseAndGrades[cntr+1]
							);
	 }
  }

//#3.1-----------------------main()---------------------------------
  public static void main(String args[]){
	 new TSNUGrades("TSNU Grades");
  }//end main
}//end class




Is This A Good Question/Topic? 0
  • +

Replies To: Java GUI compilation errors

#2 KYA  Icon User is offline

  • g++ jameson.cpp -o beverage
  • member icon

Reputation: 3106
  • View blog
  • Posts: 19,145
  • Joined: 14-September 07

Re: Java GUI compilation errors

Posted 02 December 2008 - 10:22 PM

Missing a brakcet at the end of public void actionPerformed(ActionEvent actionEv){


right before private void clearClientArea()

The compiler is pretty specific about these things. You even get a line number.
Was This Post Helpful? 1
  • +
  • -

#3 bitterlynew2java  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 7
  • Joined: 12-November 08

Re: Java GUI compilation errors

Posted 02 December 2008 - 11:09 PM

Thanks, I knew it had to be something small. Now I am able to get the meet of my problems. I am getting the following errors:
TSAssn5.java:37: cannot find symbol
symbol : method addTSAssn5WindowListener(TSAssn5WindowCloser)
location: class TSAssn5
addTSAssn5WindowListener(new TSAssn5WindowCloser(this));
^
TSAssn5.java:226: cannot find symbol
symbol : variable addedScore
location: class TSAssn5
addedScore = TBD;
^
TSAssn5.java:226: cannot find symbol
symbol : variable TBD
location: class TSAssn5
addedScore = TBD;
^
TSAssn5.java:242: cannot find symbol
symbol : variable courseAndGrades
location: class TSAssn5
for(int cntr = 0; cntr < courseAndGrades.length - 1; cntr += 2){
^
TSAssn5.java:244: cannot find symbol
symbol : variable courseAndGrades
location: class TSAssn5
frameTextArea.append(courseAndGrades[cntr]
^
TSAssn5.java:246: cannot find symbol
symbol : variable courseAndGrades
location: class TSAssn5
+ courseAndGrades[cntr+1]
^
TSAssn5.java:253: cannot find symbol
symbol : class TSNUGrades
location: class TSAssn5
new TSNUGrades("TSNU Grades");
^
7 errors



/*
 TS NU Grades GUI Interface Assignment 5
*/

import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
import java.util.*;

//#1 Implement event proceesing
public class TSAssn5 extends JFrame implements ActionListener{
  private JTextArea frameTextArea;		   //create a text area
  private Container frameContainer;		  //for the content pane
  private JScrollPane scrollForTextArea;	 //scroll bar
  private BorderLayout frameLayout;		  //default
  final int width = 640, height = 480;	   //Standard size

//#2 New attributes for data processing
  // and status bar
  private JLabel statusBar;
  private int addedNumber;

  private JMenuBar bar;
  private JMenu fileMenu, editMenu, helpMenu;
  private JMenuItem exitApp, clearText, displayText, addText,
					aboutThisApp;
  // Constructor
  public TSAssn5(String title){
	 //Call to JFrame constructor
	 super(title);
	 //Call initialization
	 init();
	}

  public void init(){
	 //Use the TSAssn5WindowCloser Class
	 addTSAssn5WindowListener(new TSAssn5WindowCloser(this));
	 //Set up the Window for the operating system
	 setLookAndFeel();

	 //Get the content pane
	 frameContainer = getContentPane();
	 //Create an instance ofa JTextArea
	 frameTextArea = new JTextArea("",
								   18, 70);
	 frameTextArea.setEditable(true);
	 frameTextArea.setLineWrap(true);
	 //Set the text area in the scroll pane
	 scrollForTextArea = new JScrollPane(frameTextArea);

	 //Create an instance of a border layout
	 frameLayout = new BorderLayout();
	 frameContainer.setLayout(frameLayout);

//#3 Add the status bar (JLabel)
	 frameContainer.add(scrollForTextArea, BorderLayout.CENTER);
	 //create a label to use as a status bar
	 statusBar = new JLabel(" ");
	 frameContainer.add(statusBar, BorderLayout.SOUTH);

	 setSize(height, width);
	 makeMenu();
//#4 Postition the window in the center of the desktop
	 positionWindow();
	 pack();
	 setVisible(true);
  }

//----------------------------setLookAndFeel()----------------------
  //Set the look and feel for the application
  public void setLookAndFeel(){
	 try{
		String lookAndFeel = UIManager.getSystemLookAndFeelClassName();
		UIManager.setLookAndFeel(lookAndFeel);
	 }
	 catch(Exception lFE){
	   //process exception
	 }
  }

//3.1
//-----------------------setStatus()---------------------------
 private void setStatus(String msg){
	statusBar.setText("  " + msg);
 }
//----------------------------positionWindow-----------------------------
//#4.1 Position the Frame
 private void positionWindow(){
   Dimension sizeOfScreen = Toolkit.getDefaultToolkit().getScreenSize();
   Dimension sizeOfFrame = this.getSize();
   if(sizeOfFrame.height > sizeOfScreen.height){
	  sizeOfFrame.height = sizeOfScreen.height;
   }
   if(sizeOfFrame.width > sizeOfScreen.width){
	  sizeOfFrame.width = sizeOfScreen.width;
   }
   this.setLocation( (sizeOfScreen.width - sizeOfFrame.width) /2 ,
				(sizeOfScreen.height - sizeOfFrame.height) /2 );
 }

//#5----------------------------makeMenu()-----------------------------
  private void makeMenu(){
	   //Create a menu bar
	 bar = new JMenuBar();

	 //create File menu
	 fileMenu = new JMenu("File");
	 fileMenu.setMnemonic('F');
		//With menu items
		
	 //generate events and add handlers
		exitApp = new JMenuItem("Exit");
		exitApp.setMnemonic('X');
		exitApp.addActionListener(this);

		//Add the File items to File menu
		fileMenu.add(exitApp);

	 //create Edit menu
	 editMenu = new JMenu("Edit");
	 editMenu.setMnemonic('E');

	   //With menu items
	   clearText = new JMenuItem("Clear Text");
	   clearText.setMnemonic('R');
	   displayText = new JMenuItem("Display Text");
	   displayText.setMnemonic('D');
	   addText = new JMenuItem("Add Text");
	   addText.setMnemonic('A');

	   //Add the Edit items to Edit menu
	   editMenu.add(clearText);
	   clearText.addActionListener(this);
	   editMenu.add(displayText);
	   displayText.addActionListener(this);
	   editMenu.add(addText);
	   addText.addActionListener(this);

	 //create Help menu
	 helpMenu = new JMenu("Help");
	 helpMenu.setMnemonic('H');
		//With menu items
		aboutThisApp = new JMenuItem("About...");
		aboutThisApp.setMnemonic('A');
		aboutThisApp.addActionListener(this);
		//Add the Help items to Help menu
		helpMenu.add(aboutThisApp);

	
	 //Add File, Edit, and Help to bar
	 bar.add(fileMenu);
	 bar.add(editMenu);
	 bar.add(helpMenu);

	 //Add the menu bar to the content pane
	 setJMenuBar(bar);
  }//end makeMenu


//#6 Handle the events the menu generates
//-----------------------actionPerformed()-------------------------
//#6.1 Use message dialog
 public void actionPerformed(ActionEvent actionEv){
   if(actionEv.getSource() == exitApp){
	 this.setStatus("Exit");
	  int flag = JOptionPane.showConfirmDialog(
						this, "Quit Tiffany Smith's Northwestern grades?",
						"Exit Tiffany Smith's Northwestern grades",
						JOptionPane.YES_NO_OPTION,
						JOptionPane.WARNING_MESSAGE );
	  if(flag == JOptionPane.YES_OPTION){
		 System.exit(0);
	  }
   }
   else if(actionEv.getSource() == clearText){
	 setStatus("Cleared and score reset");
	 clearClientArea();
   }
   else if(actionEv.getSource() == aboutThisApp){
	 setStatus("Tiffany Smith CIS 110");
//#6.2 Use message dialog
	 JOptionPane.showMessageDialog(this, "Tiffany Smith CIS 110",
								   "Tiffany Smith CIS 110",
								   JOptionPane.INFORMATION_MESSAGE);
  }
   else if(actionEv.getSource() == displayText){
	 setStatus("Grades");
	 clearClientArea();
	 showCourse();
   }
   else if(actionEv.getSource() == addText){
	setStatus("Add Score");
 //#6.2 Use input dialog
	 addScore();
   }
   }
//-------------------------- clearClientArea ()---------------------------
 private void clearClientArea(){
	 frameTextArea.setText("");
	 resetScore();
 }
 
 //#6.2.1
 //--------------------------addScore()---------------------------
 private void addScore(){
	 try{
	 String dialogValue =
				 JOptionPane.showInputDialog(this, "Enter final grades:",
								   "Add Score",
									JOptionPane.INFORMATION_MESSAGE);
	 frameTextArea.append("\n \t" + String.valueOf(dialogValue));
	 }catch(Exception jEx){
		  showTestDialog("No value entered.\nEnter integer values.");
	 }
 }

 //#6.2.2
 //--------------------------showTestDialog()---------------------------
 private void showTestDialog(String testItem){
	  JOptionPane.showMessageDialog(this, testItem);
 }

 //#6.2.3
 //--------------------------resetScore()---------------------------
 private void resetScore(){
	addedScore = TBD;
 }

//#7.1-----------------------showCourse()-------------------------
  private void showCourse(){
	 //Create a string
	 String CourseGrades =
					"ENGLISH  205-CN - 25   Intermediate Composition   , A- , 	ORG_BEH  301-CN - 24   Organization behavior  , A "  +
					"CIS  110-CN - 16   Introduction to Computer Programming, TBD , ORG_BEH  367-CN - 17   Strategic Planning and Management , TBD	 , "  +
					"BUS_LAW  201-CN - 14   Business Law I: Contracts and Agency, TBD , POLI_SCI  395-CN - 12   Political Research Seminar: Terrorism, Counterterrorism, and International 			  Security, TBD , ";
	 //Split the string into array elements
	 String coursesAndGrades[]  = CourseGrades.split(",\\s");

	 //Increment by 2's to see both columns
	 //Subtract 1 to allow counting by 2's
	 frameTextArea.append("\n\tCourset\t\tGrades\n");
	 for(int cntr = 0; cntr < courseAndGrades.length - 1; cntr += 2){
	   frameTextArea.append("\n\t");
	   frameTextArea.append(courseAndGrades[cntr]
							+ "\t"
							+ courseAndGrades[cntr+1]
							);
	 }
  }

//#3.1-----------------------main()---------------------------------
  public static void main(String args[]){
	 new TSNUGrades("TSNU Grades");
  }//end main
}//end class




/*
TSAssn5WindowCloser.java
*/
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
import java.util.*;

import java.awt.event.*;

public class TSAssn5WindowCloser extends WindowAdapter{
//Create a reference for the parent window
  JFrame parent;

  public TSAssn5WindowCloser(JFrame par){
	 parent = par;
  }

  public TSAssn5WindowCloser(){
	 parent = null;
  }

  public void TSAssn5windowClosing(WindowEvent wE){
 //Confirm that the user wants to exit.
	   int flag = JOptionPane.showConfirmDialog(
						parent, "Quit Tiffany Smith's Northwestern grades?",
						"Exit Tiffany Smith's Northwestern grades",
						JOptionPane.YES_NO_OPTION,
						JOptionPane.WARNING_MESSAGE );
	  if(flag == JOptionPane.YES_OPTION){
		 System.exit(0);
	  }
  }
}

Was This Post Helpful? 0
  • +
  • -

#4 pbl  Icon User is offline

  • There is nothing you can't do with a JTable
  • member icon

Reputation: 8342
  • View blog
  • Posts: 31,880
  • Joined: 06-March 08

Re: Java GUI compilation errors

Posted 02 December 2008 - 11:31 PM

Just a quick look
You cannot define a class in the middle of a method

 public void init(){
	 //Use the TSAssn5WindowCloser Class
	  public class TSAssn5WindowCloser extends WindowAdapter{
//	  Create a reference for the parent window



import statement should be at the beginning of a .java file cannot be iinside it

import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
import java.util.*;



neither addedScore or TDB are defined

private void resetScore(){
	addedScore = TBD;
}



what is courseAndGrades from which you extract .length ?

	for(int cntr = 0; cntr < courseAndGrades.length - 1; cntr += 2){
 

Was This Post Helpful? 0
  • +
  • -

Page 1 of 1