AppletTalk.com Forum Index AppletTalk.com
Java discussions newsgroups
 
Archives   FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

Navigation around different JFrames

 
Post new topic   Reply to topic    AppletTalk.com Forum Index -> Java GUI Toolkits
View previous topic :: View next topic  
Author Message
Bastian Hammer
Guest





PostPosted: Wed Nov 17, 2004 12:30 pm    Post subject: Navigation around different JFrames Reply with quote



Hi :)

I need to navigate around different JFrames.

I´ve got:

class MainView extends JFrame

class DefaultView extends MainView
class ManufacturerView extends MainView
class ArticlelView extends MainView

I always overwrite 1 to 3 Methods, wich are different at the SubViews
( Navigation,AricleInfo and so on )

Navigation are buttons, if a user clicks on a button, correct view
ough to be loaded.

My public static void main ( String[] args ) looks like this at the
moment:
Code:

JFrame frame = new MainView ( ControllerObject );
frame.pack ( );
frame.setSize ( 1024, 768 );
frame.setVisible ( true );
frame.show ( );


Within ControllerObject there are important values for the next view.

How could I get it work, that if I click a button, the correct next
view gets loaded?

I´ve tried CardLayout, but it seems not to work with JFrame:

JFrame frame = new MainView ( ControllerObjekt );

CardLayout ACardLayout = new CardLayout ( );
ACardLayout.addLayoutComponent( frame, "default" );

ACardLayout.show( frame, "default");

java.lang.IllegalArgumentException: wrong parent for CardLayout
First parameter has to be no JFrame, but I need JFrame :-/

Is there another possibility to get it work?

Thank you
Bye, Bastian
Back to top
Andrei Kouznetsov
Guest





PostPosted: Wed Nov 17, 2004 5:40 pm    Post subject: Re: Navigation around different JFrames Reply with quote



Quote:
class MainView extends JFrame

class DefaultView extends MainView
class ManufacturerView extends MainView
class ArticlelView extends MainView

<snip>

Quote:

I´ve tried CardLayout, but it seems not to work with JFrame:

JFrame frame = new MainView ( ControllerObjekt );

CardLayout ACardLayout = new CardLayout ( );
ACardLayout.addLayoutComponent( frame, "default" );

ACardLayout.show( frame, "default");

java.lang.IllegalArgumentException: wrong parent for CardLayout
First parameter has to be no JFrame, but I need JFrame :-/

Is there another possibility to get it work?

you have a bit wrong design, make your MainView extend JPanel, then you can
use CardLayout.

--
Andrei Kouznetsov
http://uio.dev.java.net Unified I/O for Java
http://reader.imagero.com Java image reader
http://jgui.imagero.com Java GUI components and utilities



Back to top
Bastian Hammer
Guest





PostPosted: Wed Nov 17, 2004 6:34 pm    Post subject: Re: Navigation around different JFrames Reply with quote



On Wed, 17 Nov 2004 18:40:50 +0100, "Andrei Kouznetsov"
<spam0 (AT) imagero (DOT) com.invalid> wrote:

Quote:
you have a bit wrong design, make your MainView extend JPanel, then you can
use CardLayout.

this.setBounds ( 0, 0, 1024, 768 );
this.setResizable ( false );
this.setName ( "POS" );
this.setUndecorated ( true );

this.setDefaultCloseOperation(javax.swing.JFrame.EXIT_ON_CLOSE);
this.setContentPane ( getJContentPane ( ) );
this.setVisible ( true );

I need no Frame around my Application.

I need 1024 x 768 px without any border, so I can´t use JPanel, can I?

Back to top
Andrei Kouznetsov
Guest





PostPosted: Wed Nov 17, 2004 7:05 pm    Post subject: Re: Navigation around different JFrames Reply with quote

Quote:
you have a bit wrong design, make your MainView extend JPanel, then you
can
use CardLayout.

this.setBounds ( 0, 0, 1024, 768 );
this.setResizable ( false );
this.setName ( "POS" );
this.setUndecorated ( true );

this.setDefaultCloseOperation(javax.swing.JFrame.EXIT_ON_CLOSE);
this.setContentPane ( getJContentPane ( ) );
this.setVisible ( true );

I need no Frame around my Application.

I need 1024 x 768 px without any border, so I can´t use JPanel, can I?

you can:

JFrame frame = new JFrame();
frame.setBounds ( 0, 0, 1024, 768 );
frame.setResizable ( false );
frame.setName ( "POS" );
frame.setUndecorated ( true );

