Go Back   CodingForums.com > :: Server side development > Java and JSP

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 08-22-2008, 10:20 PM   PM User | #1
Inquisit
New Coder

 
Join Date: Aug 2008
Posts: 14
Thanks: 2
Thanked 0 Times in 0 Posts
Inquisit is an unknown quantity at this point
Question How to call a j-frame from a main frame (frame to frame)

Question to the experts
I use both Netbeans 5.5 and Forte for java 4

how to call a j-frame from a main j-frame (frame to frame)



i have created a main J-frame and 8 sub j-frames in one class (package)
i find this as a conservative method and time efficient rather than individual java files for these are not internal frames but are regular frames

ive tried some methods to solve this either i get an error the whole window dissapears or nothing happens

in the Main J-frame there are buttons that you click to go to the next J-frame the same way "a-href" in HTML works in the same window and back

Lets say my project is a Finance project


i.e

Main J-Frame *****Contents

Menu:- ( TVM) ----------> button // opens TVM J-frame (J-Frame 2)

(Compound interest)------> button //Opens Compound Interest j-frame 3
etc

when you click the ---------> (TVM) button
it should open the TVM J-frame (J-frame in the same window) frame 2
this also applies when you click----> (Compound interest) opens J-frame 3
while the 2nd or 3rd frame is shown the main frame should be invisible
either this.dispose or HIDE_ON_CLOSE

while using action performed or mouse clicked to be assigned to a button
(action listeners) you get a message

i.e
public void actionPerformed(ActionEvent e)

//add your handling code here

now what code is to be placed here in order to achieve this
calling a j-frame (frame to frame)

Your help on this one

thanks
Inquisit is offline   Reply With Quote
Old 08-28-2008, 02:28 PM   PM User | #2
ess
Regular Coder

 
Join Date: Oct 2006
Location: United Kingdom
Posts: 865
Thanks: 7
Thanked 29 Times in 28 Posts
ess will become famous soon enough
Here is an example which you can expand upon

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

public class 
OpenFrames {
    public static 
void main(String[] args) {
        
JFrame first = new JFrame("First Frame");
        
first.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        
first.getContentPane().setLayout(new FlowLayout());
        
JButton b1 = new JButton("Open First");
        
JButton b2 = new JButton("Open Second");
        
first.getContentPane().add(b1);
        
first.getContentPane().add(b2);
        
b1.addActionListener(new ActionListener() {
                public 
void actionPerformed(ActionEvent e) {
                    new 
SecondFrame();
        }});
        
b2.addActionListener(new ActionListener() {
                public 
void actionPerformed(ActionEvent e) {
                    new 
ThridFrame();
        }});
        
first.setSize(450200);
        
first.setVisible(true);
    } 
//-- ends class method main
//-- ends class definition

class SecondFrame extends JFrame {
    public 
SecondFrame() {
        
setTitle("Second Frame");
        
setDefaultCloseOperation(JFrame.HIDE_ON_CLOSE);
        
getContentPane().setLayout(new FlowLayout());
        
getContentPane().add(new JLabel("THIS IS THE 2nd JFRAME"));
        
setSize(200200);
        
setVisible(true);
    } 
//-- ends constructor
    
//-- ends SecondFrame

class ThridFrame extends JFrame {
    public 
ThridFrame() {
        
setTitle("Third Frame");
        
setDefaultCloseOperation(JFrame.HIDE_ON_CLOSE);
        
getContentPane().setLayout(new FlowLayout());
        
getContentPane().add(new JLabel("THIS IS THE 3rd JFRAME"));
        
setSize(200200);
        
setVisible(true);
    } 
//-- ends constructor
//-- ends firstFrame 
Copy the above code and save in the file "OpenFrames.java"...then compile and run.

Hope this helps

Cheers
~E
ess is offline   Reply With Quote
Old 08-28-2008, 09:16 PM   PM User | #3
Inquisit
New Coder

 
Join Date: Aug 2008
Posts: 14
Thanks: 2
Thanked 0 Times in 0 Posts
Inquisit is an unknown quantity at this point
Bigg Thanks you just alleviated my stress in a therapeutic way
i should work my way round this once again thanks

i hope this works
Inquisit is offline   Reply With Quote
Reply

Bookmarks

Tags
j-frame to frame

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

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

Forum Jump


All times are GMT +1. The time now is 01:45 PM.


Advertisement
Log in to turn off these ads.