/* * TestAWT - Simple program to test AWT code. * Copyright (c) 2004 James Damour. All rights reserved. * * This program is free software; you can redistribute it and/or modify it * under the terms of the GNU General Public License as published by the Free * Software Foundation; either version 2 of the License, or (at your option) * any later version. * * This program is distributed in the hope that it will be useful, but * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License * for more details. */ /* Author: James Damour (Suvarov454) Test AWT use. */ import java.awt.*; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; import java.awt.event.WindowAdapter; import java.awt.event.WindowEvent; public class TestAWT { public static void main (String[] args) { Frame frame = new Frame("Test AWT"); frame.addWindowListener(new WindowAdapter() { public void windowClosing(WindowEvent e) { System.exit(0); } }); frame.setBackground(SystemColor.menu); frame.setForeground(SystemColor.menuText); Button hostB, connectB, botB, editB, scenB, loadB, quitB; Panel panTitle = new Panel(); ActionListener closer = new ActionListener() { public void actionPerformed (ActionEvent evt) { System.exit(0); } }; hostB = new Button("Host a New Game..."); hostB.addActionListener (closer); scenB = new Button("Host a Scenario..."); scenB.addActionListener (closer); loadB = new Button("Host a Saved Game..."); loadB.addActionListener (closer); connectB = new Button("Connect to a Game..."); connectB.addActionListener (closer); botB = new Button("Connect as a Bot..."); botB.addActionListener (closer); editB = new Button("Map Editor"); editB.addActionListener (closer); quitB = new Button("Quit"); quitB.addActionListener (closer); // layout GridBagLayout gridbag = new GridBagLayout(); GridBagConstraints c = new GridBagConstraints(); frame.setLayout(gridbag); c.fill = GridBagConstraints.BOTH; c.anchor = GridBagConstraints.WEST; c.weightx = 0.0; c.weighty = 0.0; c.insets = new Insets(4, 4, 1, 1); c.gridwidth = GridBagConstraints.REMAINDER; c.ipadx = 10; c.ipady = 5; c.gridx = 0; c.gridwidth = 1; c.gridheight = 7; addBag(frame, panTitle, gridbag, c); c.gridwidth = GridBagConstraints.REMAINDER; c.gridx = 1; c.gridheight = 1; c.fill = GridBagConstraints.HORIZONTAL; c.gridy = 0; addBag(frame, hostB, gridbag, c); c.gridy++; addBag(frame, loadB, gridbag, c); c.gridy++; addBag(frame, scenB, gridbag, c); c.gridy++; addBag(frame, connectB, gridbag, c); c.gridy++; addBag(frame, botB, gridbag, c); c.gridy++; addBag(frame, editB, gridbag, c); c.gridy++; addBag(frame, quitB, gridbag, c); frame.validate(); // set visible on middle of screen Dimension screenSize = frame.getToolkit().getScreenSize(); frame.pack(); frame.setLocation( screenSize.width / 2 - frame.getSize().width / 2, screenSize.height / 2 - frame.getSize().height / 2); // Show the window. frame.setVisible(true); } private static void addBag(Frame frame, Component comp, GridBagLayout gridbag, GridBagConstraints c) { gridbag.setConstraints(comp, c); frame.add(comp); } }