frame.setDefaultCloseOperation(javax.swing.JFrame.EXIT_ON_CLOSE);
frame.setContentPane ( getJContentPane ( ) ); //whatever JContentPane is
frame.setVisible(true);

however I can't see from your code snippet nothing about your Views...

--
Andrei Kouznetsov
http://uio.dev.java.net Unified I/O for Java
http://reader.imagero.com Java image reader
http://jgui.imagero.com Java GUI components and utilities



Back to top
Andrew Thompson
Guest





PostPosted: Wed Nov 17, 2004 7:08 pm    Post subject: Re: Navigation around different JFrames Reply with quote

On Wed, 17 Nov 2004 19:34:53 +0100, Bastian Hammer wrote:

Quote:
I need no Frame around my Application.

Use a JWindow.

--
Andrew Thompson
http://www.PhySci.org/codes/ Web & IT Help
http://www.PhySci.org/ Open-source software suite
http://www.1point1C.org/ Science & Technology
http://www.LensEscapes.com/ Images that escape the mundane

Back to top
Bastian Hammer
Guest





PostPosted: Wed Nov 17, 2004 9:51 pm    Post subject: Re: Navigation around different JFrames Reply with quote

On Wed, 17 Nov 2004 20:05:18 +0100, "Andrei Kouznetsov"
<spam0 (AT) imagero (DOT) com.invalid> wrote:

Quote:
JFrame frame = new JFrame();
frame.setBounds ( 0, 0, 1024, 768 );
frame.setResizable ( false );
frame.setName ( "POS" );
frame.setUndecorated ( true );

frame.setDefaultCloseOperation(javax.swing.JFrame.EXIT_ON_CLOSE);
frame.setContentPane ( getJContentPane ( ) ); //whatever JContentPane is
frame.setVisible(true);

however I can't see from your code snippet nothing about your Views...

That´s a code snippet from my MainView extends JFrame

protected void initialize ( )
{
this.setBounds ( 0, 0, 1024, 768 );
this.setResizable ( false );
this.setName ( "POS" );
this.setUndecorated ( true );

this.setDefaultCloseOperation(javax.swing.JFrame.EXIT_ON_CLOSE);
this.setContentPane( getJContentPane ( ) );
this.setVisible ( true );
}

In my main method I got:

JFrame frame = new MainView ( ControllerObject );

And now I need something like a switch around new MainView
switch ( ControllerObject.getView )
{
case "ManufacturerView":
JFrame frame = new ManufacturerView ( .. );
break;

case "ArticleView":
..

default:
MainView ..
}

So now, how can I "run" the main method again after a click on a
button and load the correct view?

Back to top
Bastian Hammer
Guest





PostPosted: Wed Nov 17, 2004 10:01 pm    Post subject: Re: Navigation around different JFrames Reply with quote

On Wed, 17 Nov 2004 19:08:11 GMT, Andrew Thompson
<SeeMySites (AT) www (DOT) invalid> wrote:

Quote:
I need no Frame around my Application.

Use a JWindow.

They are both a subclass of java.awt.Container, so why doesn´t it
work, if I use JFrame?

Back to top
Andrew Thompson
Guest





PostPosted: Thu Nov 18, 2004 12:19 am    Post subject: Re: Navigation around different JFrames Reply with quote

On Wed, 17 Nov 2004 23:01:57 +0100, Bastian Hammer wrote:

Quote:
On Wed, 17 Nov 2004 19:08:11 GMT, Andrew Thompson
[email]SeeMySites (AT) www (DOT) inva[/email]lid> wrote:

I need no Frame around my Application.

Use a JWindow.

They are both a subclass of java.awt.Container, so why doesn´t it
work, if I use JFrame?

OK. Now that I have read back through this thread to (try and)
understand your question. I'll put it this way.

// make MainView a JPanel
class MainView extends JPanel

// so these three are also panels
class DefaultView extends MainView
class ManufacturerView extends MainView
class ArticlelView extends MainView

public staic void main() {
JFrame f = new JFrame();
f.getContentPane().setLayout( new CardLayout() );

....
f.getContentPane().add( "Mainview", new MainView() );
f.getContentPane().add( "DefaultView", new DefaultView() );
....
}

Now, if that does not sort your problem, you are going to need to

a) Be more precise. "it doesn't work" is a comment more likely to
get the response "flog it with a whip, it may just be lazy" than
any useful suggestions.

