所以我自学Java并遇到了一些障碍。对于其中一项练习,这是我无法理解的说明。任何有关解释的帮助将不胜感激。这是我遇到问题的部分的尝试。
import java.awt.Dimension;
import java.awt.GridLayout;
import javax.swing.JButton;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
import javax.swing.JTextArea;
public class ButtonPanel extends JPanel {
public ButtonPanel(JButton[] buttons, JTextArea textArea) {
//TODO: Create a sub-panel with a 4 row, 3 column GridLayout
setLayout(new GridLayout(4,3)); //Layout of subPanel1
JButton b1 = new JButton ("A");
JButton b2 = new JButton ("B");
JButton b3 = new JButton ("C");
JButton b4 = new JButton ("1");
JButton b5 = new JButton ("2");
JButton b6 = new JButton ("3");
JButton b7 = new JButton ("X");
JButton b8 = new JButton ("Y");
JButton b9 = new JButton ("Z");
add(b1);
add(b2);
add(b3);
add(b4);
add(b4);
add(b5);
//TODO: Populate the grid with buttons
//TODO: Add the grid panel to this panel
//TODO: Create a JScrollPane containing textArea
JButton cr = new JButton();
//TODO: Set the preferred size of the scroll pane to 80x120
setPreferredSize (new Dimension(80, 120));
//TODO: Add the scroll pane to this panel
}
}