I'm new in Java so I really need help. I want my JMenu
open to open file using file chooser only when I clicked it but what happening is that it does not appear.
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
import java.io.*;
public class Myprog extends JFrame {
JMenuBar hard= new JMenuBar();
JMenu file = new JMenu("FILE");
JMenu open = new JMenu("Open");
JMenu histo = new JMenu("History");
JMenuItem exit = new JMenuItem("Exit");
JMenu view = new JMenu("VIEW");
JMenu descript = new JMenu("Description");
JMenu spm = new JMenu("Specs/Model/Version");
JMenu extra = new JMenu("EXTRAS");
JMenu trans = new JMenu("Transaction");
JMenu calcu = new JMenu("Calculator");
JMenu qoutes = new JMenu("Quotes");
JMenuItem game = new JMenuItem("Games");
JMenu about = new JMenu("ABOUT");
JMenuItem java = new JMenuItem("JAVA");
JMenuItem sirjet = new JMenuItem("References");
JMenuItem akoto = new JMenuItem("MyProfile");
JMenuItem mouse = new JMenuItem("Mouse");
JMenuItem cpu = new JMenuItem("CPU");
JMenuItem cam = new JMenuItem("Camera");
JMenuItem key = new JMenuItem("Keyboard");
JMenuItem mem = new JMenuItem("Memory");
JMenuItem mic = new JMenuItem("Microphone");
JMenuItem print= new JMenuItem("Printer");
JMenuItem scan = new JMenuItem("Scanner");
JMenuItem speak = new JMenuItem("Speaker");
JMenuItem mon = new JMenuItem("Monitor");
JFileChooser choosyAko = new JFileChooser(".");
JLabel direct = new JLabel(" ");
JLabel filename = new JLabel(" ");
public Myprog(){
super("My Program(Hardware)");
setVisible(true);
setBounds(250,250,700,700);
setBackground(Color.GREEN);
direct.setFont(new Font("Serif", Font.BOLD | Font.ITALIC, 36));
setLayout(new FlowLayout());
setDefaultCloseOperation(EXIT_ON_CLOSE);
setJMenuBar(hard);
hard.add(file);
file.setMnemonic('F');
file.add(open);
open.setMnemonic('O');
file.add(histo);
histo.setMnemonic('H');
histo.add(cam);
histo.add(cpu);
histo.add(key);
histo.add(mem);
histo.add(mic);
histo.add(mon);
histo.add(mouse);
histo.add(print);
histo.add(scan);
histo.add(speak);
file.add(exit);
exit.setMnemonic('X');
hard.add(view);
view.setMnemonic('V');
view.add(descript);
descript.setMnemonic('D');
view.add(spm);
spm.setMnemonic('S');
hard.add(extra);
extra.setMnemonic('E');
extra.add(trans);
trans.setMnemonic('T');
extra.add(calcu);
calcu.setMnemonic('C');
extra.add(qoutes);
qoutes.setMnemonic('Q');
extra.add(game);
game.setMnemonic('G');
hard.add(about);
about.setMnemonic('B');
about.add(java);
java.setMnemonic('J');
about.add(sirjet);
sirjet.setMnemonic('N');
about.add(akoto);
add(direct, BorderLayout.NORTH);
add(filename, BorderLayout.SOUTH);
add(choosyAko,BorderLayout.CENTER);
open.addActionListener(new open());
exit.addActionListener(new exit());
}
class open implements ActionListener
{
public void actionPerformed(ActionEvent e)
{
JFileChooser choosyAko = new JFileChooser(".");
JLabel direct = new JLabel(" ");
JLabel filename = new JLabel(" ");
choosyAko.setControlButtonsAreShown(false);
}
}
class exit implements ActionListener
{
public void actionPerformed(ActionEvent e)
{
System.exit(0);
}
}
public static void main(String []args)
{
Myprog frame = new Myprog();
}
}