Go Back   Java Programming Forums > Java Standard Edition Programming Help > AWT / Java Swing > Java Applets


Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 10-03-2009, 10:25 PM
Junior Member
 

Join Date: Mar 2009
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
channi3 is on a distinguished road
Question [SOLVED] Java Applet Switching To Different Windows?

Hi,

I'm very new to java, and currently learning some of the basics.

What i need help on is how to program in java so that i can change from one window to another. Not really sure how to word this but here goes:

For example, when i start the java applet, a login screen (window1) will appear, when a user enters username and password, when the user is verified, it "switches" to a different window (window2) to access the data.

Any help much appreciated.

Thanks in advance,
-channi3



Reply With Quote Share this thread on Facebook
Sponsored Links
Java Training from DevelopIntelligence
  #2 (permalink)  
Old 11-03-2009, 08:41 PM
JavaPF's Avatar
mmm.. coffee
 
8 Highscores

Join Date: May 2008
Location: United Kingdom
Posts: 1,543
Thanks: 98
Thanked 92 Times in 85 Posts
JavaPF is someone you want to know!JavaPF is someone you want to know!JavaPF is someone you want to know!

I'm feeling Relaxed
Default Re: Java Applet Switching To Different Windows?

Hello channi3 and welcome to the forums.

Take a look at this code example and compile it.

There is a main JFrame with a button on it. When this button is clicked, JFrame1 closes and opens JFrame2.

Its just a matter of invoking the run method for each form when an action is performed and setting the visibility of the previous form to false.

Java Code
import javax.swing.*;   
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

public class Channi3 {

    public static JFrame frame1 = new JFrame("Java Frame1");
    public static JFrame frame2 = new JFrame("Java Frame2");
    
    //Form1
    private static void createAndShowGUI1()  {

        frame1.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

        JButton button = new JButton("HI! IM JFRAME1 - CLICK ME TO OPEN FRAME 2");
        button.addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent e)
            {
                frame1.setVisible(false);
                System.out.println("Opening JFrame 2");
                javax.swing.SwingUtilities.invokeLater(new Runnable() {
                    public void run() {
                        createAndShowGUI2();
                       
                    }
                });
            }

        });      

        frame1.getContentPane().add(button);
        frame1.pack();
        frame1.setVisible(true);
    }
    
    
    //Form2
    private static void createAndShowGUI2()  {
        
        frame2.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

        JButton button = new JButton("HI! IM JFRAME2 - CLICK ME TO OPEN FRAME 1");
        button.addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent e)
            {
                frame2.setVisible(false);
                System.out.println("Opening JFrame 1");
                javax.swing.SwingUtilities.invokeLater(new Runnable() {
                    public void run() {
                        createAndShowGUI1();
                       
                    }
                });
            }

        });      

        frame2.getContentPane().add(button);
        frame2.pack();
        frame2.setVisible(true);
    }
    
      

    public static void main(String[] args) {
        javax.swing.SwingUtilities.invokeLater(new Runnable() {
            public void run() {
                createAndShowGUI1();
            }
        });
    }
}
__________________
Don't forget to add syntax highlighted code tags around your code: [highlight=Java] code here [/highlight]

Forum Tip: Add to peoples reputation () by clicking the button on their useful posts.
Reply With Quote
Reply

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



Similar Threads
Thread Thread Starter Forum Replies Last Post
servlet applet communication prashanthi_asn Java Servlet 0 21-05-2009 05:50 AM
RLC Circuit Java Applet syxxpac316 Java Applets 6 13-05-2009 09:26 PM
[SOLVED] merging java classes madkris Object Oriented Programming 11 16-03-2009 01:02 PM
FileNotFoundError when working with xml files in windows ochieng File I/O & Other I/O Streams 1 14-11-2008 11:56 AM
Calculator-applet AnithaBabu1 Java Applets 0 16-08-2008 04:42 AM


100 most searched terms
Search Cloud
2 dimensional arraylist java 2d arraylist java actionlistener actionlistener in java addactionlistener addactionlistener java convert double to integer java double format java double to integer in java double to integer java drag en drop programmeren java eclipse shortcut keys exception in thread "awt-eventqueue-0" java.lang.outofmemoryerror: java heap space exception in thread "main" java.lang.nullpointerexception exception in thread "main" java.lang.outofmemoryerror: java heap space format double in java format double java get mouse position java java 2d arraylist java actionlistener java double format java double formatting java double to int java double to integer java format double java forum java forums java get mouse position java list to map java mouse position java programming forum java programming forums java programming practice problems java send keystrokes to another application java two dimensional arraylist java.io.ioexception: premature eof java.lang.classformaterror: truncated class file java.lang.outofmemoryerror: java heap space java.util.arraylist jbutton action jbutton actionlistener jtextarea font jtextfield font size jxl.read.biff.biffexception: unable to recognize ole stream programming mutators and generics smack api two dimensional arraylist two dimensional arraylist java unable to sendviapost to url what is the smallest positive number that is evenly divisible by all of the numbers from 1 to 20?

All times are GMT. The time now is 01:56 AM.
Powered by vBulletin® Copyright ©2000-2009, Jelsoft Enterprises Ltd.