b) Post a *complete* short code example to give us a better feel
for what you're doing and perhaps what you are trying to achieve.
<http://www.physci.org/codes/sscce.jsp>

HTH

--
Andrew Thompson
http://www.PhySci.org/codes/ Web & IT Help
http://www.PhySci.org/ Open-source software suite
http://www.1point1C.org/ Science & Technology
http://www.LensEscapes.com/ Images that escape the mundane

Back to top
Bastian Hammer
Guest





PostPosted: Fri Nov 19, 2004 5:14 pm    Post subject: Re: Navigation around different JFrames Reply with quote

On Thu, 18 Nov 2004 00:19:38 GMT, Andrew Thompson
<SeeMySites (AT) www (DOT) invalid> wrote:

Quote:
public staic void main() {
JFrame f = new JFrame();
f.getContentPane().setLayout( new CardLayout() );

....
f.getContentPane().add( "Mainview", new MainView() );
f.getContentPane().add( "DefaultView", new DefaultView() );
....
}

How can I access the different Views?

I haven´t got Attributes for MainView, DefaultView, and so on in my
JFrame, so how can I show another View?
At the moment, only MainView gets displayed.

And wehere and what should I assign witch object, to provide, that the
user gets another view, when he clicks on a button?

Buttons are always a field of a view:

public class ManufacturerView extends MainView
{

private JButton jButtonM1 = null;
private JButton jButtonM2 = null;
...
}

Should JFrame be assigned to MainView´s constructor?

Hope you can answer my question, or do you need more code?

Back to top
Andrew Thompson
Guest





PostPosted: Sat Nov 20, 2004 1:00 am    Post subject: Re: Navigation around different JFrames Reply with quote

On Fri, 19 Nov 2004 18:14:24 +0100, Bastian Hammer wrote:

Quote:
On Thu, 18 Nov 2004 00:19:38 GMT, Andrew Thompson
[email]SeeMySites (AT) www (DOT) inva[/email]lid> wrote:

f.getContentPane().setLayout( new CardLayout() );
...
How can I access the different Views?

Questions like these are often answered by consulting the documentation.
<http://java.sun.com/j2se/1.5.0/docs/api/java/awt/CardLayout.html>

--
Andrew Thompson
http://www.PhySci.org/codes/ Web & IT Help
http://www.PhySci.org/ Open-source software suite
http://www.1point1C.org/ Science & Technology
http://www.LensEscapes.com/ Images that escape the mundane

Back to top
Bastian Hammer
Guest





PostPosted: Sat Nov 20, 2004 9:31 am    Post subject: Re: Navigation around different JFrames Reply with quote

On Sat, 20 Nov 2004 01:00:49 GMT, Andrew Thompson
<SeeMySites (AT) www (DOT) invalid> wrote:

Quote:
How can I access the different Views?

Questions like these are often answered by consulting the documentation.
http://java.sun.com/j2se/1.5.0/docs/api/java/awt/CardLayout.html


I´ve read the documentation, an if I my CardLayout would be an
attribute of frame, it would be no problem to sey:

frame.ACardLayout.show ( "MainView" );

But I´ve got an anonym class with your example:

JFrame f = new JFrame();
f.getContentPane().setLayout( new CardLayout() );

and so, I can´t access the CardLayout.

There for I´m asking. :(

Back to top
Andrew Thompson
Guest





PostPosted: Sat Nov 20, 2004 6:11 pm    Post subject: Re: Navigation around different JFrames Reply with quote

On Sat, 20 Nov 2004 10:31:18 +0100, Bastian Hammer wrote:

Quote:
But I´ve got an anonym ..

What's an anonym?

Quote:
..class with your example:

JFrame f = new JFrame();

CardLayout cl = new CardLayout();

Quote:
f.getContentPane().setLayout( new CardLayout() );

f.getContentPane().setLayout( cl );

Quote:
and so, I can´t access the CardLayout.

cl.show.....

Quote:
There for I´m asking. Sad

Keep a reference to it, see above. And if you cannot figure
it from there, naybe you'd better post to c.l.j.help.

--
Andrew Thompson
http://www.PhySci.org/codes/ Web & IT Help
http://www.PhySci.org/ Open-source software suite
http://www.1point1C.org/ Science & Technology
http://www.LensEscapes.com/ Images that escape the mundane

Back to top
Display posts from previous:   
Post new topic   Reply to topic    AppletTalk.com Forum Index -> Java GUI Toolkits All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2006 phpBB Group
SEO toolkit © 2004-2006 webmedic.