944,057 Members | Top Members by Rank

Ad:
  • Java Discussion Thread
  • Unsolved
  • Views: 2368
  • Java RSS
May 3rd, 2006
0

JFrame GUI Problem

Expand Post »
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
Java Syntax (Toggle Plain Text)
  1. package Schedule;
  2.  
  3. import javax.swing.*;
  4. import java.awt.*;
  5. import java.awt.event.*;
  6.  
  7. public class MenuFrame extends JFrame{
  8.  
  9. JTextField textField;
  10. Container contentPane;
  11. JMenuBar menuBar;
  12. JMenu fileMenu;
  13. JMenuItem displaySchedule;
  14. JMenuItem displayAll;
  15. JMenuItem displayComedy;
  16. JMenuItem displayDrama;
  17. JMenuItem displayRentables;
  18. JMenuItem addSchedule;
  19. JMenuItem removeSchedule;
  20. JMenuItem setTrailer;
  21.  
  22. public MenuFrame(String title){
  23. super(title);
  24. contentPane = getContentPane();
  25. textField = new JTextField(20);
  26. contentPane.add(textField);
  27. menuBar = new JMenuBar();
  28. displaySchedule = new JMenuItem("View Schedule");
  29. displayAll = new JMenuItem("View All Programmes");
  30. displayComedy = new JMenuItem("View All Comedies");
  31. displayDrama = new JMenuItem("View All Dramas");
  32. displayRentables = new JMenuItem("View All Rentables");
  33. addSchedule = new JMenuItem("Add Programmes To Schedule");
  34. removeSchedule = new JMenuItem("Remove Programme From Schedule");
  35. setTrailer = new JMenuItem("Set Trailer Duration");
  36.  
  37. displaySchedule.addActionListener(new MenuListener());
  38. displayAll.addActionListener(new MenuListener());
  39. displayComedy.addActionListener(new MenuListener());
  40. displayDrama.addActionListener(new MenuListener());
  41. displayRentables.addActionListener(new MenuListener());
  42. addSchedule.addActionListener(new MenuListener());
  43. removeSchedule.addActionListener(new MenuListener());
  44. setTrailer.addActionListener(new MenuListener());
  45.  
  46. fileMenu = new JMenu("File");
  47. fileMenu.add(displaySchedule);
  48. fileMenu.add(displayAll);
  49. fileMenu.add(displayComedy);
  50. fileMenu.add(displayDrama);
  51. fileMenu.add(displayRentables);
  52. fileMenu.add(addSchedule);
  53. fileMenu.add(removeSchedule);
  54. fileMenu.add(setTrailer);
  55.  
  56. menuBar.add(fileMenu);
  57.  
  58. setJMenuBar(menuBar);
  59. setSize(400,400);
  60. setVisible(true);
  61. addWindowListener(new Terminator());
  62. }
  63. public static void main(String args[]){
  64.  
  65. Database database= new Database();
  66. database.initialiseComedy();
  67. database.viewAll();
  68. database.setComedyDetails();
  69. new MenuFrame("Hotel Television Schedule System");
  70. }
  71.  
  72.  
  73. class MenuListener implements ActionListener{
  74. public void actionPerformed (ActionEvent e){
  75. if(e.getSource() == displaySchedule){
  76. Database.viewAll();
  77. }
  78. else if(e.getSource() == displayAll){
  79. textField.setText("Open an existing file");
  80. }
  81. }
  82. }
  83. }


class from where method is called
Java Syntax (Toggle Plain Text)
  1.  
  2. package Schedule;
  3.  
  4. import java.io.*;
  5. import javax.swing.JOptionPane;
  6.  
  7.  
  8. public class Database
  9.  
  10. {
  11. static Programme programme []= new Programme[200];
  12. int entry = 0;
  13. int comedysize = 10;
  14. int filmsize = 10;
  15. int dramasize = 10;
  16.  
  17. Comedy comedy[] = new Comedy[comedysize];
  18. Drama drama[] = new Drama[dramasize];
  19. Film film[] = new Film[filmsize];
  20.  
  21.  
  22. public void initialiseComedy()
  23. {
  24. for (int i=20; i<comedysize;i++)
  25. {
  26. comedy[i] = new Comedy();
  27. }
  28.  
  29. entry = 0;
  30. }
  31.  
  32. //Hardcoded details
  33. public void setComedyDetails()
  34. {
  35. entry = 1;
  36. comedy[0] = new Comedy ("My Wife & Kids ","Mario Wyans ","Lisa Ray ","Daily life of familyin america ","30 ","No ");
  37. }
  38.  
  39.  
  40. public void setFilmDetails()
  41. {
  42.  
  43. film[0] = new Film ("War Of The Worlds ","Tom Cruise ","Steven Spielberg ","Tripod aliens attack earth ","120 ","Yes ");
  44. }
  45.  
  46.  
  47. public void setDramaDetails()
  48. {
  49.  
  50. drama[0] = new Drama ("24 ","Keifer Sutherland ","Dan Maniche ","counter terrorist unit adventure ","60 ","No ");
  51. }
  52.  
  53.  
  54. public void allComedies()
  55. {
  56. if(entry == 1)
  57. {
  58. System.out.println("Title Actor Director Synopsis Duration Rentable");
  59. for (int i=0; i<comedysize;i++)
  60. {
  61. System.out.println(comedy[i].toString());
  62. }
  63. }
  64. else if(entry ==0)
  65. {
  66. System.out.println("No entries made");
  67. }
  68. }
  69.  
  70.  
  71.  
  72. public void viewAll()
  73. {
  74.  
  75. for (int i=0; i<comedysize;i++)
  76. {
  77. //System.out.println(comedy[i].toString());
  78. JOptionPane.showMessageDialog(null, comedy[i].toString());
  79. }
  80. }
  81.  
  82.  
  83. }
Similar Threads
Reputation Points: 13
Solved Threads: 0
Junior Poster in Training
nabil1983 is offline Offline
73 posts
since Mar 2005
May 3rd, 2006
0

Re: JFrame GUI Problem

I assume you have problems with this bit :
Java Syntax (Toggle Plain Text)
  1. class MenuListener implements ActionListener{
  2. public void actionPerformed (ActionEvent e){
  3. if(e.getSource() == displaySchedule){
  4. Database.viewAll();
  5. }
  6. else if(e.getSource() == displayAll){
  7. textField.setText("Open an existing file");
  8. }

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
Reputation Points: 13
Solved Threads: 0
Light Poster
DeepZ is offline Offline
27 posts
since Sep 2004

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in Java Forum Timeline: Cannot find symbol
Next Thread in Java Forum Timeline: plz help--its urgent





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC