4 Replies - 565 Views - Last Post: 23 April 2012 - 09:34 AM Rate Topic: -----

#1 richybaby  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 5
  • Joined: 23-April 12

Annoying newbie question...

Posted 23 April 2012 - 06:59 AM

I am pretty new to Java, having developed with Delphi for the past while. I started out in Oracle many years ago.

I am playing around with Eclipse and am trying to get to grips with the basics of Java. I feel I learn better (if at all) by example and would love to find some useful Java examples. In particular, I'd like to be able to open and close multiple Java forms, one after the other from within one controller:

open form1;
open form2;
open form3;
the end of the application

I know I am being pretty specific here and don't expect someone to write the code, but I feel that if I could achieve this it would be a leapstart to a lot of the other things I am going to need to learn to write the apps I want to write.

Anyway, any help is gratefully received.

best wishes

Richard

Is This A Good Question/Topic? 0
  • +

Replies To: Annoying newbie question...

#2 Ryano121  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 1461
  • View blog
  • Posts: 3,289
  • Joined: 30-January 11

Re: Annoying newbie question...

Posted 23 April 2012 - 07:08 AM

In what conditions are the two other frames shown? When the user presses a button?

So in frame1 you can create an instance of frame2. Then when its meant to show the second from, hide the first and setVisible(true) the second. Same goes for two and three. In three you can then exit the application on the condition instead of opening a new frame.

Alternatively you could go for a JTabbedPane. Depends on your circumstances.
Good luck!

This post has been edited by Ryano121: 23 April 2012 - 07:09 AM

Was This Post Helpful? 0
  • +
  • -

#3 aklo  Icon User is offline

  • D.I.C Head

Reputation: 18
  • View blog
  • Posts: 233
  • Joined: 23-January 09

Re: Annoying newbie question...

Posted 23 April 2012 - 07:08 AM

Happens that I'm also "learning" java gui so took me 5mins to copy from my code after removing some extra stuff

import java.awt.BorderLayout;
import javax.swing.JFrame;
import javax.swing.JMenu;
import javax.swing.JMenuBar;
import javax.swing.JMenuItem;
import javax.swing.JPanel;


public class aaa extends JFrame {

	public aaa() {
		
		//Main Panel
		JPanel panel = new JPanel();	

		
		//Menu bar		
		JMenuBar menuBar = new JMenuBar();
		JMenuItem item1;
		JMenuItem item2;
		JMenu menu = new JMenu("File");

		panel.add(menuBar, BorderLayout.NORTH);
		item1 = new JMenuItem("New");
		menu.add(item1);
		item2 = new JMenuItem("Exit");
		menu.add(item2);
		menuBar.add(menu);	
		//End menu bar

		BorderLayout frameLayout = new BorderLayout();
		this.setVisible(true);
		this.setDefaultCloseOperation(EXIT_ON_CLOSE);
		this.setSize(500, 500);
		this.setContentPane(panel);
		this.setLayout(frameLayout);
		
		panel.add(menuBar, BorderLayout.NORTH);
	}
	
	public static void main(String[] args){
		new aaa();
	}
	
}
		



trust me there is so much more to learn ...lots of layout , how to use them together to get the look you want...phew

Edit: oops I misunderstood your question so you need example of something that can hide/show new frame...that I have no idea but i'll just keep this gui code here haha.

This post has been edited by aklo: 23 April 2012 - 07:13 AM

Was This Post Helpful? 0
  • +
  • -

#4 richybaby  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 5
  • Joined: 23-April 12

Re: Annoying newbie question...

Posted 23 April 2012 - 07:13 AM

Wow amazing! 2 replies already!!!!

I want to show a Welcome Screen, then a screen that asks for the persons name and their specialist subject (from a bunch of checkboxes). Two players enter their information and then the last screen is the game screen which shows about 20 trivia questions.

So, One welcome screen. Two instances of a prefs screen. Then a final gameplay screen going round and round x times until the questions are all answered or whatever else has happened.

best wishes

R
Was This Post Helpful? 0
  • +
  • -

#5 pbl  Icon User is offline

  • There is nothing you can't do with a JTable
  • member icon

Reputation: 8378
  • View blog
  • Posts: 31,956
  • Joined: 06-March 08

Re: Annoying newbie question...

Posted 23 April 2012 - 09:34 AM

Here is an alternative

http://docs.oracle.c...CardLayout.html
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1