PDA

View Full Version : AWT and Swing Java question, <identifier>


tricolaire
04-17-2005, 05:08 AM
I am attempting to write a java swing application for a school project, the source code follows:

//
// Java_graphic_version.java
// Java graphic version
//
// Created by erik on 4/16/05.
// Copyright (c) 2005 __MyCompanyName__. All rights reserved.
//
// This source code is distributed under the GNU general public license
// See http://www.gnu.org/licenses/gpl.html for more information.
//

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

//A generic window Listener
class GenericWindowListener extends WindowAdapter {

public void windowClosing(WindowEvent event){

System.exit(0);

}//end windowClosing

}//end GenericWindowListener

//The class containing my main frame
class MainFrame extends JFrame {

public MainFrame(){

super("Dictionary");

setSize(500,500);

}//end mainFrame

}//end MainFraim

//main class
public class Java_graphic_version {

MainFrame app=new MainFrame();

app.addWindowListener(new GenericWindowListener());

app.show();

}//end Java_graphic_version

Only the classes currently being instantiated are shown.

For some reason, my IDE shows up two errors. One at the line stating "app.addWindowListener(new GenericWindowListener());"

the other at the line stating "app.show();"

the error for both lines is the same: "<identifier> expected"

The only thing I could possible see that is screwing up is the lack of any JPanel, or any content at all, being placed in the frame, but I don't understand why that should matter.

Any ideas?

thank you

-Moi

smeagol
04-18-2005, 02:54 PM
You need a "main" method in your Java_graphic_version class, like so:


//
// Java_graphic_version.java
// Java graphic version
//
// Created by erik on 4/16/05.
// Copyright (c) 2005 __MyCompanyName__. All rights reserved.
//
// This source code is distributed under the GNU general public license
// See http://www.gnu.org/licenses/gpl.html for more information.
//

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

//A generic window Listener
class GenericWindowListener extends WindowAdapter {

public void windowClosing(WindowEvent event){

System.exit(0);

}//end windowClosing

}//end GenericWindowListener

//The class containing my main frame
class MainFrame extends JFrame {

public MainFrame(){

super("Dictionary");

setSize(500,500);

}//end mainFrame

}//end MainFraim

//main class
public class Java_graphic_version {

public static void main(String[] args)
{
MainFrame app = new MainFrame();
app.addWindowListener(new GenericWindowListener());

app.show();
}
}//end Java_graphic_version

tricolaire
04-19-2005, 03:08 PM
Did I forget a main method?!?!?!? :eek:

oh crap, I'm sorry, I should have realized that :(

my bad everyone

-Moi