Java Forums

Main Menu
Home
Today's Posts
FAQ
Search
Contact Us

Java Network
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 12-09-2007, 08:34 PM
Member
 
Join Date: Jul 2007
Posts: 3
plodos is on a distinguished road
JMenu calling another Forms/Panels
import javax.swing.*;

import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

public class Hw extends JFrame{

JButton[] buttons = new JButton[26];

public Hw(){
Menu();
getContentPane().setLayout(new GridLayout(2,13));
JButton []buttons=new JButton[26];

for(int i=0; i<buttons.length;i++)
{
buttons[i]=new JButton(""+(char)('A'+i));
getContentPane().add(buttons[i]);
}

setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
pack();
}

public void Menu(){
// set up File menu and its menu items
JMenu fileMenu = new JMenu( "File" );
fileMenu.setMnemonic( 'F' );

// set up About... menu item
JMenuItem saveItem = new JMenuItem( "Save Game" );
saveItem.setMnemonic( 'A' );

fileMenu.add( saveItem );

// set up About... menu item
JMenuItem loadItem = new JMenuItem( "Load Game" );
loadItem.setMnemonic( 'A' );

fileMenu.add( loadItem );


// set up Exit menu item
JMenuItem exitItem = new JMenuItem( "Exit" );
exitItem.setMnemonic( 'x' );


fileMenu.add( exitItem );

// create menu bar and attach it to MenuTest window
JMenuBar bar = new JMenuBar();
setJMenuBar( bar );
bar.add( fileMenu );
///////////////////////////////////////////////////////////////
// create Format menu, its submenus and menu items
JMenu optionsMenu = new JMenu( "Options" );
optionsMenu.setMnemonic( 'F' );

// set up About... menu item
JMenuItem optionsItem = new JMenuItem( "Options" );
optionsItem.setMnemonic( 'A' );

optionsMenu.add( optionsItem );

// add Format menu to menu bar
bar.add( optionsMenu );


}

public static void main(String[] args) {
Hw win = new Hw();
win.setVisible(true);
win.setTitle("Hangman Game");
}



}

Problem is calling another Panel, if I click the Save Game , program will show me another Form/Panel ... What is the code block to call another forms?
But i dont want to use JFıleChooser , I just want to empty form

saveItem.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent e){
//what will I write??????
//
}
});
Bookmark Post in Technorati
Reply With Quote
Sponsored Links
  #2 (permalink)  
Old 12-10-2007, 06:46 AM
Member
 
Join Date: Aug 2007
Posts: 22
revathi17 is on a distinguished road
If all you need is an empty frame when clicking the save game option, here is what you can do

Code:
public class Hw extends JFrame implements ActionListener{ ...... saveItem.addActionListener(this); ................. public void actionPerformed(ActionEvent e) { JFrame newFrame = new JFrame("Empty frame"); newFrame.setDefaultCloseOperation(JFrame.HIDE_ON_CLOSE); newFrame.setSize(200,200); newFrame.setVisible(true); } }
This would open an empty frame when you click the save game.you can do whatever you want in it.
Hope I got your question correct...

-R
Bookmark Post in Technorati
Reply With Quote
  #3 (permalink)  
Old 12-10-2007, 09:02 AM
Senior Member
 
Join Date: Nov 2007
Location: Newport, WA
Posts: 141
staykovmarin is on a distinguished road
Or even easier, you can call a small dialog to appear using JOptionPane:
How to Make Dialogs (The Java™ Tutorials > Creating a GUI with JFC/Swing > Using Swing Components)

Code:
JOptionPane.showMessageDialog(prentFrame, "TextMsg");
There are also options for adding more buttons and such.

Last edited by staykovmarin : 12-10-2007 at 09:05 AM.
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


Similar Threads
Thread Thread Starter Forum Replies Last Post
Buttons to show new panels Lehane_9 AWT / Swing 1 03-06-2008 05:22 PM
Selecting a JMenu paints over the JPanel on the content pane Swingset AWT / Swing 3 01-06-2008 12:13 AM
Working with Labels on Panels. vargihate AWT / Swing 2 01-04-2008 05:09 AM
Need a tutorial for Studying about Panels ramachandran New To Java 1 10-25-2007 10:05 AM
JMenu and JRadioButtonMenuItem doron70 AWT / Swing 3 07-18-2007 07:13 PM


All times are GMT +3. The time now is 08:00 PM.


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