RSS Forums RSS
Please support our Java advertiser: Lunarpages Java Web Hosting
Views: 1200 | Replies: 1
Reply
Join Date: Mar 2005
Posts: 73
Reputation: nabil1983 is an unknown quantity at this point 
Rep Power: 4
Solved Threads: 0
nabil1983 nabil1983 is offline Offline
Junior Poster in Training

Help Final GUI JFrame problem with actionlistner method

  #1  
May 4th, 2006
Ok got a new problem i've started to implement a GUI for my program but for some reason in the actionlistener metho i cannot pass the method i want to display.. I dont know what im doing wrong because i am not familiar with using GUIs... can somebody please help me this is the last problem i got..

This is the JFrame
package Schedule;

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

public class MenuFrame extends JFrame{
 
 JTextField textField;
 Container contentPane;
 JMenuBar menuBar;
 JMenu fileMenu;
 JMenuItem displaySchedule;
 JMenuItem displayAll;
 JMenuItem displayComedy;
 JMenuItem displayDrama;
 JMenuItem displayRentables;
 JMenuItem addSchedule;
 JMenuItem removeSchedule;
 JMenuItem setTrailer;
 
 public MenuFrame(String title){
  super(title);
  contentPane = getContentPane();
  textField = new JTextField(20);
  contentPane.add(textField);
  menuBar = new JMenuBar();
  displaySchedule = new JMenuItem("View Schedule");
  displayAll = new JMenuItem("View All Programmes");
  displayComedy = new JMenuItem("View All Comedies");
  displayDrama = new JMenuItem("View All Dramas");
  displayRentables = new JMenuItem("View All Rentables");
  addSchedule = new JMenuItem("Add Programmes To Schedule");
  removeSchedule = new JMenuItem("Remove Programme From Schedule");
  setTrailer = new JMenuItem("Set Trailer Duration");
  
  displaySchedule.addActionListener(new MenuListener());
  displayAll.addActionListener(new MenuListener());
  displayComedy.addActionListener(new MenuListener());
  displayDrama.addActionListener(new MenuListener());
  displayRentables.addActionListener(new MenuListener());
  addSchedule.addActionListener(new MenuListener());
  removeSchedule.addActionListener(new MenuListener());
  setTrailer.addActionListener(new MenuListener());
  
  fileMenu = new JMenu("File");
  fileMenu.add(displaySchedule);
  fileMenu.add(displayAll);
  fileMenu.add(displayComedy);
  fileMenu.add(displayDrama);
  fileMenu.add(displayRentables);
  fileMenu.add(addSchedule);
  fileMenu.add(removeSchedule);
  fileMenu.add(setTrailer);
   
  menuBar.add(fileMenu);
  
  setJMenuBar(menuBar);
  setSize(400,400);
  setVisible(true);
  addWindowListener(new Terminator());
 }
 public static void main(String args[]){
 	
 	Database database= new Database();
		//ScheduleMenu.initialiseComedy();
		//ScheduleMenu.viewAll();
		//ScheduleMenu.setComedyDetails();
  new MenuFrame("Hotel Television Schedule System");
 }
 
 
 
 class MenuListener implements ActionListener{
   public void actionPerformed (ActionEvent e){
     if(e.getSource() == displaySchedule){
      ScheduleMenu.viewAll() ;
     }
     else if(e.getSource() == displayAll){
       textField.setText("Open an existing file");
     }
   }
 }
}






This is the class from where the method is called
package Schedule;

import java.io.*;
import javax.swing.*;

public class ScheduleMenu
{
	Programme programme []= new Programme[200];
	int entry = 0;
	int comedysize = 10;
	int filmsize = 10;
	int dramasize = 10;
	
	Comedy comedy[] = new Comedy[comedysize];
 	Drama drama[] = new Drama[dramasize];
 	Film film[] = new Film[filmsize];
 	
	
	
	public static void main(String args[])
	throws IOException
	{
		
		new ScheduleMenu().mainMenu();
		
		}
	
	public void initialiseComedy()
 	{
 	 	for (int i=20; i<comedysize;i++)
 		{
 			comedy[i] = new Comedy();
 		}
 		
 		entry = 0;
    }
    
    
    
    //Hardcoded details
    public void setComedyDetails()
    {
        entry = 1; 
    	comedy[0] = new Comedy ("My Wife & Kids			","Mario Wyans		","Lisa Ray			","","30","No");	
    	comedy[1] = new Comedy ("Friends				","Jennifer Aniston	","Marta Kaufman	","","30","No");	
    	comedy[2] = new Comedy ("Fresh Prince			","Will Smith		","Jazzy J			","","30","No");	
    	comedy[3] = new Comedy ("Joey					","Mat Le Blanc		","Marta Kaufman	","","30","No");	
    	comedy[4] = new Comedy ("My Name Is Earl		","MJames Matheis	","Jimmy Hench		","","30","No");	
    	comedy[5] = new Comedy ("Simpsons				","Bart, Homer		","Dan Castella		","","30","No");	
    	comedy[6] = new Comedy ("Two and A Half Men		","Charlie Sheen	","Brian Forre		","","30","No");	
    	comedy[7] = new Comedy ("Everybody Loves Raymond","Chris Rock		","Vincent Martella	","","30","No");	
    	comedy[8] = new Comedy ("That 70s Show			","Ashton Kutcher	","Topher Grace		","","30","No");	
    	comedy[9] = new Comedy ("Will & Grace			","Debra Messing	","Micheal Angarro	","","30","No");	
   
   }
    
    
public void setFilmDetails()
    {
       
    	film[0] = new Film ("War Of The Worlds			","Tom Cruise			","Steven Spielberg		","Tripod aliens attack earth					","120		","Yes		");	
    	film[1] = new Film ("Star Wars 3				","Ewan McGregor		","George Lucas			","Prequel to the star wars saga				","120		","Yes		");	
    	film[2] = new Film ("Inside Man					","Denzel Washington	","Spike Lee			","Robbers pull the perfect bank robbery		","120		","Yes		");	
    	film[3] = new Film ("The Sentinel				","Micheal Douglas		","James Lingman		","An agent is accused of killing president		","120		","Yes		");	
    	film[4] = new Film ("Mission Impossible 3		","Tom Cruise			","JJ Abrams			","Ethan Hunt is on another mission				","120		","Yes		");	
    	film[5] = new Film ("Kin Kong					","Jack Black			","Peter jackson		","King Kong hit new york						","180		","Yes		");	
    	film[6] = new Film ("Pirates Of The Caribbean 	","Johnny Depp 			","Gore Verbinski		","Adventures of Jack Sparrow					","120		","Yes		");	
		film[0] = new Film ("X-Men						","Hugh Jackman			","Bryan Singer			","Superhero adventures							","120		","Yes		");	
    	film[8] = new Film ("The Usual Suspects			","Kevin Spacey			","Bryan Singer			","Criminals head for a big payday				","120		","Yes		");	
    	film[9] = new Film ("Batman Begins				","	Christian Bale		","Christopher Nolan	","Adventures of the man from Gotham city		","120		","Yes		");	
    	
    }
    
    
    public void setDramaDetails()
    {
        
    	drama[0] = new Drama ("24			","Keifer Sutherland	","Dan Maniche			","counter terrorist unit adventure					","60		","No		");
    	drama[1] = new Drama ("Prison Break	","Micheal Scofield		","Luca benjamin		","Prison escape drama								","60		","No		");
    	drama[2] = new Drama ("CSI NY		","Gary Sinese			","Jerry Bruckheimer	","Forensics team investigate murder in New York	","60		","No		");
    	drama[3] = new Drama ("Alias		","Jennifer Garner		","JJ Abrams			","Terrorist espionage drama						","60		","No		");
    	drama[4] = new Drama ("Lost			","Evangeline Lilly		","JJ Abrams			","Plane crash victims stranded on island			","60		","No		");
    	drama[5] = new Drama ("Smallville	","Clark Kent			","Mickey Regvardy		","Adventures of superman							","60		","No		");
    	drama[6] = new Drama ("Hustle		","Dougray Scott		","Smith Jones			","Professional team of theifs, plan robbery		","60		","No		");
    	drama[7] = new Drama ("The Unit		","Jack Ryan			","Polanski Jena		","Missions of secret tactics unit					","60		","No		");
    	drama[8] = new Drama ("CSI Miami	","Herashio Kane		","Jerry Bruckheimer	","Forensics team investigate murder in Miami		","60		","No		");
    	drama[9] = new Drama ("CSI			","Grissom Krusky		","Jerry Bruckheimer	","Forensics team investigate murder in Las Vegas	","60		","No		");
    		
    }
	
    
  	public void allComedies()
 	{
 		   System.out.println("Title	Actor   Director	Synopsis	Duration	Rentable");
 		   for (int i=0; i<comedysize;i++)
 		   {
 			 System.out.println(comedy[i].toString());
	       }
		
 	}		  	
	public void allFilms()
 	{
 		
 		   System.out.println("Title	Actor   Director	Synopsis	Duration	Rentable");
 		   for (int i=0; i<filmsize;i++)
 		   {
 			 System.out.println(film[i].toString());
	       }
 	}	
 	public void allDramas()
 	{
 		   System.out.println("Title	Actor   Director	Synopsis	Duration	Rentable");
 		   for (int i=0; i<dramasize;i++)
 		   {
 			 System.out.println(drama[i].toString());
	       }	
 	}	
  	
 	
 	public void viewAll()
 	{
 		   System.out.println("Title	Actor   Director		Synopsis		Duration		Rentable");
           for (int i=0; i<comedysize;i++)
 		   {
 			 System.out.println(comedy[i].toString());
 			 
           }
 	}
 	
