1. import java.awt.event.ActionEvent;
  2. import java.awt.event.ActionListener;
  3. import javax.swing.JButton;
  4. import javax.swing.JFrame;
  5. import javax.swing.JOptionPane;
  6. @SuppressWarnings( "serial" )
  7. public class Menu extends JFrame implements ActionListener{
  8. // JButtons fürs Menü erstellen
  9. private JButton start;
  10. private JButton settings;
  11. private JButton info;
  12. private JButton exit;
  13. // Konstruktor für die Menu-GUI
  14. private Menu( String title ) {
  15. super( title ) ;
  16. start = new JButton( "Spiel starten" ) ;
  17. start.setBounds( 120, 40, 160, 40 ) ;
  18. start.addActionListener( this ) ;
  19. add( start ) ;
  20. settings = new JButton( "Einstellungen" ) ;
  21. settings.setBounds( 120, 120, 160, 40 ) ;
  22. settings.addActionListener( this ) ;
  23. add( settings ) ;
  24. info = new JButton( "Credits" ) ;
  25. info.setBounds( 120, 200, 160, 40 ) ;
  26. info.addActionListener( this ) ;
  27. add( info ) ;
  28. exit = new JButton( "Ende" ) ;
  29. exit.setBounds( 120, 280, 160, 40 ) ;
  30. exit.addActionListener( this ) ;
  31. add( exit ) ;
  32. }
  33. // Actionevents für die JButtons
  34. public void actionPerformed( ActionEvent e ) {
  35. if( e.getSource() == start ) {
  36. new Window() ;
  37. }
  38. else if( e.getSource() == info ) {
  39. Object[] options = {"OK"};
  40. JOptionPane.showOptionDialog( null, "Programmiert von Chris : ) ", "Information", JOptionPane.DEFAULT_OPTION, JOptionPane.PLAIN_MESSAGE, null, options, options[ 0 ] ) ;
  41. }
  42. else if( e.getSource() == settings ) {
  43. // settings();
  44. }
  45. else if( e.getSource() == exit ) {
  46. System.exit( 0 ) ;
  47. }
  48. }
  49. // Platzhalter für den Menüpunkt: Einstellungen
  50. //
  51. // public static void settings() {
  52. //
  53. // }
  54. // Startpunkt fürs Programm: Ruft den Konstruktor auf und passt ihn an
  55. public static void main( String[] args ) {
  56. Menu menu = new Menu( "Menü" ) ;
  57. menu.setDefaultCloseOperation( JFrame.EXIT_ON_CLOSE ) ;
  58. menu.setSize( 400, 400 ) ;
  59. menu.setLocationRelativeTo( null ) ;
  60. menu.setLayout( null ) ;
  61. menu.setVisible( true ) ;
  62. }
  63. }

Diesen Code in Original-Formatierung anzeigen
goto line:
Compare with:
text copy window edit this code post new code