-1

I've looked through the swing tutorials and i do not see what i'm doing wrong. Why is nothing happening when i click on the jmenuitem?

my first class:

import javax.swing.*;

public class WordProcess{

/*TODO: make program end on close
 */
public static void main(String[] args) {

    MainFrame frame = new MainFrame("Word Processor", 10000, 10000);
    }
} 

second class:

import javax.swing.*;

public class MainFrame extends JFrame {

JMenuBar menubar = new JMenuBar();


public MainFrame(String name, int x, int y) {
    setTitle(name);
    setSize(x, y);
    setVisible(true);
    setJMenuBar(menubar);



    //creates file menu and adds to menubar
    //TODO populate with JMenuItems 
    JMenu filemenu = new JMenu("file");
    filemenu.setVisible(true);
    menubar.add(filemenu);

    buttonnew buttonnew = new buttonnew("new");
    buttonnew.setVisible(true);
    filemenu.add(buttonnew);
}
}

and third class:

import javax.swing.*;
import java.awt.event.*;

public class buttonnew extends JMenuItem implements ActionListener{

buttonnew(String s) {
super();
super.setText(s);
addActionListener(this);
}

@Override
public void actionPerformed(ActionEvent ae) {
    JFrame newframe = new JFrame("sup");
}

}
Andrew Thompson
  • 168,117
  • 40
  • 217
  • 433
user2465510
  • 99
  • 10

1 Answers1

3

When the button is pressed, it will create an empty, invisible JFrame. You won't see it, since you have not called setVisible() on it, and it's tiny, as it has no contents. Otherwise, the code is fine.

Ernest Friedman-Hill
  • 80,601
  • 10
  • 150
  • 186
  • 2
    @user2465510, I would suggest you start accepting answers when you get help if you want to continue to get help in the future. – camickr Jun 09 '13 at 04:50