我修复了代码并更新了,但现在我不知道在哪里放置构造函数:
private JPanel panel;
public RollButton(JPanel panel){
this.panel = panel;
}
Run Code Online (Sandbox Code Playgroud)
我查看了一些放置构造函数的示例,看起来它放在我的RollButton类周围,但我试图将它放在多个地方并且在多个地方,但我似乎无法做到正确.
码:
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import javax.swing.border.*;
import java.util.Random;
public class DiceRollGUI {
public static JLabel label;
public static JFrame frame;
public static JPanel panel;
private static JButton button;
private static JButton buttonRollDie;
private static JLabel diceRoll;
public static void main (String[] args) {
JFrame frame = new JFrame("Dice Roll GUI");
JPanel contentPanel = new JPanel(new GridLayout(0,2,5,10));
button = new JButton("Roll");;
frame.setVisible(true);
frame.setResizable(false);
frame.setSize(750, …Run Code Online (Sandbox Code Playgroud)