Java Class 图

Java Class Diagram

我正在学习为 java 设计 class 图,这是我的第一次尝试。可以请告诉我一下吗

这是源代码

public class DiceRoll1 extends JFrame implements ActionListener {

    private JTextField txtNotation;

    private JButton btRoll, btShuffle;

    private List<Integer> dealtCard;
    private History history;
    public DiceRoll1() {
        initComponents();

        dealtCard = new ArrayList<>();
      history = new History();

    }

    public void initComponents() {
        //designing the userform
        setSize(400, 500);
        setLayout(new FlowLayout());
        setTitle("Dice Roll");
        txtNotation = new JTextField("2d6");
        btRoll = new JButton("Roll");
        btShuffle = new JButton("Shuffle");

        txtNotation.setColumns(20);



        getContentPane().add(txtNotation);
        getContentPane().add(btRoll);
        getContentPane().add(btShuffle);

        btRoll.addActionListener(this);
        btShuffle.addActionListener(this);

    }

    /**
     * @param args the command line arguments
     */
    public static void main(String[] args) {

        new DiceRoll().setVisible(true);

    }

    @Override
    public void actionPerformed(ActionEvent e) {
        JButton source = (JButton) e.getSource();

        if (source.equals(btRoll)) {

        } else if (source.equals(btShuffle)) {

        }
    }

    public void displayOutput(String message) {
        System.out.println(message);
    }
}

这是我使用 Visio 专业版绘制的图表:

我认为你的图表还不错,但我注意到了一些事情。

  1. 你的属性在代码和图中的名称不一致
  2. 您不需要添加 Java 内置 classes 除非您扩展或实现它们,或者您被告知这样做是因为它们不必要地夸大了您的图表
  3. 您应该在 JFrame 和您的 class
  4. 之间绘制一个继承连接
  5. 您应该在 ActionListeners 和您的 class
  6. 之间建立一个实现连接

Connection types of an UML-Class-Diagram