| | |
JFrame GUI Problem
![]() |
•
•
Join Date: Mar 2005
Posts: 73
Reputation:
Solved Threads: 0
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
class from where method is called
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)
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
Java Syntax (Toggle Plain Text)
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 :
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
Java Syntax (Toggle Plain Text)
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
:?: Sometimes i wonder if i'm on the right planet :!:
![]() |
Similar Threads
- Windows GUI - problem with dialog box (C++)
- Java GUI problem... contents of JFrame is invisible... (Java)
- basic java GUI problem (Java)
Other Threads in the Java Forum
- Previous Thread: Cannot find symbol
- Next Thread: plz help--its urgent
| Thread Tools | Search this Thread |
911 actionlistener addressbook android api append applet application array arrays automation binary blackberry block bluetooth character chat class client code component consumer csv database desktop developmenthelp eclipse error fractal ftp game givemetehcodez graphics gui html ide image integer j2me j2seprojects japplet java javaarraylist javac javaee javaprojects jni jpanel julia lego linked linux list loops mac map method methods mobile netbeans newbie number objects online oriented panel printf problem program programming project projects properties recursion replaydirector reporting researchinmotion rotatetext rsa scanner se server set singleton sms sort sql string swing test textfields threads time title tree tutorial-sample ubuntu update windows working





