mirror of
				https://github.com/lov3b/Schack.git
				synced 2025-10-31 13:20:21 +01:00 
			
		
		
		
	Inital meny med local IP dialog
This commit is contained in:
		| @@ -1,7 +1,18 @@ | |||||||
| package schack; | package schack; | ||||||
|  |  | ||||||
| import java.awt.Dimension; | import java.awt.Dimension; | ||||||
|  | import java.awt.event.ActionEvent; | ||||||
|  | import java.awt.event.ActionListener; | ||||||
|  | import java.net.InetAddress; | ||||||
|  | import java.net.UnknownHostException; | ||||||
|  | import java.util.logging.Level; | ||||||
|  | import java.util.logging.Logger; | ||||||
| import javax.swing.JFrame; | import javax.swing.JFrame; | ||||||
|  | import javax.swing.JMenu; | ||||||
|  | import javax.swing.JMenuBar; | ||||||
|  | import javax.swing.JMenuItem; | ||||||
|  | import javax.swing.JOptionPane; | ||||||
|  | import javax.swing.JPopupMenu; | ||||||
|  |  | ||||||
| /** | /** | ||||||
|  * |  * | ||||||
| @@ -16,9 +27,46 @@ public class Schack extends JFrame { | |||||||
|         setAlwaysOnTop(true); |         setAlwaysOnTop(true); | ||||||
|         setResizable(false); |         setResizable(false); | ||||||
|         setContentPane(new Board()); |         setContentPane(new Board()); | ||||||
|  |  | ||||||
|  |         // Create menu         | ||||||
|  |         JMenuBar menuBar = new JMenuBar(); | ||||||
|  |         JMenu gameMenu = new JMenu("Game"); | ||||||
|  |         JMenu connectMenu = new JMenu("Connect"); | ||||||
|  |         JMenuItem connectToOpponent = new JMenuItem("Connect to opponent"); | ||||||
|  |         JMenuItem showLocalIP = new JMenuItem("Show IP"); | ||||||
|  |         JMenuItem askForRemi = new JMenuItem("Ask for remi"); | ||||||
|  |         JMenuItem surrender = new JMenuItem("Surrender"); | ||||||
|  |  | ||||||
|  |         // Actions | ||||||
|  |         connectToOpponent.addActionListener((ActionEvent ae) -> { | ||||||
|  |             System.out.println("Connecting (TODO)"); | ||||||
|  |         }); | ||||||
|  |         showLocalIP.addActionListener((ActionEvent ae) -> { | ||||||
|  |             try { | ||||||
|  |                 String localIp = InetAddress.getLocalHost().toString(); | ||||||
|  |                 JOptionPane.showMessageDialog(this, "Local IP: " + localIp); | ||||||
|  |             } catch (UnknownHostException ex) { | ||||||
|  |                 JOptionPane.showMessageDialog(this, "Could not get local IP"); | ||||||
|  |             } | ||||||
|  |         }); | ||||||
|  |         askForRemi.addActionListener((ActionEvent ae) -> { | ||||||
|  |             System.out.println("I BEG FOR LE MERCY! (TODO)"); | ||||||
|  |         }); | ||||||
|  |         surrender.addActionListener((ActionEvent ae) -> { | ||||||
|  |             System.out.println("I'M FRENCH! (TODO)"); | ||||||
|  |         }); | ||||||
|  |  | ||||||
|  |         // Add the menu stuff | ||||||
|  |         setJMenuBar(menuBar); | ||||||
|  |         menuBar.add(gameMenu); | ||||||
|  |         menuBar.add(connectMenu); | ||||||
|  |         connectMenu.add(connectToOpponent); | ||||||
|  |         connectMenu.add(showLocalIP); | ||||||
|  |         gameMenu.add(askForRemi); | ||||||
|  |         gameMenu.add(surrender); | ||||||
|         pack(); |         pack(); | ||||||
|         setVisible(true); |  | ||||||
|         setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); |         setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); | ||||||
|  |         setVisible(true); | ||||||
|  |  | ||||||
|     } |     } | ||||||
|  |  | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user
	 lov3b
					lov3b