Java Forums

Main Menu
Home
Today's Posts
FAQ
Search
Contact Us

Java Network
Linux Archive
Java Tips
Java Tips Blog

Sponsored Links





Welcome to the Java Forums.

You are currently viewing our boards as a guest which gives you limited access to view most discussions and access our other features. By joining our free community, you will:

  • have access to post topics
  • communicate privately with other members (PM)
  • not see advertisements between posts
  • have the possibility to earn one of our surprises if you are an active member
  • access many other special features that will be introduced later.

Registration is fast, simple and absolutely free so please, join our community today!

If you have any problems with the registration process or your account login, please contact us.

Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 07-04-2007, 05:22 PM
Senior Member
 
Join Date: Jun 2007
Posts: 111
Eric is on a distinguished road
Help with GUI Java
Hi, I am trying to make a simple java program which acts as a shop register.
The user is able to click on a cd and select to buy it.
I am having major problems learning java and cannot find anyway for forms to navigate from one to another. Is it even possible?
Are there any programs which work as a GUI creation as a tool which may help me?

Thanks.
Eric
Bookmark Post in Technorati
Reply With Quote
Sponsored Links
  #2 (permalink)  
Old 07-04-2007, 05:24 PM
Senior Member
 
Join Date: Jun 2007
Posts: 114
Albert is on a distinguished road
Have you written any code?

Also, is this a Java application or JSP (Java Server Pages)?
You said forms, so I just want to clarify.

I think Netbeans (the IDE) has a feature where you can do a sort of "GUI Creation" but I'm unsure, as I'm typically an Eclipse only user.

Greetings
Albert
Bookmark Post in Technorati
Reply With Quote
  #3 (permalink)  
Old 07-04-2007, 05:58 PM
Member
 
Join Date: Jun 2007
Posts: 92
Daniel is on a distinguished road
Hello, I have created a quick example that demonstrates how you could create more than one JFrame in the same class.

Depending on your particular requirements...it might be better to create a class for each frame though...as that would make it easier when performing maintenance etc.

Code:
import java.awt.*; import java.awt.event.*; import javax.swing.*; public class MyApp { private JFrame first, // first Jframe instance second, // second Jframe instance third; // third Jframe instance private JButton openFirst, // opens second jframe openSecond; // open third jframe private final int WIDTH = 400; // first frame's width private final int HEIGHT = 200; // second frame's height public MyApp() { // create and initilize the first frame...first being the main one this.first = new JFrame( "First Frame" ); this.first.setDefaultCloseOperation( JFrame.EXIT_ON_CLOSE ); // initialize components this.initComponents(); // place the first frame in the center of the screen this.first.setLocation( ( Toolkit.getDefaultToolkit().getScreenSize().width - WIDTH ) / 2, ( Toolkit.getDefaultToolkit().getScreenSize().height - HEIGHT ) / 2 ); // set frame size this.first.setSize( WIDTH, HEIGHT ); this.first.setVisible( true ); // make it visible } //-- ends class constructor private void initComponents() { // this method takes care of initializing and // adding comonents to the first frame Container pane = this.first.getContentPane(); FlowLayout layout = new FlowLayout(); pane.setLayout( layout ); // initialize the first button to open the first frame this.openFirst = new JButton( "Open First Dialog" ); this.openFirst.addActionListener( new ActionListener() { public void actionPerformed( ActionEvent event ){ openFirst_clicked( event ); }}); pane.add( this.openFirst ); this.openSecond = new JButton( "Open Second Dialog" ); this.openSecond.addActionListener( new ActionListener() { public void actionPerformed( ActionEvent event ) { openSecond_clicked( event ); }}); pane.add( this.openSecond ); } //-- ends instance method initComponents private void openFirst_clicked( ActionEvent event ) { this.second = new JFrame( "Second Frame" ); this.second.setDefaultCloseOperation( JFrame.DISPOSE_ON_CLOSE ); this.second.getContentPane().setLayout( new FlowLayout() ); this.second.getContentPane().add( new JLabel("Hello from second frame" ) ); this.second.setSize( 250, 100 ); this.second.setVisible( true ); } //-- ends instance method openFirst_clicked private void openSecond_clicked( ActionEvent event ) { this.third = new JFrame( "Third Frame" ); this.third.setDefaultCloseOperation( JFrame.DISPOSE_ON_CLOSE ); this.third.getContentPane().setLayout( new FlowLayout() ); this.third.getContentPane().add( new JLabel("Hello from third frame" ) ); this.third.setSize( 250, 100 ); this.third.setVisible( true ); } //-- ends instance method openFirst_clicked public static void main( String [] args ) { SwingUtilities.invokeLater( new Runnable() { public void run() { new MyApp(); }}); } //-- ends class method main } //-- ends class definition
Greetings
Daniel
Bookmark Post in Technorati
Reply With Quote
Sponsored Links
Reply


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

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



All times are GMT +3. The time now is 12:20 PM.


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