Skip to Main Content

Java SE (Java Platform, Standard Edition)

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

Interested in getting your voice heard by members of the Developer Marketing team at Oracle? Check out this post for AppDev or this post for AI focus group information.

Integer cannot be resolved

Jade BelingaOct 15 2024 — edited Oct 16 2024
package cryptopackage;
import javafx.application.Platform;

import javafx.event.ActionEvent;
import javafx.event.EventHandler;
import javafx.geometry.Insets;
import javafx.geometry.Pos;
import javafx.scene.control.Button;
import javafx.scene.control.Label;
import javafx.scene.control.RadioButton;
import javafx.scene.control.TextField;
import javafx.scene.control.ToggleGroup;
import javafx.scene.control.Tooltip;
import javafx.scene.layout.BorderPane;
import javafx.scene.layout.HBox;
import javafx.scene.layout.VBox;



/**
* The class creates an object of FXMainPane used in FXDriver
* 
* @author Farnaz Eivazi
* @version 7/12/2022
*/

public class FXMainPane2 extends BorderPane {

private Button decryption, exitButton, encryption, test, clearButton;
private TextField plainTextTextField, inputForEncryptionTextField, encryptedStringTextField3, decryptedTextField4;
private Label plainTextLabel, descriptionForInputLabel, encryptedLabel3, decryptedLabel4, blankLabel1, blankLabel2;
private RadioButton radioButton1, radioButton2;
private int shiftInt = 0;
private final String BLANK = " ";

private void buildTextFields() {
plainTextTextField = new TextField();
inputForEncryptionTextField = new TextField();
encryptedStringTextField3 = new TextField();
decryptedTextField4 = new TextField();
}

private void buildLabels() {
plainTextLabel = new Label("Enter plain-text string to encrypt");
descriptionForInputLabel = new Label("Cyber Key - enter an integer for Caesar Cipher");
encryptedLabel3 = new Label("Encrypted string");
decryptedLabel4 = new Label("Decrypted string");
buildBlankLabels();
}

private void buildBlankLabels() {
blankLabel1 = new Label(BLANK);
blankLabel2 = new Label(BLANK);
setRight(blankLabel1);
setLeft(blankLabel2);
}

private void buildRadioButtons() {
// create three radio button instances
radioButton1 = new RadioButton("Use Caesar cipher");
radioButton2 = new RadioButton("Use Bellaso cipher");
// create a group to make the radio buttons mutually exclusive
ToggleGroup radioButtonGroup = new ToggleGroup();
radioButton1.setToggleGroup(radioButtonGroup);
radioButton2.setToggleGroup(radioButtonGroup);

radioButton1.setSelected(true);
radioButton1.setAlignment(Pos.CENTER);
radioButton2.setAlignment(Pos.CENTER);

RadioButtonListener radioButtonListener = new RadioButtonListener();
radioButton1.setOnAction(radioButtonListener);
radioButton2.setOnAction(radioButtonListener);
}

private void buildButtons() {
// _ in label specifies that the next character is the mnemonic, ie, type Alt-m
// as a shortcut
// this activates the mnemonic on exitButton when the Alt key is pressed

// create the exit Button
exitButton = new Button("E_xit");
exitButton.setMnemonicParsing(true);
exitButton.setTooltip(new Tooltip("Select to close the application"));

// create the clear Button
clearButton = new Button("_Clear");
clearButton.setMnemonicParsing(true);
clearButton.setTooltip(new Tooltip("Select this to clear the text fields"));

// create the decryption Button
decryption = new Button("_Decrypt a string");
decryption.setMnemonicParsing(true);
decryption.setTooltip(new Tooltip("Select this to decrypt a string"));

// create the encryption Button
encryption = new Button("Encrypt a string");
encryption.setMnemonicParsing(true);
encryption.setTooltip(new Tooltip("Encrypt the string in the upper textfield"));
encryption.setVisible(true);
}

private void addActionToExitButton() {
// use a lambda expression for the EventHandler class for exitButton
exitButton.setOnAction(event -> {
Platform.exit();
System.exit(0);
});
}

private void addActionToClearButton() {
// create a listener for the other button using a lambda expression
clearButton.setOnAction(event -> {
plainTextTextField.setText("");
inputForEncryptionTextField.setText("");
encryptedStringTextField3.setText("");
decryptedTextField4.setText("");
});
}

private void addActionToEncryptButton() {
// create a listener for the exit button using a lambda expression
encryption.setOnAction(event -> {
try {
String bellasoStr = "";
String encryptedStr = "";

if (radioButton1.isSelected()) {
shiftInt = Integer.parseInt(inputForEncryptionTextField.getText());
encryptedStr = CryptoManager2.caesarEncryption(plainTextTextField.getText().toUpperCase(), shiftInt);
} else {
bellasoStr = inputForEncryptionTextField.getText().toUpperCase();
inputForEncryptionTextField.setText(bellasoStr);
encryptedStr = CryptoManager2.bellasoEncryption(plainTextTextField.getText().toUpperCase(), bellasoStr);
}

plainTextTextField.setText(plainTextTextField.getText().toUpperCase());
if (encryptedStr.equals(""))
encryptedStringTextField3.setText("encryption failed");
else
encryptedStringTextField3.setText(encryptedStr);
} catch (NumberFormatException e) {
System.out.println(inputForEncryptionTextField.getText() + " should be an integer");
} catch (RuntimeException e) {
System.out.println(e.getMessage());
}
});
}

private void addActionToDecryptButton() {
// create a listener for the other button using a lambda expression
decryption.setOnAction(event -> {
try {
String encryptedText = "";
String bellasoStr = "";
String decryptedText;
encryptedText = encryptedStringTextField3.getText().toUpperCase();
if (radioButton1.isSelected()) {
shiftInt = Integer.parseInt(inputForEncryptionTextField.getText());
decryptedText = CryptoManager2.caesarDecryption(encryptedText, shiftInt);
} else {
bellasoStr = inputForEncryptionTextField.getText().toUpperCase();
inputForEncryptionTextField.setText(bellasoStr);
decryptedText = CryptoManager2.bellasoDecryption(encryptedText, bellasoStr);
}
decryptedTextField4.setText(decryptedText);
} catch (NumberFormatException e) {
System.out.println(inputForEncryptionTextField.getText() + " should be an integer");
} catch (RuntimeException e) {
System.out.println(e.getMessage());
}
});
}

private void addButtonActions() {
addActionToExitButton();
addActionToClearButton();
addActionToEncryptButton();
addActionToDecryptButton();
}

FXMainPane2() {
// for setting margins
Insets inset = new Insets(10);
buildTextFields();
buildLabels();
buildRadioButtons();
buildButtons();
addButtonActions();

HBox topBox = new HBox();
HBox.setMargin(radioButton1, inset);
topBox.setAlignment(Pos.CENTER);
topBox.getChildren().addAll(radioButton1, radioButton2);
topBox.setStyle("-fx-border-color: gray;");

// create the leftPanel
VBox centerBox = new VBox(10);
centerBox.getChildren().addAll(plainTextLabel, plainTextTextField, encryptedLabel3, encryptedStringTextField3,
decryptedLabel4, decryptedTextField4, descriptionForInputLabel, inputForEncryptionTextField);
setCenter(centerBox);

setTop(topBox);

HBox bottomBox = new HBox();
HBox.setMargin(decryption, inset);
HBox.setMargin(encryption, inset);
HBox.setMargin(clearButton, inset);

HBox.setMargin(exitButton, inset);
bottomBox.getChildren().addAll(encryption, decryption, clearButton, exitButton);
setBottom(bottomBox);
bottomBox.setAlignment(Pos.CENTER);

}

class RadioButtonListener implements EventHandler<ActionEvent> {
@Override
public void handle(ActionEvent event) {
Object source = event.getTarget();
if (source == radioButton1) {
descriptionForInputLabel.setText("Cyber Key - enter an integer for Caesar Cipher");
} else if (source == radioButton2) {
descriptionForInputLabel.setText("Cyber Key - enter a string for Bellaso Cipher");
}
}
}

}

