From 476910abd64760223f3e4143866134e49facf487 Mon Sep 17 00:00:00 2001 From: =?utf8?q?J=C3=A9r=C3=B4me=20Benoit?= Date: Fri, 11 Jan 2019 17:23:34 +0100 Subject: [PATCH] Finish the SizeView by using a JSpinner. MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit Signed-off-by: Jérôme Benoit --- src/FirstnameView.java | 2 +- src/MainWindowsView.java | 2 +- src/Size.java | 12 ++++++++++-- src/SizeView.java | 10 ++++++++++ 4 files changed, 22 insertions(+), 4 deletions(-) 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() { -- 2.34.1