|
|
|||||||||
|
|||||||||
|
|||||||||
| |
|||
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Display Modes |
|
#1
|
|||
|
|||
|
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); } } |
|
#2
|
|||
|
|||
|
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). |
![]() |
| Viewing: Dev Articles Community Forums > Programming > Java Development > Help Java-Swing |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|