Search code examples
javaumlclass-diagram

Java Class Diagram


I'm learning to design a class diagram for java and this is my first attempt. 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:

enter image description here


Solution

  • 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
    3. You should draw an inheritance connection between JFrame and your class
    4. You should draw a realization connection between ActionListeners and your class

    Connection types of an UML-Class-Diagram