?? mainframe.java~2~
字號:
package snake;import java.awt.*;import java.awt.event.*;import javax.swing.*;import com.borland.jbcl.layout.*;/** * <p>Title: 貪食蛇游戲</p> * <p>Description: </p> * <p>Copyright: Copyright (c) 2005</p> * <p>Company: </p> * @author zsb * @version 1.0 */public class MainFrame extends JFrame { private JPanel contentPane; private BorderLayout borderLayout1 = new BorderLayout(); private JToolBar jToolBar1 = new JToolBar(); private JButton jButton1 = new JButton(); private JButton jButton2 = new JButton(); private JButton jButton3 = new JButton(); private JButton jButton4 = new JButton(); private JButton jButton9 = new JButton(); private JPanel jPanel1 = new JPanel(); private JToolBar jToolBar2 = new JToolBar(); private JButton jButton5 = new JButton(); private JPanel jPanel_PlayArea = new JPanel(); private final int COLS = 15; private final int ROWS = 13; private GridLayout gridLayout1 = new GridLayout(ROWS,COLS,0,0); private JPanel[][] playBlocks ; private XYLayout xYLayout1 = new XYLayout(); //Construct the frame public MainFrame() { enableEvents(AWTEvent.WINDOW_EVENT_MASK); try { jbInit(); } catch(Exception e) { e.printStackTrace(); } } //Component initialization private void jbInit() throws Exception { //setIconImage(Toolkit.getDefaultToolkit().createImage(MainFrame.class.getResource("[Your Icon]"))); contentPane = (JPanel) this.getContentPane(); contentPane.setLayout(borderLayout1); this.setSize(new Dimension(536, 401)); this.setTitle("貪食蛇"); jButton1.setFont(new java.awt.Font("DialogInput", 0, 12)); jButton1.setMaximumSize(new Dimension(79, 39)); jButton1.setMinimumSize(new Dimension(79, 39)); jButton1.setPreferredSize(new Dimension(79, 39)); jButton1.setText("開始"); jButton2.setText("暫停"); jButton2.setPreferredSize(new Dimension(79, 39)); jButton2.setMinimumSize(new Dimension(79, 39)); jButton2.setMaximumSize(new Dimension(79, 39)); jButton2.setFont(new java.awt.Font("DialogInput", 0, 12)); jButton3.setText("退出"); jButton3.setPreferredSize(new Dimension(79, 39)); jButton3.setMinimumSize(new Dimension(79, 39)); jButton3.setMaximumSize(new Dimension(79, 39)); jButton3.setFont(new java.awt.Font("DialogInput", 0, 12)); jButton4.setText("幫助"); jButton4.setPreferredSize(new Dimension(79, 39)); jButton4.setMinimumSize(new Dimension(79, 39)); jButton4.setMaximumSize(new Dimension(79, 39)); jButton4.setFont(new java.awt.Font("DialogInput", 0, 12)); jButton9.setText("jButton1"); jButton9.setPreferredSize(new Dimension(79, 39)); jButton9.setMinimumSize(new Dimension(79, 39)); jButton9.setMaximumSize(new Dimension(79, 39)); jButton9.setFont(new java.awt.Font("DialogInput", 0, 12)); jPanel1.setLayout(xYLayout1); jButton5.setText("jButton5"); jPanel_PlayArea.setLayout(gridLayout1); jPanel_PlayArea.setBorder(BorderFactory.createEtchedBorder()); contentPane.add(jToolBar1, BorderLayout.NORTH); jToolBar1.add(jButton1, null); jToolBar1.add(jButton2, null); jToolBar1.add(jButton3, null); jToolBar1.add(jButton4, null); contentPane.add(jPanel1, BorderLayout.CENTER); jPanel1.add(jToolBar2, new XYConstraints(0, 0, 524, -1)); jPanel1.add(jPanel_PlayArea, new XYConstraints(2, 33, 521, 314)); jToolBar2.add(jButton5, null); playBlocks = new JPanel[ROWS][COLS]; for(int i=0;i<ROWS;i++){ for(int j=0;j<COLS;j++){ playBlocks[i][j]=new JPanel(); playBlocks[i][j].setBackground(Color.green); //playBlocks[i][j].hide(); jPanel_PlayArea.add(playBlocks[i][j]); } } } //Overridden so we can exit when window is closed protected void processWindowEvent(WindowEvent e) { super.processWindowEvent(e); if (e.getID() == WindowEvent.WINDOW_CLOSING) { System.exit(0); } }}
?? 快捷鍵說明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -