📄 bubblet.java
字号:
import java.awt.*;import java.awt.event.*;import javax.swing.*;/** * Representation of the game interface for Bubblet. */public class Bubblet extends JFrame { // Interface variables private static final int NROWS = 10; private static final int NCOLS = 7; private static final int NCOLORS = 5; private static final int VOFFSET = 30; private static final int VOFFSET2 = 10; private static final int HOFFSET = 10; private static final int WSIZE = 20, HSIZE = 20; private final JButton newGame; private final JLabel score1; private final JLabel score2; private final JLabel group1; private final JLabel group2; private int scoreVal; private int groupVal; private Container pane; private Surface surface; /** Construct the frame */ public Bubblet () { super("Bubblet 0.7"); pane = this.getContentPane(); pane.setLayout(new BorderLayout()); JPanel controls = new JPanel(); newGame = new JButton("New Game"); controls.add(newGame); scoreVal = 0; score1 = new JLabel("Score: "); controls.add(score1); score2 = new JLabel("0 "); // score2.setFont(new Font("SansSerif", Font.BOLD, 10)); controls.add(score2); groupVal = 0; group1 = new JLabel("Group: "); controls.add(group1); group2 = new JLabel("0 "); // group2.setFont(new Font("SansSerif", Font.BOLD, 10)); controls.add(group2); newGame.addActionListener(new ActionListener () { public void actionPerformed (ActionEvent e) { restart(); }}); pane.add(controls, "North"); surface = new Surface(NROWS, NCOLS, NCOLORS, this); surface.setPreferredSize(new Dimension(NROWS*WSIZE+2*HOFFSET, VOFFSET+NCOLS*HSIZE+VOFFSET2)); // surface.setPreferredSize(new Dimension(NROWS*WSIZE, NCOLS*HSIZE)); JPanel tmpPanel = new JPanel(new FlowLayout()); tmpPanel.add(surface); pane.add(tmpPanel, "Center"); this.setSize(NROWS*WSIZE+2*HOFFSET, NCOLS*HSIZE+VOFFSET2); this.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE); this.pack(); this.setVisible(true); } public void setGroup (int n) { group2.setText(n + ""); } public void setScore (int n) { score2.setText(n + ""); } public void restart () { scoreVal = 0; setScore(scoreVal); groupVal = 0; setGroup(groupVal); remove(surface); surface = new Surface(NROWS, NCOLS, NCOLORS, this); surface.setPreferredSize(new Dimension(NROWS*WSIZE+2*HOFFSET, VOFFSET+NCOLS*HSIZE+VOFFSET2)); JPanel tmpPanel = new JPanel(new FlowLayout()); tmpPanel.add(surface); pane.add(tmpPanel, "Center"); validate(); repaint(); } /* Test class methods */ public static void main (String[] args) { Bubblet game = new Bubblet(); }}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -