hello.

Im having problems trying to get my jframe gui to work correctly i got the window all done fine but when i tell it to display somethis in the code , it comes up with errors when compiled.
Can someone please tell me where im going wrong ..
apreciate any help.

The class with 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();
		database.initialiseComedy();
		database.viewAll();
		database.setComedyDetails();
  new MenuFrame("Hotel Television Schedule System");
 }
 
 
 class MenuListener implements ActionListener{
   public void actionPerformed (ActionEvent e){
     if(e.getSource() == displaySchedule){
      Database.viewAll();
     }
     else if(e.getSource() == displayAll){
       textField.setText("Open an existing file");
     }
   }
 }
}

class from where method is called

package Schedule;

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


public class Database

{
	static 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 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		","Daily life of familyin america		","30		","No		");	
    }
    
    
public void setFilmDetails()
    {
       
    	film[0] = new Film ("War Of The Worlds		","Tom Cruise		","Steven Spielberg		","Tripod aliens attack earth		","120		","Yes		");	
    }
    
    
    public void setDramaDetails()
    {
        
    	drama[0] = new Drama ("24		","Keifer Sutherland		","Dan Maniche		","counter terrorist unit adventure		","60		","No		");	
    }
	
    
  	public void allComedies()
 	{
 		if(entry == 1)
 		{
 		   System.out.println("Title	Actor   Director		Synopsis		Duration		Rentable");
 		   for (int i=0; i<comedysize;i++)
 		   {
 			 System.out.println(comedy[i].toString());
	       }
		}
		else if(entry ==0)
		{
		  	 System.out.println("No entries made");	      	
		}	
 	}		  	

  	
 	
 	public void viewAll()
 	{
 		   
           for (int i=0; i<comedysize;i++)
 		   {
 			//System.out.println(comedy[i].toString());
 			JOptionPane.showMessageDialog(null, comedy[i].toString());
           }
 	}	
 	
 
}

I assume you have problems with this bit :

class MenuListener implements ActionListener{
   public void actionPerformed (ActionEvent e){
     if(e.getSource() == displaySchedule){
      Database.viewAll();
     }
     else if(e.getSource() == displayAll){
       textField.setText("Open an existing file");
     }

you call 'Database.viewAll();' which is a call to a static method in the Database class. However there is no such method.

I think you wanted to do 'database.viewAll();' to invoke the viewAll method on the instance of the Database class you created in the main method.

However, you would also have to change the database variable to an instance variable by moving the declaration (or definition, i can never remeber) out of the main method as it's scope is now limited to the main method.

Hope this helps,
Guido

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.