📄 main.java
字号:
import java.awt.*;import java.awt.event.*;import javax.swing.*;/** * * @author abigael */public class Main extends JFrame implements ActionListener, Runnable { GamePanel gamePanel; static JButton button; static JLabel labelRound; static JLabel labelTotalCash; int screenWidth = (int) Toolkit.getDefaultToolkit().getScreenSize().getWidth(); int screenHeight = (int) Toolkit.getDefaultToolkit().getScreenSize().getHeight(); MainMenu mm = new MainMenu(this); int mmWidth = 250; int mmHeight = 300; public Main() { add(mm); setDefaultCloseOperation(EXIT_ON_CLOSE); setSize(mmWidth, mmHeight); setLocation(screenWidth / 2 - getWidth() / 2, screenHeight / 2 - getHeight() / 2); setVisible(true); setTitle("WHEEL OF FORTUNE"); } /** * @param args the command line arguments */ public static void main(String[] args) { new Main(); } /* * ActionPerformed for the button, starts a new Thread and * diables the button */ public void actionPerformed(ActionEvent e) { Thread t = new Thread(this); t.start(); spun(true); } /* * Used for diabling and enabling the button * Called by GamePanel after spinning the wheel */ public static void spun(boolean a) { if (a) { button.setEnabled(false); } else { button.setEnabled(true); } } /* * run method for the Thread */ public void run() { gamePanel.spinTheWheel(); } public void startGame(int round, int initialCash) { JPanel gp = new JPanel(new BorderLayout()); labelRound = new JLabel("Round: " + round); button = new JButton("Spin"); labelTotalCash = new JLabel("Total Cash: " + initialCash); gamePanel = new GamePanel(this, round, initialCash); button.addActionListener(this); setLayout(new BorderLayout()); JPanel northPanel = new JPanel(new GridLayout(1, 2)); northPanel.add(labelTotalCash); northPanel.add(labelRound); gp.add(northPanel, BorderLayout.NORTH); gp.add(gamePanel, BorderLayout.CENTER); gp.add(button, BorderLayout.SOUTH); setContentPane(gp); pack(); setSize(398, 450); setLocation(screenWidth / 2 - getWidth() / 2, screenHeight / 2 - getHeight() / 2); } public void loadMainMenu() { setContentPane(mm); pack(); setSize(mmWidth, mmHeight); }}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -