New Posts  All Forums:Forum Nav:

Java GUI Question

post #1 of 16
Thread Starter 
I have an applet that when you click a button it opens a new window. The question is how do i get the window to replace the existing window?

Code:
    public void actionPerformed(ActionEvent evt) {
    if (evt.getSource() == empLogin) {        
    employeeLogin emp = new employeeLogin();
    emp.init();    
    
                Frame window = new Frame("Employee");
    window.add("Center", emp);
window.pack();
window.setVisible(true);
    
    }
in this code it will create a new window, so the question is how do i go about to make it replace the existing window which is declared here:

Code:
    public static void main(String args[]) {
        login applet = new login();        
        Frame window = new Frame("login");
        
        window.addWindowListener(new WindowAdapter() {
            public void windowClosing(WindowEvent e) {
                System.exit(0);
            }            
        });

        applet.init();
        window.add("Center", applet);
        window.pack();
        window.setVisible(true);
    }
I have tried declaring the frame window outside both the main and actionPerformed functions, but it doesn't work for main.
The Sivmiester
(13 items)
 
  
CPUMotherboardGraphicsRAM
i7 875k @ 4.0ghz EVGA p55 FTW EVGA GTX 480 - 875/1750/2100 Mushkin Redline DDR3 1600 (2x2gb) 
Hard DriveOptical DriveOSMonitor
Intel X25-M 80GB SSD, 640 WD Black, 2TB WD Green Asus 24x DVD RW+/- Win7 Ultimate x64 Asus 24" 
KeyboardPowerCaseMouse
Logitech G15v2 Silverstone Strider 1000w Obsidian 700d undecided 
Mouse Pad
Razer Destructor 
  hide details  
Reply
The Sivmiester
(13 items)
 
  
CPUMotherboardGraphicsRAM
i7 875k @ 4.0ghz EVGA p55 FTW EVGA GTX 480 - 875/1750/2100 Mushkin Redline DDR3 1600 (2x2gb) 
Hard DriveOptical DriveOSMonitor
Intel X25-M 80GB SSD, 640 WD Black, 2TB WD Green Asus 24x DVD RW+/- Win7 Ultimate x64 Asus 24" 
KeyboardPowerCaseMouse
Logitech G15v2 Silverstone Strider 1000w Obsidian 700d undecided 
Mouse Pad
Razer Destructor 
  hide details  
Reply
post #2 of 16
try this. declare the fame you have named window outside of both methods. Then, in your actionperformed method, call that decalaration of the frame and add the necessary stuff, and reset it to visible. This way, you dont actually create a new window, but rather just add the new stuff.

You could also close the original window, and open a new one and it would be as if it replaced it on the same window.

The way you have it right now, your frames are only declared in the scope of the respective methods, and cannot be accessed from each other...
post #3 of 16
Thread Starter 
Code:
public class login extends Applet implements ActionListener {
     Frame window;
          
          public main() {
               window = new Frame("login");
          }
          public actionPerformed() {
          }
}
This is how it looks, but inside main it complains about window not being declared properly. Am i doing something wrong?
The Sivmiester
(13 items)
 
  
CPUMotherboardGraphicsRAM
i7 875k @ 4.0ghz EVGA p55 FTW EVGA GTX 480 - 875/1750/2100 Mushkin Redline DDR3 1600 (2x2gb) 
Hard DriveOptical DriveOSMonitor
Intel X25-M 80GB SSD, 640 WD Black, 2TB WD Green Asus 24x DVD RW+/- Win7 Ultimate x64 Asus 24" 
KeyboardPowerCaseMouse
Logitech G15v2 Silverstone Strider 1000w Obsidian 700d undecided 
Mouse Pad
Razer Destructor 
  hide details  
Reply
The Sivmiester
(13 items)
 
  
CPUMotherboardGraphicsRAM
i7 875k @ 4.0ghz EVGA p55 FTW EVGA GTX 480 - 875/1750/2100 Mushkin Redline DDR3 1600 (2x2gb) 
Hard DriveOptical DriveOSMonitor
Intel X25-M 80GB SSD, 640 WD Black, 2TB WD Green Asus 24x DVD RW+/- Win7 Ultimate x64 Asus 24" 
KeyboardPowerCaseMouse
Logitech G15v2 Silverstone Strider 1000w Obsidian 700d undecided 
Mouse Pad
Razer Destructor 
  hide details  
Reply
post #4 of 16
outside you have already called Frame window; You then tried to redeclare it as another Frame called login. You can't do that I don't think.
post #5 of 16
Thread Starter 
hmm, but the Frame window; isn't declared as a new frame called "login".

how would i go about closing the other window?
The Sivmiester
(13 items)
 
  
CPUMotherboardGraphicsRAM
i7 875k @ 4.0ghz EVGA p55 FTW EVGA GTX 480 - 875/1750/2100 Mushkin Redline DDR3 1600 (2x2gb) 
Hard DriveOptical DriveOSMonitor
Intel X25-M 80GB SSD, 640 WD Black, 2TB WD Green Asus 24x DVD RW+/- Win7 Ultimate x64 Asus 24" 
KeyboardPowerCaseMouse
Logitech G15v2 Silverstone Strider 1000w Obsidian 700d undecided 
Mouse Pad
Razer Destructor 
  hide details  
Reply
The Sivmiester
(13 items)
 
  
CPUMotherboardGraphicsRAM
i7 875k @ 4.0ghz EVGA p55 FTW EVGA GTX 480 - 875/1750/2100 Mushkin Redline DDR3 1600 (2x2gb) 
Hard DriveOptical DriveOSMonitor
Intel X25-M 80GB SSD, 640 WD Black, 2TB WD Green Asus 24x DVD RW+/- Win7 Ultimate x64 Asus 24" 
KeyboardPowerCaseMouse
Logitech G15v2 Silverstone Strider 1000w Obsidian 700d undecided 
Mouse Pad
Razer Destructor 
  hide details  
Reply
post #6 of 16
set visible equal to false for that frame.
post #7 of 16
I don't know java, but one would think since you have window.add("Center", emp);, that window.remove/delete might do something.
post #8 of 16
nah, it's window.setVisible(false) to close the window.
post #9 of 16
If you hide it via visible, you can still access any information you had on the form, such as Text boxes, values, etc. To save them when closing a form, you must save them into variables, storage places, etc. That is, if it is anything like Visual Basic...
post #10 of 16
I'm not sure that they're all that similar...I dunno..it's been a while. I'm not that familiar with Visual Basic.
New Posts  All Forums:Forum Nav:
  Return Home
  Back to Forum: Coding and Programming