Methods addActionToDecryptButton() and addActionToEncryptButton() have the line

shiftInt = Integer.parseInt(inputForEncryptionTextField.getText());

At these two lines it is saying “Integer cannot be resolved.”

I have tried java.lang.Integer.parseInt and importing java.lang as well (which resulted in a similar error).

How could I fix this?

Comments

The language shown in the Forms runtime is the result of your NLS_LANG setting in the runtime environment configuration (e.g. default.env). However, Forms can only change the language of labels it knows about. For example, the ones you highlighted. The column titles, in your example are labels that you elected to use (or column names from the DB). As a result, we cannot change them automatically because we would have no idea if that is what you wanted to do.

You would need to programmatically change those if desired. For example:

SET_LOV_COLUMN_PROPERTY ('LOV1', 2, TITLE, 'Nombre del empleado (Spanish)');

In this example, I am running a form in English but want one column to show in Spanish. So, I use the code above to make that change at runtime.

xu meng Feb 12 2025

Thanks for your reply, your example has inspired me a bit, but it still can't meet my usage needs.
I'm confused about:
When my system language variable is Chinese, I want to make the LOV component's Query/Confirm/Cancel button appear separately in other languages. As shown in the image above.
I don't know, but you can understand what I mean.

xu meng Feb 12 2025

As shown on the picture you provided. "查询" is displayed when the Chinese environment variable is used, and "FIND" is displayed when it is used in English. At present, I want to make the button of its LOV component window display "FIND" separately in the Chinese system, but I have not found the method in the help document and the network.

As I mentioned, strings built into Forms like “Find”, “Ok”, “Cancel”, and others can be translated into the language you choose in the runtime environment using the NLS_LANG settings. Unfortunately, this cannot be changed after the application has been started. So if the app is started with for example, Chinese-Traditional it cannot later be changed to French while the form is running. This means that you must either configure your server to support multiple languages and create modules for each language. This is often the best approach. There are other ways that customers have used, but what I described here likely would require the smallest effort.

You did not mention which Forms version you are using and therefore I cannot point you to the documentation for that version. However, here is the link to the related documentation for Forms 14.1.2. The concepts are basically the same for earlier versions, although some minor improvements have been introduced in the latest release (14.1.2).

https://docs.oracle.com/en/middleware/developer-tools/forms/14.1.2/working-forms/enabling-language-detection.html

But again, for strings that do not natively belong to Forms (you created them) you would need to programmatically change them as necessary.

xu meng Feb 12 2025

OH! I will try to implement your plan first. Thank you for your patience. My Forms version is 11.1.2.

As you are likely aware, but I feel it necessary to mention in case you are not, Forms 11.1.2 was desupported many years ago. I recommend you consider upgrading to the latest Supported version in order to ensure that you can get the latest bug fixes (including security fixes), the latest features, and improvements like what I mentioned about language support and others.

Details can always be found on the Forms product page.

https://www.oracle.com/application-development/technologies/forms/forms.html

xu meng Feb 12 2025

Thank you for telling me this news. I will consider your suggestion carefully and refer to it later. Thank you for your answer.

1 - 7

Post Details

Added on Oct 15 2024
2 comments
190 views