簡體   English   中英

Java類圖

[英]Java Class Diagram

我正在學習為Java設計類圖,這是我的第一次嘗試。 你能告訴我是否可以。

這是源代碼

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 Professional繪制的圖表:

在此處輸入圖片說明

我認為您的圖表還不錯,但是我注意到了一些事情。

  1. 代碼和圖中的屬性名稱不一致
  2. 您不需要添加Java內置類,除非您擴展或實現它們,否則會被告知這樣做是因為它們不必要地使您的圖表膨脹
  3. 您應該在JFrame和您的類之間繪制一個繼承連接
  4. 您應該在ActionListeners和您的類之間繪制一個實現連接

UML類圖的連接類型

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM