📄 mainpanel.java
字号:
package net.rectang;import java.awt.BorderLayout;import java.awt.Color;import java.awt.FlowLayout;import java.awt.GridLayout;import javax.swing.BorderFactory;import javax.swing.JButton;import javax.swing.JLabel;import javax.swing.JPanel;import javax.swing.border.TitledBorder;public class MainPanel extends JPanel{ private static final long serialVersionUID = 1L; private JPanel playPanel = null; private JPanel buttonPanel = null; private JPanel listPanel = null; private JButton startButton = null; private JButton endButton = null; private JPanel nextPanel = null; private JPanel levelPanel = null; private JPanel scorePanel = null; private JLabel nextLabel = null; private JPanel picturePanel = null; private JLabel levelLabel = null; private JLabel levelNumLabel = null; private JLabel scoreLabel = null; private JLabel scoreNumLabel = null; private JPanel rectangPanel = null; public MainPanel() { super(); initialize(); } private void initialize() { //this.setSize(400, 300); this.setLayout(new BorderLayout()); this.add(getPlayPanel(), BorderLayout.CENTER); this.add(getButtonPanel(), BorderLayout.SOUTH); } public JLabel getLevelNumLabel() { return levelNumLabel; } public void setLevelNumLabel(JLabel levelNumLabel) { this.levelNumLabel = levelNumLabel; } public JLabel getScoreNumLabel() { return scoreNumLabel; } public void setScoreNumLabel(JLabel scoreNumLabel) { this.scoreNumLabel = scoreNumLabel; } /** * This method initializes playPanel * * @return javax.swing.JPanel */ private JPanel getPlayPanel() { if (playPanel == null) { playPanel = new JPanel(); playPanel.setLayout(new BorderLayout()); playPanel.add(getListPanel(), BorderLayout.EAST); playPanel.add(getRectangPanel(), BorderLayout.CENTER); } return playPanel; } /** * This method initializes buttonPanel * * @return javax.swing.JPanel */ private JPanel getButtonPanel() { if (buttonPanel == null) { buttonPanel = new JPanel(); buttonPanel.setLayout(new FlowLayout()); buttonPanel.add(getStartButton(), null); buttonPanel.add(getEndButton(), null); } return buttonPanel; } /** * This method initializes listPanel * * @return javax.swing.JPanel */ private JPanel getListPanel() { if (listPanel == null) { listPanel = new JPanel(); listPanel.setLayout(new GridLayout(4, 1)); listPanel.add(getNextPanel(), null); listPanel.add(getLevelPanel(), null); listPanel.add(getScorePanel(), null); } return listPanel; } /** * This method initializes workPanel * * @return javax.swing.JPanel */ private JPanel getRectangPanel() { if (rectangPanel == null) { rectangPanel = new JPanel(); rectangPanel.setBorder(BorderFactory.createTitledBorder(null, "Rectang", TitledBorder.DEFAULT_JUSTIFICATION, TitledBorder.DEFAULT_POSITION, null, Color.blue)); } return rectangPanel; } public JPanel getRecPanel(){ return this.rectangPanel; } /** * This method initializes startButton * * @return javax.swing.JButton */ private JButton getStartButton() { if (startButton == null) { startButton = new JButton(); startButton.setText("开始"); startButton.setActionCommand(RectangActionController.NEW_GAME); startButton.addActionListener(RectangActionController.getInstance()); startButton.addKeyListener(RectangActionController.getInstance()); } return startButton; } /** * This method initializes endButton * * @return javax.swing.JButton */ private JButton getEndButton() { if (endButton == null) { endButton = new JButton(); endButton.setText("结束"); endButton.setActionCommand(RectangActionController.EXIT_GAME); endButton.addActionListener(RectangActionController.getInstance()); } return endButton; } /** * This method initializes nextPanel * * @return javax.swing.JPanel */ private JPanel getNextPanel() { if (nextPanel == null) { nextLabel = new JLabel(); nextLabel.setText("Next:"); nextPanel = new JPanel(); nextPanel.setLayout(new BorderLayout()); nextPanel.add(nextLabel, BorderLayout.NORTH); nextPanel.add(getPicturePanel(), BorderLayout.CENTER); } return nextPanel; } /** * This method initializes levelPanel * * @return javax.swing.JPanel */ private JPanel getLevelPanel() { if (levelPanel == null) { levelNumLabel = new JLabel(); levelNumLabel.setText("0"); levelLabel = new JLabel(); levelLabel.setText("Level:"); levelPanel = new JPanel(); levelPanel.setLayout(new BorderLayout()); levelPanel.add(levelLabel, BorderLayout.NORTH); levelPanel.add(levelNumLabel, BorderLayout.CENTER); } return levelPanel; } /** * This method initializes scorePanel * * @return javax.swing.JPanel */ private JPanel getScorePanel() { if (scorePanel == null) { scoreNumLabel = new JLabel(); scoreNumLabel.setText("0"); scoreLabel = new JLabel(); scoreLabel.setText("Score:"); scorePanel = new JPanel(); scorePanel.setLayout(new BorderLayout()); scorePanel.add(scoreLabel, BorderLayout.NORTH); scorePanel.add(scoreNumLabel, BorderLayout.CENTER); } return scorePanel; } /** * This method initializes picturePanel * * @return javax.swing.JPanel */ private JPanel getPicturePanel() { if (picturePanel == null) { picturePanel = new JPanel(); picturePanel.setLayout(new BorderLayout()); } return picturePanel; }}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -