Having learned a little about labels, text fields, buttons, and the grid
layout manager, you can define the RatingPanel
class's constructor. That
constructor takes three arguments, which become row labels via instances of
the JLabel
class. The constructor arranges three labels, three text
fields, and six buttons in a grid layout:
import java.awt.*; import java.util.*; import java.awt.event.*; import javax.swing.*; import javax.swing.event.*; public class RatingPanel extends JPanel implements RatingPanelInterface { private int value1, value2, value3; private JTextField field1, field2, field3; private JButton button1Plus, button2Plus, button3Plus; private JButton button1Minus, button2Minus, button3Minus; RatingPanel (String x, String y, String z) { setLayout(new GridLayout (3, 4, 3, 3)); value1 = 0; value2 = 0; value3 = 0; field1 = new JTextField(String.valueOf(value1), 20); button1Plus = new JButton("+"); button1Minus = new JButton("-"); // Ditto for other text fields and buttons add(new JLabel (x)); add(field1); add(button1Minus); add(button1Plus); // Ditto for other labels, text fields, and buttons // Listeners connected here } // Setters and getters defined here // Local listener defined here } public Dimension getMinimumSize() {return new Dimension(300, 75);} public Dimension getPreferredSize() {return new Dimension(300, 75);} }