From 3d6476b1ef4819d895cc56b7eecb92296a51063d Mon Sep 17 00:00:00 2001 From: Kristian Knarvik Date: Wed, 19 Aug 2020 15:19:00 +0200 Subject: [PATCH] Makes Console extend KeyAdapter to remove empty methods. Also improves comments --- .../userinterface/Console.java | 33 ++++++++++--------- 1 file changed, 17 insertions(+), 16 deletions(-) diff --git a/src/main/java/net/knarcraft/minecraftserverlauncher/userinterface/Console.java b/src/main/java/net/knarcraft/minecraftserverlauncher/userinterface/Console.java index a420e03..f987eba 100644 --- a/src/main/java/net/knarcraft/minecraftserverlauncher/userinterface/Console.java +++ b/src/main/java/net/knarcraft/minecraftserverlauncher/userinterface/Console.java @@ -5,23 +5,21 @@ import net.knarcraft.minecraftserverlauncher.Main; import javax.swing.*; import javax.swing.text.DefaultCaret; import java.awt.*; -import java.awt.event.ActionEvent; -import java.awt.event.ActionListener; -import java.awt.event.KeyEvent; -import java.awt.event.KeyListener; +import java.awt.event.*; import java.util.ArrayList; import static javax.swing.text.DefaultCaret.ALWAYS_UPDATE; /** * Acts as a single writable/readable tab - * Has a box for user input, and a textArea for server output. + * + *

Has a box for user input, and a textArea for server output.

* * @author Kristian Knarvik * @version 1.0.0 * @since 1.0.0 */ -public class Console implements ActionListener, KeyListener { +public class Console extends KeyAdapter implements ActionListener, KeyListener { private final JTextField textInput; private final JTextArea textOutput; private final String name; @@ -29,6 +27,12 @@ public class Console implements ActionListener, KeyListener { private final ArrayList commands = new ArrayList<>(); private int commandIndex; + /** + * Instantiates a new console + * + * @param tab

The tabbed pane used for displaying the console

+ * @param name

The name of the console tab

+ */ Console(JTabbedPane tab, String name) { this.name = name; panel = new JPanel(); @@ -48,14 +52,19 @@ public class Console implements ActionListener, KeyListener { textInput.addKeyListener(this); } + /** + * Gets the JPanel this console is drawn on + * + * @return

The JPanel this console is drawn on

+ */ public JPanel getPanel() { return this.panel; } /** - * Prints a string to the textArea. + * Prints a string to the console's output * - * @param text The text to print + * @param text

The string to print

*/ public void output(String text) { this.textOutput.setText(this.textOutput.getText() + "\n" + text); @@ -86,14 +95,6 @@ public class Console implements ActionListener, KeyListener { } } - @Override - public void keyReleased(KeyEvent e) { - } - - @Override - public void keyTyped(KeyEvent e) { - } - /** * Shows the previously executed command in the input field *