Skip to content

CustomFrame.java

Josef Miko Urquico edited this page Jun 30, 2024 · 1 revision

CustomFrame.java

Mainly stores the core functions of the JFrame.
It's plain stupid to explain the functions in great detail so a summary is going
to be performed when explaining things.

Current variables:

  • randomCharacterDisplay: displays the randomly picked character via JLabel
  • randomCharacterPositionDisplay: blinks the correct answer before generating a new letter
  • refreshButton: button used to generate a random character
  • toggleNumberPositionButton: for users who want to see the button the entire time

Current Classes inside CustomFrame.java

  • CustomButton: uses JButton as parent class and contains instance variable and a getter method to be able to specify what buttons to look for when actionEvent gets triggered
  • ChangeLetter: threading class that is mainly for run() to create a separate thread to properly observe changes in the JFrame in real time

Pseudocode

public class CustomFrame extends JFrame implements ActonListener {
  declare JLabel randomCharacterdisplay, randomCharacterPositionDisplay
  declare CustomButton refreshButton, toggleNumberPositionButton
  
  constructor() {
    give properties to randomCharacterdisplay; // Text value is null for now
	give properties to randomCharacterPositionDisplay; // Text value is null for now
	
	give properties to refreshButton;
	give properties to toggleNumberPositionButton;
	
	create new obj changeLetter;
	run changeLetter.start(); // Get a random letter
	
	give properties to THIS;
	
	add randomCharacterdisplay to THIS;
	add randomCharacterPositionDisplay to THIS;
	add refreshButton to THIS;
	add toggleNumberPositionButton to THIS;
	
	set .setVisible(true) to THIS;
  }
  
  static toggleRefreshButton(boolean value) {
	set .setEnabled(value) to refreshButton;
  }
  
  static String getButtonStatus(String value) {
	return value
	  if value == "toggleNumberPositionButton" -> toggleNumberPositionButton.getText();
  }
  
  @Override
  actionPerformed(ActionEvent e) {
    if e is refreshButton:
      create new obj changeLetter;
      run changeLetter.start(); // Get a random letter
	  
    else if e is toggleNumberPositionButton:
      if "text is hidden":
	show text 
      else if "text is shown":
	hide text
  }
}

Files

Clone this wiki locally