Java Forum / GUI / November 2004
Navigation around different JFrames
Bastian Hammer - 17 Nov 2004 12:30 GMT 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 ( ); [/code]
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
Andrei Kouznetsov - 17 Nov 2004 17:40 GMT > class MainView extends JFrame > > class DefaultView extends MainView > class ManufacturerView extends MainView > class ArticlelView extends MainView <snip>
> I?ve tried CardLayout, but it seems not to work with JFrame: > [quoted text clipped - 9 lines] > > Is there another possibility to get it work? you have a bit wrong design, make your MainView extend JPanel, then you can use CardLayout.
 Signature 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
Bastian Hammer - 17 Nov 2004 18:34 GMT >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?
Andrei Kouznetsov - 17 Nov 2004 19:05 GMT > >you have a bit wrong design, make your MainView extend JPanel, then you can > >use CardLayout. [quoted text clipped - 11 lines] > > 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...
 Signature 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
Bastian Hammer - 17 Nov 2004 21:51 GMT > JFrame frame = new JFrame(); > frame.setBounds ( 0, 0, 1024, 768 ); [quoted text clipped - 7 lines] > >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?
Andrew Thompson - 17 Nov 2004 19:08 GMT > I need no Frame around my Application. Use a JWindow.
 Signature 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
Bastian Hammer - 17 Nov 2004 22:01 GMT >> 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?
Andrew Thompson - 18 Nov 2004 00:19 GMT >>> 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
 Signature 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
Bastian Hammer - 19 Nov 2004 17:14 GMT >public staic void main() { > JFrame f = new JFrame(); [quoted text clipped - 5 lines] > .... >} 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?
Andrew Thompson - 20 Nov 2004 01:00 GMT >> 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>
 Signature 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
Bastian Hammer - 20 Nov 2004 09:31 GMT >> 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. :(
Andrew Thompson - 20 Nov 2004 18:11 GMT > But I´ve got an anonym .. What's an anonym?
>..class with your example: > > JFrame f = new JFrame(); CardLayout cl = new CardLayout();
> f.getContentPane().setLayout( new CardLayout() ); f.getContentPane().setLayout( cl );
> and so, I can´t access the CardLayout. cl.show.....
> There for I´m asking. :( 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.
 Signature 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
Free MagazinesGet these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...
|
|
|