Java Development
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
 
User Name:
Password:
Remember me
 
Go Back   Dev Articles Community ForumsProgrammingJava Development

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Display Modes
 
Unread Dev Articles Community Forums Sponsor:
  #1  
Old December 14th, 2006, 03:46 AM
itel itel is offline
Contributing User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Nov 2006
Posts: 33 itel User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 17 h 7 m 9 sec
Reputation Power: 3
Help Java-Swing

I m new in java and I want to do the menu and when I click File->Open I want that FileChooser() will open. Here is code. Pleasse help if anyone know what must I do. Thanks a lot.


import java.awt.*;
import java.awt.event.*;
import java.util.*;
import javax.swing.*;
import java.io.*;
import javax.swing.JPanel;

public class Voipgraphic extends JFrame {

public Voipgraphic () {
super ("Analyze");

JMenuBar meni = new JMenuBar ();
JButton gumb = new JButton ("Gumb");

JMenu file = new JMenu("File");
JMenu statistic = new JMenu ("Statistic");
JMenu help = new JMenu ("Help");

//open
JMenuItem open = new JMenuItem ("Open");
open.addActionListener (new ActionListener () {
public void actionPerformed (ActionEvent e) {
JFileChooser c = new JFileChooser();
}
});
file.add (open);
file.add ("Save as...");
//exit
JMenuItem exit = new JMenuItem ("Exit");
exit.addActionListener (new ActionListener () {
public void actionPerformed (ActionEvent e) {
System.exit (0);
}
});
file.addSeparator();
file.add(exit);

statistic.add ("Show statistic");
help.add ("Help");
JMenuItem license = new JMenuItem("License",
new ImageIcon("java_logo.gif"));
license.setHorizontalTextPosition(JMenuItem.RIGHT) ;
license.setAccelerator(KeyStroke.getKeyStroke('L', Toolkit.getDefaultToolkit().getMenuShortcutKeyMask ()));

help.add (license);

meni.add (file);
meni.add (statistic);
meni.add (help);
setJMenuBar (meni);
}

public static void main (String args[]) throws Exception {
JFrame window = new Voipgraphic();
window.setDefaultCloseOperation (JFrame.EXIT_ON_CLOSE);
BorderLayout.CENTER);
window.setSize(600, 500);
window.setVisible (true);
}
}

Reply With Quote
  #2  
Old December 17th, 2006, 12:31 AM
daniel_g daniel_g is offline
Contributing User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Mar 2006
Posts: 60 daniel_g User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 21 h 3 m 50 sec
Reputation Power: 3
First off, remove or comment(to fix later) this:
Code:
//BorderLayout.CENTER);

Then you wont get any compile errors.

Second, put comments on your code so is easier for us to read. We wont be able to help you if we don't understand what's going on. It would also help to use code brackets to enclose your code.

Third, you could easily have your answer if you knew how to get arround the java documentation. For example, if you wanted to learn about FileChooser(), then all you need to do is go to www.google.com, and type "java FileChooser()".
The first links you will see will point to: http://java.sun.com/javase/6/docs/a...ileChooser.html

And you will also find the java tutorials: http://java.sun.com/docs/books/tuto...ilechooser.html
If you read it carefully, you should be able to figure out that the only thing you are mising is:
Code:
int returnVal = c.showOpenDialog(Voipgraphic.this);

Now I'm not going to tell you where to put it, but if you do read the tutorial, then you will know where(hint: look at the sample codes).

Reply With Quote
Reply

Viewing: Dev Articles Community ForumsProgrammingJava Development > Help Java-Swing


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


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
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 4 hosted by Hostway
Stay green...Green IT