Skip to content
Home
Post Code
Jass (Warcraft III)
Wurst
GUI (Warcraft III)
Galaxy (StarCraft II)
GUI (StarCraft II)
C++
Java
Delphi
Text
Search Code
Compare Code
Uploads
Draw
Create New Drawing
View Drawings
Graph
Log in
<pre class="jasscode">import java<span class="style_symbol">.</span>awt<span class="style_symbol">.</span>event<span class="style_symbol">.</span>ActionEvent; import java<span class="style_symbol">.</span>awt<span class="style_symbol">.</span>event<span class="style_symbol">.</span>ActionListener; import javax<span class="style_symbol">.</span>swing<span class="style_symbol">.</span>JButton; import javax<span class="style_symbol">.</span>swing<span class="style_symbol">.</span>JFrame; import javax<span class="style_symbol">.</span>swing<span class="style_symbol">.</span>JOptionPane; @SuppressWarnings(<span class="style_string">"serial"</span>) <span class="style_keyword">public</span> <span class="style_keyword">class</span> Menu extends JFrame implements ActionListener<span class="style_comment">{</span> <span class="style_comment"></span> <span class="style_comment"> // JButtons fürs Menü erstellen</span> <span class="style_comment"> private JButton start;</span> <span class="style_comment"> private JButton settings;</span> <span class="style_comment"> private JButton info;</span> <span class="style_comment"> private JButton exit;</span> <span class="style_comment"></span> <span class="style_comment"></span> <span class="style_comment"> // Konstruktor für die Menu-GUI</span> <span class="style_comment"> private Menu(String title) {</span> <span class="style_comment"></span> <span class="style_comment"> super(title);</span> <span class="style_comment"></span> <span class="style_comment"> start = new JButton("Spiel starten");</span> <span class="style_comment"> start.setBounds(120,40,160,40);</span> <span class="style_comment"> start.addActionListener(this);</span> <span class="style_comment"> add(start);</span> <span class="style_comment"></span> <span class="style_comment"> settings = new JButton("Einstellungen");</span> <span class="style_comment"> settings.setBounds(120,120,160,40);</span> <span class="style_comment"> settings.addActionListener(this);</span> <span class="style_comment"> add(settings);</span> <span class="style_comment"></span> <span class="style_comment"> info = new JButton("Credits");</span> <span class="style_comment"> info.setBounds(120,200,160,40);</span> <span class="style_comment"> info.addActionListener(this);</span> <span class="style_comment"> add(info);</span> <span class="style_comment"></span> <span class="style_comment"> exit = new JButton("Ende");</span> <span class="style_comment"> exit.setBounds(120,280,160,40);</span> <span class="style_comment"> exit.addActionListener(this);</span> <span class="style_comment"> add(exit);</span> <span class="style_comment"> }</span> <span class="style_comment">// Actionevents für die JButtons</span> <span class="style_keyword">public</span> void actionPerformed(ActionEvent e) <span class="style_comment">{</span> <span class="style_comment"></span> <span class="style_comment"> if (e.getSource() == start) {</span> <span class="style_comment"> new Window();</span> <span class="style_comment"> }</span> <span class="style_keyword">else</span> <span class="style_keyword">if</span> (e<span class="style_symbol">.</span>getSource() <span class="style_symbol">=</span><span class="style_symbol">=</span> info) <span class="style_comment">{</span> <span class="style_comment"> Object[] options = {"OK"}</span>; JOptionPane<span class="style_symbol">.</span>showOptionDialog(null<span class="style_symbol">,</span> <span class="style_string">"Programmiert von Chris :)"</span><span class="style_symbol">,</span> <span class="style_string">"Information"</span><span class="style_symbol">,</span> JOptionPane<span class="style_symbol">.</span>DEFAULT_OPTION<span class="style_symbol">,</span> JOptionPane<span class="style_symbol">.</span>PLAIN_MESSAGE<span class="style_symbol">,</span> null<span class="style_symbol">,</span> options<span class="style_symbol">,</span> options<span class="style_symbol">[</span><span class="style_int">0</span><span class="style_symbol">]</span>); } <span class="style_keyword">else</span> <span class="style_keyword">if</span> (e<span class="style_symbol">.</span>getSource() <span class="style_symbol">=</span><span class="style_symbol">=</span> settings) <span class="style_comment">{</span> <span class="style_comment"> // settings();</span> <span class="style_comment"> }</span> <span class="style_keyword">else</span> <span class="style_keyword">if</span> (e<span class="style_symbol">.</span>getSource() <span class="style_symbol">=</span><span class="style_symbol">=</span> exit) <span class="style_comment">{</span> <span class="style_comment"> System.exit(0);</span> <span class="style_comment"> }</span> } <span class="style_comment">// Platzhalter für den Menüpunkt: Einstellungen</span> <span class="style_comment">//</span> <span class="style_comment">// public static void settings() {</span> <span class="style_comment">//</span> <span class="style_comment">// }</span> <span class="style_comment">// Startpunkt fürs Programm: Ruft den Konstruktor auf und passt ihn an</span> <span class="style_keyword">public</span> static void main(<span class="style_type">String</span><span class="style_symbol">[</span><span class="style_symbol">]</span> args) <span class="style_comment">{</span> <span class="style_comment"></span> <span class="style_comment"> Menu menu = new Menu("Menü");</span> <span class="style_comment"> menu.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);</span> <span class="style_comment"> menu.setSize(400,400);</span> <span class="style_comment"> menu.setLocationRelativeTo(null);</span> <span class="style_comment"> menu.setLayout(null);</span> <span class="style_comment"> menu.setVisible(true);</span> <span class="style_comment"> }</span> } </pre>
select language
jass
java
> delphi
C++
php
GSL
galaxy
visualBasic
wurst
Text
Markdown
select style
default
bbcode - default
Jasscraft
> jasscraft html
visual
lightweight
lightweightNr
goto line:
Compare with:
text copy window
edit this code
post new code
import java.awt.event.ActionEvent; import java.awt.event.ActionListener; import javax.swing.JButton; import javax.swing.JFrame; import javax.swing.JOptionPane; @SuppressWarnings("serial") public class Menu extends JFrame implements ActionListener{ // JButtons fürs Menü erstellen private JButton start; private JButton settings; private JButton info; private JButton exit; // Konstruktor für die Menu-GUI private Menu(String title) { super(title); start = new JButton("Spiel starten"); start.setBounds(120,40,160,40); start.addActionListener(this); add(start); settings = new JButton("Einstellungen"); settings.setBounds(120,120,160,40); settings.addActionListener(this); add(settings); info = new JButton("Credits"); info.setBounds(120,200,160,40); info.addActionListener(this); add(info); exit = new JButton("Ende"); exit.setBounds(120,280,160,40); exit.addActionListener(this); add(exit); } // Actionevents für die JButtons public void actionPerformed(ActionEvent e) { if (e.getSource() == start) { new Window(); } else if (e.getSource() == info) { Object[] options = {"OK"}; JOptionPane.showOptionDialog(null, "Programmiert von Chris :)", "Information", JOptionPane.DEFAULT_OPTION, JOptionPane.PLAIN_MESSAGE, null, options, options[0]); } else if (e.getSource() == settings) { // settings(); } else if (e.getSource() == exit) { System.exit(0); } } // Platzhalter für den Menüpunkt: Einstellungen // // public static void settings() { // // } // Startpunkt fürs Programm: Ruft den Konstruktor auf und passt ihn an public static void main(String[] args) { Menu menu = new Menu("Menü"); menu.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); menu.setSize(400,400); menu.setLocationRelativeTo(null); menu.setLayout(null); menu.setVisible(true); } }