 			public void mainMenu(){ 
		Schedule schedule= new Schedule();
		
		initialiseComedy();
		setComedyDetails();
		setFilmDetails();
		setDramaDetails();
		
	    char choice = '0';
	    
		do
		{
			try
			{
			   System.out.println("\nPLEASE CHOOSE FROM THE OPTIONS BELOW");
			   System.out.println(" 1. VIEW ALL");
			   System.out.println(" 2. VIEW COMEDIES");
			   System.out.println(" 3. VIEW FILMS");
			   System.out.println(" 4. VIEW DRAMAS");
			   System.out.println(" 5. ADD PROGRAMME");
			   System.out.println(" 6. REMOVE PROGRAMME");
			   System.out.println(" 7. VIEW HOTEL INFO");
			   System.out.println(" 8. TO QUIT");
			   System.out.println(" ENTER A NUMBER CORRESPONDING THE OPTION:");
		       
		       /**** problem ****/
		       choice=(char) System.in.read();
		       /**** end of problem ****/
		       
		       //BufferedReader reader;
			//	reader = new BufferedReader(new InputStreamReader(System.in));
				
			//	String i = reader.readLine();
				//choice = Integer.parseInt(i);
			//	choice=(char) System.in.read();
				
		       switch(choice)
		       {
			      case '1': viewAll();
		 	      break;
		 	      
		 	      case '2': allComedies();
		 	      break;
		 	      case '3': allFilms();
		 	      break;
		 	      case '4': allDramas();
		 	      break;
		 	      case '5': addProgramme();
		 	      break;
		 	      case '6': //removeProgramme();
		 	      break;
		 	      case '7': //hotelInfo();
		 	      break;
		 	      case '8': System.out.println("System Exit");
		      	            System.exit(0);
		      	  break; 
		       } 
		       
		    }
		    
		    catch (IOException e)
			{
				System.out.println(e);
			}
		    
		    //catch(NumberFormatException e)
		    //{
		    //	System.out.println("Problem :"+e.getMessage());
		    //}
		}while(choice !=8);
	}
	
	public void addProgramme(){
		
		
		
		
		
		
		
		
	}
	
	
	
	
	
			
}



AddThis Social Bookmark Button
Reply With Quote  
Join Date: Nov 2004
Location: Netherlands
Posts: 5,752
Reputation: jwenting is a jewel in the rough jwenting is a jewel in the rough jwenting is a jewel in the rough jwenting is a jewel in the rough 
Rep Power: 19
Solved Threads: 200
Colleague
jwenting's Avatar
jwenting jwenting is offline Offline
duckman

Re: Final GUI JFrame problem with actionlistner method

  #2  
May 5th, 2006
you're trying to access an instance method like it were a static method, that's not allowed.

That entire ScheduleMenu class seems rather out of place in a Swing application anyway.
As people are clearly allowed to attack me but I'm not allowed to defend myself, I no longer post to this site.
Reply With Quote  
Reply

Only community members can participate in forum threads. You must register or log in to contribute.

Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)

 

Thread Tools Display Modes
Forums | Blogs | Tutorials | Code Snippets | Whitepapers | RSS Feeds | Advertising
All times are GMT -4. The time now is 8:30 pm.
Newsletter Archive - Sitemap - Privacy Statement - Contact Us
Forum system based on vBulletin Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
©2003 - 2008 DaniWeb® LLC