From: Jérôme Benoit Date: Fri, 11 Jan 2019 16:23:34 +0000 (+0100) Subject: Finish the SizeView by using a JSpinner. X-Git-Url: https://git.piment-noir.org/?a=commitdiff_plain;h=476910abd64760223f3e4143866134e49facf487;p=Persons_Comparator.git Finish the SizeView by using a JSpinner. Signed-off-by: Jérôme Benoit --- diff --git a/src/FirstnameView.java b/src/FirstnameView.java index b7b8568..1fb6fee 100644 --- a/src/FirstnameView.java +++ b/src/FirstnameView.java @@ -10,7 +10,7 @@ public class FirstnameView extends JPanel { this.label = new JLabel(); this.label.setText("Firstname"); this.textField = new JTextField(length); - this.textField.setText(firstnameObj.getFirstname()); + this.textField.setText(this.getFirstnameObj().getFirstname()); add(label); add(textField); } diff --git a/src/MainWindowsView.java b/src/MainWindowsView.java index 3fab8e0..406fcd5 100644 --- a/src/MainWindowsView.java +++ b/src/MainWindowsView.java @@ -34,7 +34,7 @@ public class MainWindowsView extends JFrame { /** * Create menu that support cut/copy/paste. */ - public JMenuBar createMenuBar() { + private JMenuBar createMenuBar() { JMenuItem menuItem; JMenuBar menuBar = new JMenuBar(); diff --git a/src/Size.java b/src/Size.java index 6946e5a..a0e7d78 100644 --- a/src/Size.java +++ b/src/Size.java @@ -1,6 +1,6 @@ public class Size implements Comparable { private int max = 240; - private int min = 20; + private int min = 40; private int size; Size() { @@ -10,6 +10,14 @@ public class Size implements Comparable { setSize(size); } + public int getMin() { + return min; + } + + public int getMax() { + return max; + } + public int getSize() { return size; } @@ -18,7 +26,7 @@ public class Size implements Comparable { if (validateSize(size)) { this.size = size; } else { - throw new IllegalArgumentException("Size must be between " + this.min + " and " + this.max); + throw new IllegalArgumentException("Size must be between " + this.getMin() + " and " + this.getMax()); } } diff --git a/src/SizeView.java b/src/SizeView.java index 0173615..781f397 100644 --- a/src/SizeView.java +++ b/src/SizeView.java @@ -3,12 +3,22 @@ import javax.swing.*; public class SizeView extends JPanel { private Size sizeObj; private JLabel label; + private JSpinner spinner; SizeView(Size sizeObj) { setSizeObj(sizeObj); this.label = new JLabel(); this.label.setText("Size"); + SpinnerNumberModel numberModel = new SpinnerNumberModel((this.getSizeObj().getMax() - this.getSizeObj().getMin()) / 2, + this.getSizeObj().getMin(), + this.getSizeObj().getMax(), + 1); + this.spinner = new JSpinner(numberModel); + if (this.getSizeObj().getSize() != 0) + this.spinner.setValue(this.getSizeObj().getSize()); + add(label); + add(spinner); } public Size getSizeObj() {