-1

I'm doing a simple program(on a game),i am an amateur and graphics are recomended for my class X project.I want to create a button which when clicked by the user takes them to a new menu.Can anyone provide me with the layout of the programm where just by adding details such as name of the button and where it should take the user when clicked.I'm just looking for four buttons-"New Game" and "Exit",when "New Game" is clicked it should display another menu with two buttons "LimitedOvers" and "CustomOvers".i have coveredthe rest.Sorry for asking too much. Thank You.

Manu
  • 41
  • 5
  • 2
    Welcome to stackoverflow. That's not the way stackoverflow works.. provide some effort and code you've tried, what errors you have and volunteers will help you. As an advice start reading oracle swing tutorials. [Using swing](http://docs.oracle.com/javase/tutorial/uiswing/components/) – nachokk Sep 22 '13 at 03:36
  • Another tutorial: http://www.java2s.com/Tutorial/Java/0240__Swing/0100__JButton.htm – PM 77-1 Sep 22 '13 at 03:38
  • @nachokk can you please tell me about the setActionCommand and setActionListner – Manu Sep 22 '13 at 03:43
  • @Manu : Please have a look at [CardLayout](http://docs.oracle.com/javase/tutorial/uiswing/layout/card.html) for this scenario. One [working example](http://stackoverflow.com/a/9349137/1057230) for a bit help :-) – nIcE cOw Sep 22 '13 at 04:33
  • On stack over flow you must provide good that shows what you have done and what doesn't work so that for future reference someone can make use of this page. I did not mark your question down because I think you just didn't under stand how the site works. –  May 05 '14 at 14:59

1 Answers1

1

Welcome to Stack, as mentioned by @nachokk you should really at least make an attempt before looking for others to code it for you. Or even doing a Simple Google will solve most of your problems(At least that's the way it works for me).

Anyways, to answer your question You can use Swing.

JButton butt = new JButton("Click me!");
butt.addActionListener(new ActionListener() {
    public void actionPerformed(ActionEvent evt) {
        // ... called when button is clicked
    }
});
nIcE cOw
  • 24,238
  • 7
  • 47
  • 133
Brandon
  • 951
  • 4
  • 12
  • 30
  • where do i enter the name of the method that is being called?? Thank you – Manu Sep 22 '13 at 03:50
  • I have a question what about making a custom button. Lets say that you have a class that extends JButton and you want to make it a completely customized button. I know that it has to extend JButton or Componenet but what about seeing the size of the button and providing a paintComponent(...). –  May 05 '14 at 15:00