Class GTerm

java.lang.Object
java.awt.Component
java.awt.Container
java.awt.Window
java.awt.Frame
javax.swing.JFrame
GTerm

public final class GTerm
This Version:
2021.03.01

GTerm allows you to create a GUI application using System.out.println-like statements.

Version History:

2020.02.29: Original version

2020.03.06: Added \n support for print and println. Added clear.

2020.03.10: Added textField, textArea, setTextInField, getTextInField, addButton support, repaint in clear.

2020.03.15: Does not exit on close; added close, addPasswordField, addList, addElementToList, removeElementFromList, getSelectedElementFromList

2020.03.21: Fixed non-removal in removeElementFromList, addList and addTextArea now has auto-scrollbars

2020.06.01: Lists of String type

2020.07.06: getElementFromList returns value of consistent type. Added getSelectedElementIndexFromList, setFilePath

2020.08.25: Lists replaced with tables (\t formats data in to columns. Supports optional header row.). Added addTable, addRowToTable, clearRowsOfTable, getSelectedRowIndexFromTable, getSelectedRowFromTable. Exceptions thrown from invoked supplied methods are more readable. Added addImageIcon(BufferedImage), showErrorDialog(String), showWarningDialog(String). Title of showMessageDialog(String) says "information" instead of "message" (to match icon). addPasswordField, addTextArea and addTextField now return the text field index.

2021.03.01: Images added in a terminal fashion. addTable uses background set by setBackgroundColor.

Author:
Gayan Wijesinghe
  • Constructor Summary

    Constructors 
    Constructor Description
    GTerm​(int width, int height)
    GTerm constructor taking a width and a height suggestion for the window
  • Method Summary

    Modifier and Type Method Description
    void addButton​(String buttonText, Object handlingObject, String handlingMethodName)
    Adds a button.
    void addImageIcon​(String imageFilename)
    Adds an image at current x,y coordinates.
    int addPasswordField​(String defaultPassword, int widthInPixels)
    Adds a single-line password text field.
    int addRowToTable​(int indexOfTable, String rowData)
    Adds a row to an existing table.
    int addTable​(int width, int height, String columnNames)
    Adds a list-like table.
    int addTextArea​(String defaultText, int widthInPixels, int heightInPixels)
    Adds a multi-line, word-wrapping-capable, auto-scrolling text area.
    int addTextField​(String defaultText, int widthInPixels)
    Adds a single-line text field.
    void clear()
    Clears the GTerm like clearing a terminal.
    void clearRowsOfTable​(int indexOfTable)
    Clears added rows of an existing table.
    void close()
    Closes this GTerm window but does not necessarily stop the program from running.
    java.awt.Color getColorFromDialog​(String message)
    Shows a colour chooser.
    String getFilePath()
    Displays a file open dialog.
    int getIndexOfSelectedRowFromTable​(int indexOfTable)
    Retrieve the currently chosen row's index within an existing table.
    String getInputString​(String message)
    Allows the user to enter a String.
    String getPasswordFromDialog​(String message)
    Shows a password entry dialog box and returns the password.
    String getSelectedRowFromTable​(int indexOfTable)
    Retrieve the currently chosen row String from an existing table.
    String getTextFromEntry​(int textFieldIndex)
    Access the text entered in a text field or a text area.
    void print​(String message)
    Similar to System.out.print.
    void println​(String message)
    Similar to System.out.println.
    void setBackgroundColor​(int r, int g, int b)
    Change the RGB background colour of the window.
    void setBackgroundColor​(java.awt.Color backgroundColor)
    Change the background colour of the window.
    String setFilePath()
    Displays a file save dialog.
    void setFont​(String fontName, int fontStyle, int fontSize)
    Change the font size, style and size used for text that will be added next.
    void setFontColor​(int r, int g, int b)
    Change the font colour used for text that will be added next.
    void setFontColor​(java.awt.Color fontColor)
    Change the font colour used for text that will be added next.
    void setFontName​(String fontName)
    Change the font name used for text that will be added next.
    void setFontSize​(int fontSize)
    Change the font size used for text that will be added next.
    void setFontStyle​(int fontStyle)
    Change the font style for text that will be added next.
    void setTabSize​(int tabSize)
    Number of spaces used to replace a tab character by methods such as print and println.
    void setTextInEntry​(int textFieldIndex, String text)
    Modify the text entered in a text field or a text area.
    void setXY​(int x, int y)
    Allows the change of placement within the window.
    void showErrorDialog​(String message)
    Shows the supplied message to the user using an error message dialog box.
    void showHelp()
    Prints the version, credits and help file location.
    void showMessageDialog​(String message)
    Shows the supplied message to the user using an information message dialog box.
    void showWarningDialog​(String message)
    Shows the supplied message to the user using a warning message dialog box.