Makes Console extend KeyAdapter to remove empty methods. Also improves comments

This commit is contained in:
Kristian Knarvik 2020-08-19 15:19:00 +02:00
parent 070f87222b
commit 3d6476b1ef

View File

@ -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.
*
* <p>Has a box for user input, and a textArea for server output.</p>
*
* @author Kristian Knarvik <kristian.knarvik@knett.no>
* @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<String> commands = new ArrayList<>();
private int commandIndex;
/**
* Instantiates a new console
*
* @param tab <p>The tabbed pane used for displaying the console</p>
* @param name <p>The name of the console tab</p>
*/
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 <p>The JPanel this console is drawn on</p>
*/
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 <p>The string to print</p>
*/
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
*