kennykoid
asked on
Cannot get the Child form appear in the parent form
All Experts hope u guys can help me... i have some difficuties when i trying to call out another form from my current form it give me this err msg
C:\..\HotelSys.java:112: illegal start of expression
protected void Testing() {
C:\..\HotelSys.java:85: cannot resolve symbol
symbol: method Testing ()
Testing();
^
2 errors
Well, i actually want to call another form which is nmae AddGuest and it give me this error, following is my code...
import java.awt.*;
import java.awt.event.*;
import java.sql.*;
import java.util.*;
import javax.swing.*;
import javax.swing.event.*;
import java.awt.print.*;
import java.io.*;
public class HotelSys extends JFrame
{
public HotelSys()
{
JMenuBar menuBar = new JMenuBar();
setJMenuBar(menuBar);
JMenu MenuHelp = new JMenu("Help");
JMenuItem SubMenuAbout = new JMenuItem( "About HotelSys" );
MenuHelp.add( SubMenuAbout );
menuBar.add(MenuHelp);
MenuHelp.addActionListener (new ActionListener() {
public void actionPerformed(ActionEven t e) {
Testing();
}
});
protected void Testing() {
AddGuest m = new AddGuest();
m.setVisible(true);
desktop.add(m);
m.addInternalFrameListener ( this );
try {
m.setSelected(true);
} catch (java.beans.PropertyVetoEx ception e) {}
}
setSize(1027,760);
setResizable(false);
show();
}
public static void main(String args[])
{
HotelSys hotel = new HotelSys();
hotel.addWindowListener(ne w WindowAdapter(){
public void windowClosing(WindowEvent e){
JOptionPane.showMessageDia log( null,
"Thank you .", "Exit",
JOptionPane.INFORMATION_ME SSAGE );
System.exit(0);
}});}}
//----Really hope you guys can help me out ,thank you---//
// please give me opinion if my way is wrong , i am JAVA beginner//
C:\..\HotelSys.java:112: illegal start of expression
protected void Testing() {
C:\..\HotelSys.java:85: cannot resolve symbol
symbol: method Testing ()
Testing();
^
2 errors
Well, i actually want to call another form which is nmae AddGuest and it give me this error, following is my code...
import java.awt.*;
import java.awt.event.*;
import java.sql.*;
import java.util.*;
import javax.swing.*;
import javax.swing.event.*;
import java.awt.print.*;
import java.io.*;
public class HotelSys extends JFrame
{
public HotelSys()
{
JMenuBar menuBar = new JMenuBar();
setJMenuBar(menuBar);
JMenu MenuHelp = new JMenu("Help");
JMenuItem SubMenuAbout = new JMenuItem( "About HotelSys" );
MenuHelp.add( SubMenuAbout );
menuBar.add(MenuHelp);
MenuHelp.addActionListener
public void actionPerformed(ActionEven
Testing();
}
});
protected void Testing() {
AddGuest m = new AddGuest();
m.setVisible(true);
desktop.add(m);
m.addInternalFrameListener
try {
m.setSelected(true);
} catch (java.beans.PropertyVetoEx
}
setSize(1027,760);
setResizable(false);
show();
}
public static void main(String args[])
{
HotelSys hotel = new HotelSys();
hotel.addWindowListener(ne
public void windowClosing(WindowEvent e){
JOptionPane.showMessageDia
"Thank you .", "Exit",
JOptionPane.INFORMATION_ME
System.exit(0);
}});}}
//----Really hope you guys can help me out ,thank you---//
// please give me opinion if my way is wrong , i am JAVA beginner//
Your Testing() method is protected. You can't call it from classes outside the package or from classes that do not extend the HotelSys class.
your braces "{}" were in the wrong places...
I also changed the method names to start with a lower case letter (it is MUCH easier to debug code if only classes start with an uppercase letter)
And I changed the menuHelp variable to use a lowercase first letter too (for the same reason)
Tim.
I also changed the method names to start with a lower case letter (it is MUCH easier to debug code if only classes start with an uppercase letter)
And I changed the menuHelp variable to use a lowercase first letter too (for the same reason)
Tim.
ASKER
thank for the reply, by the way girionis, can i know which part of my braces in the wrong place? anyway i have try to move the method out but another err is out
C:\..\HotelSys.java:140: cannot resolve symbol
symbol : variable desktop
location: class HotelSys
desktop.add(m);
^
C:\..\HotelSys.java:141: addInternalFrameListener(j avax.swing .event.Int ernalFrame Listener) in javax.swing.JInternalFrame cannot be applied to (HotelSys)
m.addInternalFrameListener ( this );
^
2 errors
anyway girionis it is the same error if i change the protected to public same error is occur..anyway i put my entire code here now.. well i know my code is not Pro.. but i am a beginner.. waiting for u ppl help please
import java.awt.*;
import java.awt.event.*;
import java.sql.*;
import java.util.*;
import javax.swing.*;
import javax.swing.event.*;
import java.awt.print.*;
import java.io.*;
public class HotelSys extends JFrame
{
public HotelSys()
{
super(" xxx Hotel Management System");
//MenuBar Define
JMenuBar menuBar = new JMenuBar();
setJMenuBar(menuBar);
//Define the Menu Bar and Sub Menu
JMenu MenuFile = new JMenu("File");
JMenu MenuReservation = new JMenu("Reservation");
JMenu MenuGuests = new JMenu("Guest");
JMenu MenuAction = new JMenu("Action");
JMenu MenuReport = new JMenu("Reports");
JMenu MenuHelp = new JMenu("Help");
JMenuItem SubMenuExit = new JMenuItem( "Exit" );
JMenuItem SubMenuAddRe = new JMenuItem( "Add Reservation" );
JMenuItem SubMenuUpdateRe = new JMenuItem( "Update Reservation" );
JMenuItem SubMenuCancelRe = new JMenuItem( "Cancel Reservation" );
JMenuItem SubMenuAddGuest = new JMenuItem( "Add Guest" );
JMenuItem SubMenuDelGuest = new JMenuItem( "Delete Guest" );
JMenuItem SubMenuCheckIn = new JMenuItem( "Check In" );
JMenuItem SubMenuCheckOut = new JMenuItem( "Check Out" );
JMenuItem SubMenuViewReport = new JMenuItem( "View Report" );
JMenuItem SubMenuPrintReport = new JMenuItem( "Print Report" );
JMenuItem SubMenuAbout = new JMenuItem( "About HotelSys" );
//Add the Sub Menu
MenuFile.add( SubMenuExit );
MenuReservation.add( SubMenuAddRe );
MenuReservation.add( SubMenuUpdateRe );
MenuReservation.add( SubMenuCancelRe );
MenuGuests.add( SubMenuAddGuest );
MenuGuests.add( SubMenuDelGuest );
MenuAction.add( SubMenuCheckIn );
MenuAction.add( SubMenuCheckOut );
MenuReport.add( SubMenuViewReport );
MenuReport.add( SubMenuPrintReport );
MenuHelp.add( SubMenuAbout );
SubMenuExit.setMnemonic( 'E' );
SubMenuAddRe.setMnemonic( 'A' );
SubMenuUpdateRe .setMnemonic( 'U' );
SubMenuCancelRe.setMnemoni c( 'C' );
SubMenuAddGuest.setMnemoni c( 'A' );
SubMenuDelGuest.setMnemoni c( 'D' );
SubMenuCheckIn.setMnemonic ( 'I' );
SubMenuCheckOut.setMnemoni c( 'O' );
SubMenuViewReport.setMnemo nic( 'V' );
SubMenuPrintReport.setMnem onic( 'P' );
SubMenuAbout.setMnemonic( 'A' );
//Add the Menu
menuBar.add(MenuFile);
menuBar.add(MenuReservatio n);
menuBar.add(MenuGuests);
menuBar.add(MenuAction);
menuBar.add(MenuReport );
menuBar.add(MenuHelp);
MenuFile.setMnemonic( 'F' );
MenuReservation.setMnemoni c( 'e' );
MenuGuests.setMnemonic( 'G' );
MenuAction.setMnemonic( 'A' );
MenuReport.setMnemonic( 'R' );
MenuHelp.setMnemonic( 'H' );
MenuHelp.addActionListener (new ActionListener() {
public void actionPerformed(ActionEven t e) {
testing();
}
});
//------------------------ ---------- ---------- ---------- ---------- ---------- -------//
//Start (SubMenuExit)//
SubMenuExit.setAccelerator ( KeyStroke.getKeyStroke( KeyEvent.VK_F4, KeyEvent.CTRL_MASK ) );
SubMenuExit.addActionListe ner(new ActionListener(){
public void actionPerformed( ActionEvent e ){
int exit = JOptionPane.showConfirmDia log( null,
"Are you sure you want to exit from the system?", "Exit",
JOptionPane.YES_NO_OPTION );
if( exit == 0 ){
JOptionPane.showMessageDia log( null,
"Thank you for using PlusCare Hotel Reservation System.", "Exit",
JOptionPane.INFORMATION_ME SSAGE );
System.exit( 0 );
}
}
}
);
//------------------------ ---------- ---------- ---------- ---------- ---------- -------/// /
//------------------------ ---------- ---------- ---------- ---------- ---------- ---------- -//
setSize(1027,760);
setResizable(false);
show();
}
public void testing() {
AddGuest m = new AddGuest();
m.setVisible(true);
desktop.add(m);
m.addInternalFrameListener ( this );
try {
m.setSelected(true);
} catch (java.beans.PropertyVetoEx ception e)
{}
}
public static void main(String args[])
{
HotelSys hotel = new HotelSys();
hotel.addWindowListener (new WindowAdapter(){
public void windowClosing(WindowEvent e){
JOptionPane.showMessageDia log( null,
"Thank you for using xxx Hotel ManagementSystem.", "Exit",
JOptionPane.INFORMATION_ME SSAGE );
System.exit(0);
}
});
}
}
C:\..\HotelSys.java:140: cannot resolve symbol
symbol : variable desktop
location: class HotelSys
desktop.add(m);
^
C:\..\HotelSys.java:141: addInternalFrameListener(j
m.addInternalFrameListener
^
2 errors
anyway girionis it is the same error if i change the protected to public same error is occur..anyway i put my entire code here now.. well i know my code is not Pro.. but i am a beginner.. waiting for u ppl help please
import java.awt.*;
import java.awt.event.*;
import java.sql.*;
import java.util.*;
import javax.swing.*;
import javax.swing.event.*;
import java.awt.print.*;
import java.io.*;
public class HotelSys extends JFrame
{
public HotelSys()
{
super(" xxx Hotel Management System");
//MenuBar Define
JMenuBar menuBar = new JMenuBar();
setJMenuBar(menuBar);
//Define the Menu Bar and Sub Menu
JMenu MenuFile = new JMenu("File");
JMenu MenuReservation = new JMenu("Reservation");
JMenu MenuGuests = new JMenu("Guest");
JMenu MenuAction = new JMenu("Action");
JMenu MenuReport = new JMenu("Reports");
JMenu MenuHelp = new JMenu("Help");
JMenuItem SubMenuExit = new JMenuItem( "Exit" );
JMenuItem SubMenuAddRe = new JMenuItem( "Add Reservation" );
JMenuItem SubMenuUpdateRe = new JMenuItem( "Update Reservation" );
JMenuItem SubMenuCancelRe = new JMenuItem( "Cancel Reservation" );
JMenuItem SubMenuAddGuest = new JMenuItem( "Add Guest" );
JMenuItem SubMenuDelGuest = new JMenuItem( "Delete Guest" );
JMenuItem SubMenuCheckIn = new JMenuItem( "Check In" );
JMenuItem SubMenuCheckOut = new JMenuItem( "Check Out" );
JMenuItem SubMenuViewReport = new JMenuItem( "View Report" );
JMenuItem SubMenuPrintReport = new JMenuItem( "Print Report" );
JMenuItem SubMenuAbout = new JMenuItem( "About HotelSys" );
//Add the Sub Menu
MenuFile.add( SubMenuExit );
MenuReservation.add( SubMenuAddRe );
MenuReservation.add( SubMenuUpdateRe );
MenuReservation.add( SubMenuCancelRe );
MenuGuests.add( SubMenuAddGuest );
MenuGuests.add( SubMenuDelGuest );
MenuAction.add( SubMenuCheckIn );
MenuAction.add( SubMenuCheckOut );
MenuReport.add( SubMenuViewReport );
MenuReport.add( SubMenuPrintReport );
MenuHelp.add( SubMenuAbout );
SubMenuExit.setMnemonic( 'E' );
SubMenuAddRe.setMnemonic( 'A' );
SubMenuUpdateRe .setMnemonic( 'U' );
SubMenuCancelRe.setMnemoni
SubMenuAddGuest.setMnemoni
SubMenuDelGuest.setMnemoni
SubMenuCheckIn.setMnemonic
SubMenuCheckOut.setMnemoni
SubMenuViewReport.setMnemo
SubMenuPrintReport.setMnem
SubMenuAbout.setMnemonic( 'A' );
//Add the Menu
menuBar.add(MenuFile);
menuBar.add(MenuReservatio
menuBar.add(MenuGuests);
menuBar.add(MenuAction);
menuBar.add(MenuReport );
menuBar.add(MenuHelp);
MenuFile.setMnemonic( 'F' );
MenuReservation.setMnemoni
MenuGuests.setMnemonic( 'G' );
MenuAction.setMnemonic( 'A' );
MenuReport.setMnemonic( 'R' );
MenuHelp.setMnemonic( 'H' );
MenuHelp.addActionListener
public void actionPerformed(ActionEven
testing();
}
});
//------------------------
//Start (SubMenuExit)//
SubMenuExit.setAccelerator
SubMenuExit.addActionListe
public void actionPerformed( ActionEvent e ){
int exit = JOptionPane.showConfirmDia
"Are you sure you want to exit from the system?", "Exit",
JOptionPane.YES_NO_OPTION );
if( exit == 0 ){
JOptionPane.showMessageDia
"Thank you for using PlusCare Hotel Reservation System.", "Exit",
JOptionPane.INFORMATION_ME
System.exit( 0 );
}
}
}
);
//------------------------
//------------------------
setSize(1027,760);
setResizable(false);
show();
}
public void testing() {
AddGuest m = new AddGuest();
m.setVisible(true);
desktop.add(m);
m.addInternalFrameListener
try {
m.setSelected(true);
} catch (java.beans.PropertyVetoEx
{}
}
public static void main(String args[])
{
HotelSys hotel = new HotelSys();
hotel.addWindowListener (new WindowAdapter(){
public void windowClosing(WindowEvent e){
JOptionPane.showMessageDia
"Thank you for using xxx Hotel ManagementSystem.", "Exit",
JOptionPane.INFORMATION_ME
System.exit(0);
}
});
}
}
Actually it was Tim that corectly suggested the misplaced curly brackets.
> cannot resolve symbol
>symbol : variable desktop
Where is the variable "desktop" and where do you initialize it?
> cannot resolve symbol
>symbol : variable desktop
Where is the variable "desktop" and where do you initialize it?
> m.addInternalFrameListener ( this );
You need to pass as argument to addInternalFrameListener an object of type javax.swing.event.Internal FrameListe ner but you currently pass it an object of type HotelSys. You either need to implement the javax.swing.event.Internal FrameListe ner interface or write a new class that does it.
You need to pass as argument to addInternalFrameListener an object of type javax.swing.event.Internal
There were two obvious cases
1) You didn't close the constructor before you started the Testing method
2) You had "setSize" and 3 other method calls hanging off the bottom of "Testing", and not in a method
I think you pasted the Testing method right in the middle of the constructor...
1) You didn't close the constructor before you started the Testing method
2) You had "setSize" and 3 other method calls hanging off the bottom of "Testing", and not in a method
I think you pasted the Testing method right in the middle of the constructor...
ASKER
well i only leave one more error.. like what girionis.. i would paste out the error as well as all the code i have code..
the error however is this....
C:\..\HotelSys.java:144: addInternalFrameListener(j avax.swing .event.Int ernalFrame Listener) in javax.swing.JInternalFrame cannot be applied to (HotelSys)
m.addInternalFrameListener ( this );
^
1 error
I have 3 file actually one is main, another one is AddGuest while another is AddGuest_interface. so this will be the code
/---HotelSys.Java---/
import java.awt.*;
import java.awt.event.*;
import java.sql.*;
import java.util.*;
import javax.swing.*;
import javax.swing.event.*;
import java.awt.print.*;
import java.io.*;
public class HotelSys extends JFrame
{
public JDesktopPane desktop = new JDesktopPane();
public HotelSys()
{
super(" PlusCare Hotel Management System");
//setIconImage( Toolkit.getDefaultToolkit( ).createIm age(
// "no.jpg" ) );
setContentPane(desktop);
//MenuBar Define
JMenuBar menuBar = new JMenuBar();
setJMenuBar(menuBar);
//Define the Menu Bar and Sub Menu
JMenu MenuFile = new JMenu("File");
JMenu MenuReservation = new JMenu("Reservation");
JMenu MenuGuests = new JMenu("Guest");
JMenu MenuAction = new JMenu("Action");
JMenu MenuReport = new JMenu("Reports");
JMenu MenuHelp = new JMenu("Help");
JMenuItem SubMenuExit = new JMenuItem( "Exit" );
JMenuItem SubMenuAddRe = new JMenuItem( "Add Reservation" );
JMenuItem SubMenuUpdateRe = new JMenuItem( "Update Reservation" );
JMenuItem SubMenuCancelRe = new JMenuItem( "Cancel Reservation" );
JMenuItem SubMenuAddGuest = new JMenuItem( "Add Guest" );
JMenuItem SubMenuDelGuest = new JMenuItem( "Delete Guest" );
JMenuItem SubMenuCheckIn = new JMenuItem( "Check In" );
JMenuItem SubMenuCheckOut = new JMenuItem( "Check Out" );
JMenuItem SubMenuViewReport = new JMenuItem( "View Report" );
JMenuItem SubMenuPrintReport = new JMenuItem( "Print Report" );
JMenuItem SubMenuAbout = new JMenuItem( "About HotelSys" );
//Add the Sub Menu
MenuFile.add( SubMenuExit );
MenuReservation.add( SubMenuAddRe );
MenuReservation.add( SubMenuUpdateRe );
MenuReservation.add( SubMenuCancelRe );
MenuGuests.add( SubMenuAddGuest );
MenuGuests.add( SubMenuDelGuest );
MenuAction.add( SubMenuCheckIn );
MenuAction.add( SubMenuCheckOut );
MenuReport.add( SubMenuViewReport );
MenuReport.add( SubMenuPrintReport );
MenuHelp.add( SubMenuAbout );
SubMenuExit.setMnemonic( 'E' );
SubMenuAddRe.setMnemonic( 'A' );
SubMenuUpdateRe .setMnemonic( 'U' );
SubMenuCancelRe.setMnemoni c( 'C' );
SubMenuAddGuest.setMnemoni c( 'A' );
SubMenuDelGuest.setMnemoni c( 'D' );
SubMenuCheckIn.setMnemonic ( 'I' );
SubMenuCheckOut.setMnemoni c( 'O' );
SubMenuViewReport.setMnemo nic( 'V' );
SubMenuPrintReport.setMnem onic( 'P' );
SubMenuAbout.setMnemonic( 'A' );
//Add the Menu
menuBar.add(MenuFile);
menuBar.add(MenuReservatio n);
menuBar.add(MenuGuests);
menuBar.add(MenuAction);
menuBar.add(MenuReport );
menuBar.add(MenuHelp);
MenuFile.setMnemonic( 'F' );
MenuReservation.setMnemoni c( 'e' );
MenuGuests.setMnemonic( 'G' );
MenuAction.setMnemonic( 'A' );
MenuReport.setMnemonic( 'R' );
MenuHelp.setMnemonic( 'H' );
MenuHelp.addActionListener (new ActionListener() {
public void actionPerformed(ActionEven t e) {
testing();
}
});
//------------------------ ---------- ---------- ---------- ---------- ---------- -------//
//Start (SubMenuExit)//
SubMenuExit.setAccelerator ( KeyStroke.getKeyStroke( KeyEvent.VK_F4, KeyEvent.CTRL_MASK ) );
SubMenuExit.addActionListe ner(new ActionListener(){
public void actionPerformed( ActionEvent e ){
int exit = JOptionPane.showConfirmDia log( null,
"Are you sure you want to exit from the system?", "Exit",
JOptionPane.YES_NO_OPTION );
if( exit == 0 ){
JOptionPane.showMessageDia log( null,
"Thank you for using PlusCare Hotel Reservation System.", "Exit",
JOptionPane.INFORMATION_ME SSAGE );
System.exit( 0 );
}
}
}
);
//------------------------ ---------- ---------- ---------- ---------- ---------- -------/// /
//------------------------ ---------- ---------- ---------- ---------- ---------- ---------- -//
//Container c = getContentPane();
//c.setLayout( new BorderLayout() );
//Icon mainBgIcon = new ImageIcon( "bg.jpg" );
//JLabel bgLabel = new JLabel();
//bgLabel.setIcon( mainBgIcon );
//c.add( bgLabel );
setSize(1027,760);
setResizable(false);
show();
}
public void testing() {
AddGuest m = new AddGuest();
m.setVisible(true);
desktop.add(m);
m.addInternalFrameListener ( this );
try {
m.setSelected(true);
} catch (java.beans.PropertyVetoEx ception e)
{}
}
public static void main(String args[])
{
HotelSys hotel = new HotelSys();
hotel.addWindowListener (new WindowAdapter(){
public void windowClosing(WindowEvent e){
JOptionPane.showMessageDia log( null,
"Thank you for using PlusCare Hotel ManagementSystem.", "Exit",
JOptionPane.INFORMATION_ME SSAGE );
System.exit(0);
}
});
}
}
/------AddGuest.java----/
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
import java.sql.*;
import javax.swing.JInternalFrame ;
public class AddGuest extends JInternalFrame implements AddGuest_interface{
private int paintx, painty;
public AddGuest()
{
super("Add Guest",
true, //resizable
true, //closable
true, //maximizable
true);//iconifiable
int inset = 250;
//addButtons(toolBar);
Dimension screenSize = Toolkit.getDefaultToolkit( ).getScree nSize();
Container c = getContentPane();
setSize(800, 500);
setLocation(0, 0);
setResizable(false);
show();
paintx = (screenSize.width);
painty = (screenSize.height);
setBounds( (paintx - 800)/2 , ((painty-100) - 500)/2,
800,500);
//c.add(toolBar, BorderLayout.NORTH);
//c.add(gen, BorderLayout.CENTER);
}
public static void main(String args[])
{
AddGuest hotel = new AddGuest();
//hotel.addWindowListener (new WindowAdapter(){
//public void windowClosing(WindowEvent e){
//JOptionPane.showMessageD ialog( null,
// "Thank you for using PlusCare Hotel ManagementSystem.", "Exit",
// JOptionPane.INFORMATION_ME SSAGE );
//System.exit(0);
}
//});
}
/----AddGuest_interface--- /
import javax.swing.*;
import java.awt.*;
public interface AddGuest_interface
{
public JPanel text = new JPanel();
public String type_list[] = {"Male", "Female"};
public JTextField AddGuest_ID = new JTextField(20);
public JTextField AddGuest_Name = new JTextField(20);
public JTextField AddGuest_IC = new JTextField(20);
public JTextField AddGuest_Address = new JTextField(20);
public JTextField AddGuest_PostCode = new JTextField(20);
public JTextField AddGuest_City = new JTextField(20);
public JTextField AddGuest_State = new JTextField(20);
public JTextField AddGuest_Country = new JTextField(20);
public JTextField AddGuest_Contact = new JTextField(20);
public JComboBox AddGuest_Sex = new JComboBox(type_list);
public JLabel AddGuest_ID_J = new JLabel("Guest ID");
public JLabel jAddGuest_Name_J = new JLabel("Name");
public JLabel AddGuest_IC_J = new JLabel("IC/Passpost #");
public JLabel AddGuest_Sex_J= new JLabel("Sex");
public JLabel AddGuest_Address_J = new JLabel("Address");
public JLabel AddGuest_PostCode_J = new JLabel("Postcode");
public JLabel AddGuest_City_J = new JLabel("City");
public JLabel AddGuest_State_J = new JLabel("State");
public JLabel AddGuest_Country_J = new JLabel("Country");
public JLabel AddGuest_Contact_J = new JLabel("Contact");
}
/----I really happy casuse you guys actually guide me---/
the error however is this....
C:\..\HotelSys.java:144: addInternalFrameListener(j
m.addInternalFrameListener
^
1 error
I have 3 file actually one is main, another one is AddGuest while another is AddGuest_interface. so this will be the code
/---HotelSys.Java---/
import java.awt.*;
import java.awt.event.*;
import java.sql.*;
import java.util.*;
import javax.swing.*;
import javax.swing.event.*;
import java.awt.print.*;
import java.io.*;
public class HotelSys extends JFrame
{
public JDesktopPane desktop = new JDesktopPane();
public HotelSys()
{
super(" PlusCare Hotel Management System");
//setIconImage( Toolkit.getDefaultToolkit(
// "no.jpg" ) );
setContentPane(desktop);
//MenuBar Define
JMenuBar menuBar = new JMenuBar();
setJMenuBar(menuBar);
//Define the Menu Bar and Sub Menu
JMenu MenuFile = new JMenu("File");
JMenu MenuReservation = new JMenu("Reservation");
JMenu MenuGuests = new JMenu("Guest");
JMenu MenuAction = new JMenu("Action");
JMenu MenuReport = new JMenu("Reports");
JMenu MenuHelp = new JMenu("Help");
JMenuItem SubMenuExit = new JMenuItem( "Exit" );
JMenuItem SubMenuAddRe = new JMenuItem( "Add Reservation" );
JMenuItem SubMenuUpdateRe = new JMenuItem( "Update Reservation" );
JMenuItem SubMenuCancelRe = new JMenuItem( "Cancel Reservation" );
JMenuItem SubMenuAddGuest = new JMenuItem( "Add Guest" );
JMenuItem SubMenuDelGuest = new JMenuItem( "Delete Guest" );
JMenuItem SubMenuCheckIn = new JMenuItem( "Check In" );
JMenuItem SubMenuCheckOut = new JMenuItem( "Check Out" );
JMenuItem SubMenuViewReport = new JMenuItem( "View Report" );
JMenuItem SubMenuPrintReport = new JMenuItem( "Print Report" );
JMenuItem SubMenuAbout = new JMenuItem( "About HotelSys" );
//Add the Sub Menu
MenuFile.add( SubMenuExit );
MenuReservation.add( SubMenuAddRe );
MenuReservation.add( SubMenuUpdateRe );
MenuReservation.add( SubMenuCancelRe );
MenuGuests.add( SubMenuAddGuest );
MenuGuests.add( SubMenuDelGuest );
MenuAction.add( SubMenuCheckIn );
MenuAction.add( SubMenuCheckOut );
MenuReport.add( SubMenuViewReport );
MenuReport.add( SubMenuPrintReport );
MenuHelp.add( SubMenuAbout );
SubMenuExit.setMnemonic( 'E' );
SubMenuAddRe.setMnemonic( 'A' );
SubMenuUpdateRe .setMnemonic( 'U' );
SubMenuCancelRe.setMnemoni
SubMenuAddGuest.setMnemoni
SubMenuDelGuest.setMnemoni
SubMenuCheckIn.setMnemonic
SubMenuCheckOut.setMnemoni
SubMenuViewReport.setMnemo
SubMenuPrintReport.setMnem
SubMenuAbout.setMnemonic( 'A' );
//Add the Menu
menuBar.add(MenuFile);
menuBar.add(MenuReservatio
menuBar.add(MenuGuests);
menuBar.add(MenuAction);
menuBar.add(MenuReport );
menuBar.add(MenuHelp);
MenuFile.setMnemonic( 'F' );
MenuReservation.setMnemoni
MenuGuests.setMnemonic( 'G' );
MenuAction.setMnemonic( 'A' );
MenuReport.setMnemonic( 'R' );
MenuHelp.setMnemonic( 'H' );
MenuHelp.addActionListener
public void actionPerformed(ActionEven
testing();
}
});
//------------------------
//Start (SubMenuExit)//
SubMenuExit.setAccelerator
SubMenuExit.addActionListe
public void actionPerformed( ActionEvent e ){
int exit = JOptionPane.showConfirmDia
"Are you sure you want to exit from the system?", "Exit",
JOptionPane.YES_NO_OPTION );
if( exit == 0 ){
JOptionPane.showMessageDia
"Thank you for using PlusCare Hotel Reservation System.", "Exit",
JOptionPane.INFORMATION_ME
System.exit( 0 );
}
}
}
);
//------------------------
//------------------------
//Container c = getContentPane();
//c.setLayout( new BorderLayout() );
//Icon mainBgIcon = new ImageIcon( "bg.jpg" );
//JLabel bgLabel = new JLabel();
//bgLabel.setIcon( mainBgIcon );
//c.add( bgLabel );
setSize(1027,760);
setResizable(false);
show();
}
public void testing() {
AddGuest m = new AddGuest();
m.setVisible(true);
desktop.add(m);
m.addInternalFrameListener
try {
m.setSelected(true);
} catch (java.beans.PropertyVetoEx
{}
}
public static void main(String args[])
{
HotelSys hotel = new HotelSys();
hotel.addWindowListener (new WindowAdapter(){
public void windowClosing(WindowEvent e){
JOptionPane.showMessageDia
"Thank you for using PlusCare Hotel ManagementSystem.", "Exit",
JOptionPane.INFORMATION_ME
System.exit(0);
}
});
}
}
/------AddGuest.java----/
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
import java.sql.*;
import javax.swing.JInternalFrame
public class AddGuest extends JInternalFrame implements AddGuest_interface{
private int paintx, painty;
public AddGuest()
{
super("Add Guest",
true, //resizable
true, //closable
true, //maximizable
true);//iconifiable
int inset = 250;
//addButtons(toolBar);
Dimension screenSize = Toolkit.getDefaultToolkit(
Container c = getContentPane();
setSize(800, 500);
setLocation(0, 0);
setResizable(false);
show();
paintx = (screenSize.width);
painty = (screenSize.height);
setBounds( (paintx - 800)/2 , ((painty-100) - 500)/2,
800,500);
//c.add(toolBar, BorderLayout.NORTH);
//c.add(gen, BorderLayout.CENTER);
}
public static void main(String args[])
{
AddGuest hotel = new AddGuest();
//hotel.addWindowListener (new WindowAdapter(){
//public void windowClosing(WindowEvent e){
//JOptionPane.showMessageD
// "Thank you for using PlusCare Hotel ManagementSystem.", "Exit",
// JOptionPane.INFORMATION_ME
//System.exit(0);
}
//});
}
/----AddGuest_interface---
import javax.swing.*;
import java.awt.*;
public interface AddGuest_interface
{
public JPanel text = new JPanel();
public String type_list[] = {"Male", "Female"};
public JTextField AddGuest_ID = new JTextField(20);
public JTextField AddGuest_Name = new JTextField(20);
public JTextField AddGuest_IC = new JTextField(20);
public JTextField AddGuest_Address = new JTextField(20);
public JTextField AddGuest_PostCode = new JTextField(20);
public JTextField AddGuest_City = new JTextField(20);
public JTextField AddGuest_State = new JTextField(20);
public JTextField AddGuest_Country = new JTextField(20);
public JTextField AddGuest_Contact = new JTextField(20);
public JComboBox AddGuest_Sex = new JComboBox(type_list);
public JLabel AddGuest_ID_J = new JLabel("Guest ID");
public JLabel jAddGuest_Name_J = new JLabel("Name");
public JLabel AddGuest_IC_J = new JLabel("IC/Passpost #");
public JLabel AddGuest_Sex_J= new JLabel("Sex");
public JLabel AddGuest_Address_J = new JLabel("Address");
public JLabel AddGuest_PostCode_J = new JLabel("Postcode");
public JLabel AddGuest_City_J = new JLabel("City");
public JLabel AddGuest_State_J = new JLabel("State");
public JLabel AddGuest_Country_J = new JLabel("Country");
public JLabel AddGuest_Contact_J = new JLabel("Contact");
}
/----I really happy casuse you guys actually guide me---/
you will have to make HotelSys "implement InternalFrameAdaptor"
http://java.sun.com/docs/books/tutorial/uiswing/events/internalframelistener.html
Tells you all about what it is and what it does...
Tim
http://java.sun.com/docs/books/tutorial/uiswing/events/internalframelistener.html
Tells you all about what it is and what it does...
Tim
Sorry...
> you will have to make HotelSys "implement InternalFrameAdaptor"
should read;
-------------------
you will have to make HotelSys "implement InternalFrameListener"
> you will have to make HotelSys "implement InternalFrameAdaptor"
should read;
-------------------
you will have to make HotelSys "implement InternalFrameListener"
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
> or right a brand new class that "implements
should be
or write a brand new class that "implements
should be
or write a brand new class that "implements
ASKER
well,Thank for both ideas and comments, well, to make the thing simple i actually only want to make a main page which can act as a Parent MDI form and call the Child AddGuest when i needed but Main must be Maximize all the time while AddGuest in the child, well while the AddGuest_interface actually want to make the code more clear instead on putting in.. any idea for me to do it without using the "implement InternalFrameListener". I willing to learn actually but i have no time to do it. Well i know VB6, and franky speak this is my 1st time to make a JAVA App, it is not easy like VB... so any opinion for me? dude, need u guys help serious.
Kenny
Kenny
>> Main page which can act as a Parent MDI form and call the Child AddGuest
Try this very simple sample :
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
public class Word extends JFrame {
public Word()
{
super("Main Frame");
JDesktopPane p1 = new JDesktopPane();
JInternalFrame f1 = new JInternalFrame("Child Frame",false,true,false,tr ue);
JTextArea txt1 = new JTextArea();
txt1.setSize(300,300);
f1.add(new JScrollPane(txt1));
f1.show();
p1.add(f1);
getContentPane().setLayout ( new BorderLayout() );
getContentPane().add( p1, BorderLayout.CENTER);
setSize(500, 500);
show();
}
public static void main (String args[])
{
Word x = new Word();
x.addWindowListener(
new WindowAdapter() {
public void windowClosing( WindowEvent e )
{
System.exit( 0 );
}
}
);
}
}
Try this very simple sample :
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
public class Word extends JFrame {
public Word()
{
super("Main Frame");
JDesktopPane p1 = new JDesktopPane();
JInternalFrame f1 = new JInternalFrame("Child Frame",false,true,false,tr
JTextArea txt1 = new JTextArea();
txt1.setSize(300,300);
f1.add(new JScrollPane(txt1));
f1.show();
p1.add(f1);
getContentPane().setLayout
getContentPane().add( p1, BorderLayout.CENTER);
setSize(500, 500);
show();
}
public static void main (String args[])
{
Word x = new Word();
x.addWindowListener(
new WindowAdapter() {
public void windowClosing( WindowEvent e )
{
System.exit( 0 );
}
}
);
}
}
ASKER
well i think i understand a bit of ur codr, but the code give me error after i run..
Exception in thread "main" java.lang.Error: Do not use javax.swing.JInternalFram
e.add() use javax.swing.JInternalFrame .getConten tPane().ad d() instead
at javax.swing.JInternalFrame .createRoo tPaneExcep tion(JInte rnalFrame. jav
a:416)
at javax.swing.JInternalFrame .addImpl(J InternalFr ame.java:4 43)
at java.awt.Container.add(Con tainer.jav a:307)
at Word.<init>(Word.java:16)
at Word.main(Word.java:29)
Press any key to continue...
i not good in JAVA .. sorry for that
:)
Exception in thread "main" java.lang.Error: Do not use javax.swing.JInternalFram
e.add() use javax.swing.JInternalFrame
at javax.swing.JInternalFrame
a:416)
at javax.swing.JInternalFrame
at java.awt.Container.add(Con
at Word.<init>(Word.java:16)
at Word.main(Word.java:29)
Press any key to continue...
i not good in JAVA .. sorry for that
:)
Change this:
> f1.add(new JScrollPane(txt1));
to this:
fi.getContentPane().add(ne w JScrollPane(txt1))
> f1.add(new JScrollPane(txt1));
to this:
fi.getContentPane().add(ne
ASKER
hmmm... well thank for all comments..
:)
import java.awt.event.* ;
import java.sql.* ;
import java.util.* ;
import javax.swing.* ;
import javax.swing.event.* ;
import java.awt.print.* ;
import java.io.* ;
public class HotelSys
extends JFrame
{
public HotelSys()
{
JMenuBar menuBar = new JMenuBar() ;
setJMenuBar( menuBar ) ;
JMenu menuHelp = new JMenu( "Help" ) ;
JMenuItem SubMenuAbout = new JMenuItem( "About HotelSys" ) ;
menuHelp.add( SubMenuAbout ) ;
menuBar.add( menuHelp ) ;
menuHelp.addActionListener
{
public void actionPerformed( ActionEvent e )
{
testing() ;
}
} ) ;
setSize( 1027, 760 ) ;
setResizable( false ) ;
show() ;
}
protected void testing()
{
AddGuest m = new AddGuest() ;
m.setVisible( true ) ;
desktop.add( m ) ;
m.addInternalFrameListener
try
{
m.setSelected( true ) ;
}
catch( java.beans.PropertyVetoExc
{}
}
public static void main( String args[] )
{
HotelSys hotel = new HotelSys() ;
hotel.addWindowListener( new WindowAdapter()
{
public void windowClosing( WindowEvent e )
{
JOptionPane.showMessageDia
"Thank you .", "Exit",
JOptionPane.INFORMATION_ME
System.exit( 0 ) ;
}
} ) ;
}
}