Results 1 to 2 of 2

Thread: Calling a frame

  1. #1
    Proshitness is offline Member
    Join Date
    Oct 2011
    Posts
    28
    Rep Power
    0

    Default Calling a frame

    i created a couple of frames and i want to use JButton that when i press one button it will change to a diffrent frame.
    here is the code:
    PHP Code:
    import java.awt.*;
    import javax.swing.*;
    import java.awt.event.*;
    
    
    public class MainMenuGui extends JFrame{
        private JButton button1;
        private JButton button2;
        private JButton button3;
        private Screen s;
        JLabel lmw = new JLabel();
       
        public MainMenuGui(){
            super("The Tribal Council");
            setLayout(new FlowLayout());
            button1 = new JButton("Play");
            ButtonHandler handler = new ButtonHandler();
            button2.addActionListener(handler);
            button2 = new JButton("Option");
            button3 = new JButton("FullScreen Mode");
            button1.setPreferredSize(new Dimension(220, 40));
            add(button1);
            add(button2);
            add(button3);
    
            
        }
        
        private class ChooseSaveGui extends JFrame{
            public ChooseSaveGui(){
               
            }
        }
        
        private class Settings extends JFrame {
            public Settings(){
                   Setting s = new Setting();
                   s.Audiorun();
            }
        }
        
        private class ButtonHandler implements ActionListener{
                    ChangeRes CH = new ChangeRes();
            public void actionPreformed(ActionEvent e){
            if(e.getSource() == button1){
               new ChooseSaveGui();
            }
            if(e.getSource() == button2){
              new Settings(); 
            }
            if(e.getSource() == button3){
              CH.runthis();
            }
          }
    
            @Override
            public void actionPerformed(ActionEvent e) {
                throw new UnsupportedOperationException("Not supported yet.");
            }
        }
        
            public class Screen{
                
                private GraphicsDevice vc;
                
                public Screen(){
                       GraphicsEnvironment env = GraphicsEnvironment.getLocalGraphicsEnvironment();
                       vc = env.getDefaultScreenDevice();
               }
                
                public void setFullScreen(DisplayMode dm, JFrame window){
                    window.setUndecorated(true);
                    window.setResizable(false);
                    vc.setFullScreenWindow(window);
                    
                    if(dm  != null  && vc.isDisplayChangeSupported()){
                        try{
                            vc.setDisplayMode(dm);
                        }catch(Exception ex){}
                    }
                }
                    
                    public Window getFullScreenWindow(){
                        return vc.getFullScreenWindow();
                }
                    
                    public void restoreScreen(){
                    Window w = vc.getFullScreenWindow();
                    if(w != null){
                        w.dispose();
                    }
                    
                    vc.setFullScreenWindow(null);
                    
             }
        }
            
            private class ChangeRes extends JFrame{
              public void runthis(){  
                  DisplayMode dm = new DisplayMode(800, 600, 16, DisplayMode.REFRESH_RATE_UNKNOWN);
                  ChangeRes c = new ChangeRes();
                  c.run(dm);
            }
              
              public void run(DisplayMode dm){
                  Screen s = new Screen();
                  try{
                      s.setFullScreen(dm, this);
                      try{
                            Thread.sleep(80000);
                      }finally{
                          s.restoreScreen();
                      }
                  }catch(Exception ex){}
              }
            }
    }
    when i try to run this it gives me an error at line 20:
    PHP Code:
            button2.addActionListener(handler);
    and in the main file at line 18:
    PHP Code:
      static  MainMenuGui MMG = new MainMenuGui();
    how can i fix this?

  2. #2
    DarrylBurke's Avatar
    DarrylBurke is offline Forum Police
    Join Date
    Sep 2008
    Location
    Madgaon, Goa, India
    Posts
    11,423
    Rep Power
    20

    Default Re: Calling a frame

    it gives me an error at line 20:
    When seeking help with an error, always post the entire text of the error trace -- copy and paste, don't paraphrase.

    and in the main file
    What main file?

    I suggest you reduce your code to the barest minimum that still demonstrates the problem, and SSCCE. Then if that doesn't lead to a solution you can post the SSCCE here with specific error details.

    The code you posted isn't executable, has a lot of fluff, appears to have a Thread.sleep(...) which is possibly called on the EDT -- a big no-no; that's in addition to a NetBeans-default actionPerformed(...) and your own misspelled actionPreformed(...), and uneven indents/outdents which make the code difficult to follow.

    db
    If you're forever cleaning cobwebs, it's time to get rid of the spiders.

Similar Threads

  1. Replies: 4
    Last Post: 01-18-2011, 08:22 AM
  2. how to open one frame to another frame
    By tukadiya in forum AWT / Swing
    Replies: 1
    Last Post: 12-20-2010, 08:27 PM
  3. Java slave Frame access to its owner main frame problem
    By cagdaseckin in forum New To Java
    Replies: 0
    Last Post: 12-10-2010, 10:40 AM
  4. Replies: 7
    Last Post: 11-02-2009, 06:31 PM
  5. frame
    By arunkumarinfo in forum NetBeans
    Replies: 0
    Last Post: 02-07-2009, 10:26 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •