象棋二(chessFrame.java)
<P>package chess;</P><P>import java.awt.Toolkit;<BR>import javax.swing.SwingUtilities;<BR>import javax.swing.UIManager;<BR>import java.awt.Dimension;</P>
<P>public class chessApp {<BR> boolean packFrame = false;</P>
<P> /**<BR> * Construct and show the application.<BR> */<BR> public chessApp() {<BR> chessFrame frame = new chessFrame();<BR> // Validate frames that have preset sizes<BR> // Pack frames that have useful preferred size info, e.g. from their layout<BR> if (packFrame) {<BR> frame.pack();<BR> } else {<BR> frame.validate();<BR> }</P>
<P> // Center the window<BR> Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();<BR> Dimension frameSize = frame.getSize();<BR> if (frameSize.height > screenSize.height) {<BR> frameSize.height = screenSize.height;<BR> }<BR> if (frameSize.width > screenSize.width) {<BR> frameSize.width = screenSize.width;<BR> }<BR> frame.setLocation((screenSize.width - frameSize.width) / 2,<BR> (screenSize.height - frameSize.height) / 2);<BR> frame.setVisible(true);<BR> }</P>
<P> /**<BR> * Application entry point.<BR> *<BR> * @param args String[]<BR> */<BR> public static void main(String[] args) {<BR> SwingUtilities.invokeLater(new Runnable() {<BR> public void run() {<BR> try {<BR> UIManager.setLookAndFeel(UIManager.<BR> getSystemLookAndFeelClassName());<BR> } catch (Exception exception) {<BR> exception.printStackTrace();<BR> }</P>
<P> new chessApp();<BR> }<BR> });<BR> }<BR>}</P>
页:
[1]
