Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 03-01-2009, 11:32 PM
Member
 
Join Date: Mar 2009
Posts: 13
Rep Power: 0
billbo123 is on a distinguished road
Default New button in new frame
my program is compiling and running but when i click on my button named "New frame" i need the new frame to open with the third button on the interface, but at the moment it is opening in the original frame, any help in getting the 'Third' button to the new frame would be greatly appreciated.

Code:
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;

public class GuiDemo4 extends JFrame
{

  private JButton myFirstButton;
  private JButton button3;
  private JButton myFourthbutton;

  public GuiDemo4()
  {

    super("My First Button Program");

    myFirstButton = new JButton("FIRST");
    myFirstButton.setFont(new Font("Arial", Font.BOLD, 18));
    myFirstButton.setBackground(Color.red);


    button3 = new JButton("Original Frame");
    button3.setFont(new Font ("Arial", Font.BOLD, 18));
    button3.setBackground(Color.green);

    Container c = getContentPane();
    FlowLayout fl = new FlowLayout(FlowLayout.LEFT);
    c.setLayout(fl);

    c.add(myFirstButton);
    c.add(button3);

    ButtonHandler handler = new ButtonHandler();
    myFirstButton.addActionListener(handler);
    button3.addActionListener(handler);



    setSize(400, 300);
    setVisible(true);
  }

  public static void main(String[] args)
  {

    GuiDemo4 f = new GuiDemo4();

    f.addWindowListener(new WindowAdapter()
    {
      public void windowClosing(WindowEvent e)
      {
        System.out.println("Exit via windowClosing.");
        System.exit(0);
      }
    });
  }

  private class ButtonHandler implements ActionListener


  {
    public void actionPerformed(ActionEvent e)
    {
      if (e.getSource() == myFirstButton)
      {
        System.out.println("Left Button has been pressed.");
      }


      if (e.getSource() == button3)
      {
        JFrame frame = new JFrame("New Frame");
        pack();

       frame.setDefaultCloseOperation(JDialog.EXIT_ON_CLOSE);
	   frame.setLocationRelativeTo(null);
	   frame.setVisible(true);





			Container c = getContentPane();
		    FlowLayout f1 = new FlowLayout(FlowLayout.LEFT);
		    c.setLayout(f1);


		myFourthbutton = new JButton ("Third");
		myFourthbutton.setFont(myFirstButton.getFont());
    	myFourthbutton.setBackground(new Color(180, 100, 255));



		c.add(myFourthbutton);	}


		ButtonHandler handler = new ButtonHandler();
		myFourthbutton.addActionListener(handler);



		    setSize(400, 300);
		    setVisible(true);

		}


	}

}
Bookmark Post in Technorati
Reply With Quote
Reply

Bookmarks

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
GUI new frame billbo123 New To Java 15 03-02-2009 05:24 AM
frame arunkumarinfo NetBeans 0 02-07-2009 11:26 AM
how disable the display of close button on the frame kalanidhi New To Java 6 11-19-2008 10:51 AM
Frame to other Frame Aswq New To Java 2 07-19-2008 05:27 PM
Frame Query Daniel AWT / Swing 1 07-05-2007 07:27 PM


All times are GMT +2. The time now is 08:56 AM.



VBulletin, Copyright ©2000 - 2010, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO ©2009, Crawlability, Inc.
Copyright ©2006 - 2007, www.java-forums.org