简体   繁体   English

Java类图

[英]Java Class Diagram

I'm learning to design a class diagram for java and this is my first attempt. 我正在学习为Java设计类图,这是我的第一次尝试。 Could you please tell me if it's okay. 你能告诉我是否可以。

Here's the source code 这是源代码

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);
    }
}

Here's the diagram that i have drawn using Visio professional: 这是我使用Visio Professional绘制的图表:

在此处输入图片说明

I think that your diagram isn't too bad but I noticed some things. 我认为您的图表还不错,但是我注意到了一些事情。

  1. the names of your attributes in the code and the diagram are not consistent 代码和图中的属性名称不一致
  2. You don't need to add Java built-in classes except you extend or implement them or you're told to do so because they unnecessarily inflate your diagram 您不需要添加Java内置类,除非您扩展或实现它们,否则会被告知这样做是因为它们不必要地使您的图表膨胀
  3. You should draw an inheritance connection between JFrame and your class 您应该在JFrame和您的类之间绘制一个继承连接
  4. You should draw a realization connection between ActionListeners and your class 您应该在ActionListeners和您的类之间绘制一个实现连接

Connection types of an UML-Class-Diagram UML类图的连接类型

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM