0

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

2
  • 1
    I suggest you download an evaluation copy of a professional tool, such as MagicDraw or Sparx EA. Those tools make it easy to create correct UML. If you ask a sales person, they will usually give you a longer eval period with no restrictions.
    – Jim L.
    Commented Oct 9, 2016 at 15:21
  • Thanks for the information, @JimL. Commented Oct 9, 2016 at 16:52

1 Answer 1

1

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

5
  • 2
    And instead of properties it's advisable to use role names towards the associated classes.
    – qwerty_so
    Commented Oct 9, 2016 at 15:57
  • what does role names mean? @ThomasKilian Commented Oct 9, 2016 at 17:14
  • This is a good post that explains it: stackoverflow.com/questions/16732607/…
    – magoeke
    Commented Oct 9, 2016 at 17:22
  • Instead of -btRoll:JButton write a label -btRoll near the association end at the JButton class. This is the preferred way (those are called associtaion roles). You might also add the multiplicity 1 in the same area.
    – qwerty_so
    Commented Oct 9, 2016 at 18:28
  • What type of connector should i use between awt and event , and event and ActionListener? In visual paradigm, there are so many connectors so i'm confused @ThomasKilian Commented Oct 10, 2016 at 9:50

Not the answer you're looking for? Browse other questions tagged or ask your own question.