The problem here is that I wanna make sure that the user doesn't enter any strings or text especially that I need to enter his choice into a database later so I don't things to get messed up in the database's part, here is part of code which is the view I wish to use the textview with restricted Integers (specifically the amount am field).
PS: I'm still new to both JavaFX and TornadoFX so hope this doesn't sound like a rather silly question.
My Code:
package com.company.view
import javafx.beans.property.SimpleIntegerProperty
import javafx.scene.control.CheckBox
import tornadofx.*
import javafx.scene.control.TextField
import javafx.util.converter.NumberStringConverter
import java.sql.Connection
class Add: View() {
override val root = Form()
private val mainMenu: MainMenu by inject()
private var cname: TextField by singleAssign()
private var address: TextField by singleAssign()
private var sname: TextField by singleAssign()
private var ch: CheckBox by singleAssign()
private var am: TextField by singleAssign()
var conn: Connection?= mainMenu.conn
init {
with(root) {
vbox(30.0) {
fieldset("Enter Your Info below") {
field("Enter The Customer's Name") {
cname = textfield()
}
field("Enter the Customer's address") {
address = textfield()
}
field("Enter Bought Stock's Name") {
sname = textfield()
}
field("Do you wish to pay now?") {
ch = checkbox()
}
field("Enter the amount you wish to buy"){
am = textfield()
}
button("Submit")
{
setOnAction {
addPayment(cname.text, address.text, sname.text, ch.isSelected, am.text)
}
}
}
}
}
}
private fun addPayment(cusName: String, caddress: String, stname: String, che: Boolean,am: String){
//required code for inserting into the database here.
}
}
You can use the filterInput extension function we've added to TextField and check that the text after the addition is in int. If it's not, deny the last input change:
textfield {
filterInput { it.controlNewText.isInt() }
}
On another note, you really need to look into ItemViewModel. It's an anti-pattern to assign each input element to a variable and extract the values from the input values on submit. Your code will be a lot cleaner and easier to reason about and refactor later if you use view models.
PS: The filterInput function is available in the soon to be released TornadoFX 1.7.15, in the mean time you can add this extension function to your project:
fun TextInputControl.filterInput(discriminator: (TextFormatter.Change) -> Boolean) {
textFormatter = TextFormatter<Any>(CustomTextFilter(discriminator))
}
From your example it seems like that you'd want to use a PropertySheet which comes from ControlsFX. I use it in production and it works well with TornadoFX.
Here is an example from the samples project which you can peruse. This will let you edit and bind multiple types not just numbers:
public class PropertySheetExample extends VBox {
private static Map<String, Object> customDataMap = new LinkedHashMap<>();
static {
customDataMap.put("Group 1#My Text", "Same text"); // Creates a TextField in property sheet
customDataMap.put("Group 1#My Date", LocalDate.of(2000, Month.JANUARY, 1)); // Creates a DatePicker
customDataMap.put("Group 2#My Enum Choice", SomeEnumType.EnumValue); // Creates a ChoiceBox
customDataMap.put("Group 2#My Boolean", false); // Creates a CheckBox
customDataMap.put("Group 2#My Number", 500); // Creates a NumericField
}
class CustomPropertyItem implements PropertySheet.Item {
private String key;
private String category, name;
public CustomPropertyItem(String key) {
this.key = key;
String[] skey = key.split("#");
category = skey[0];
name = skey[1];
}
#Override
public Class<?> getType() {
return customDataMap.get(key).getClass();
}
#Override
public String getCategory() {
return category;
}
#Override
public String getName() {
return name;
}
#Override
public String getDescription() {
return null;
}
#Override
public Object getValue() {
return customDataMap.get(key);
}
#Override
public void setValue(Object value) {
customDataMap.put(key, value);
}
}
public PropertySheetExample {
ObservableList<PropertySheet.Item> list = FXCollections.observableArrayList();
for (String key : customDataMap.keySet())
list.add(new CustomPropertyItem(key));
PropertySheet propertySheet = new PropertySheet(list);
VBox.setVgrow(propertySheet, Priority.ALWAYS);
getChildren().add(propertySheet);
}
}
You can also take a look at this question for more info.
Related
This is a followup to a prior question I posted here.
In the MCVE below, I have a TableView displaying a list of Person objects. Above the list, I have a single TextField which I use to filter the listed items in the TableView.
The Person class contains 4 fields, but I have my search field only checking for matches in 3 of them: userId, lastName, and emailAddress.
The filtering function works as expected.
However, I now need to rank the results based on which fields were matched and the user Type.
MCVE CODE
Person.java:
import javafx.beans.property.IntegerProperty;
import javafx.beans.property.SimpleIntegerProperty;
import javafx.beans.property.SimpleStringProperty;
import javafx.beans.property.StringProperty;
public final class Person {
private StringProperty userType = new SimpleStringProperty();
private IntegerProperty userId = new SimpleIntegerProperty();
private StringProperty firstName = new SimpleStringProperty();
private StringProperty lastName = new SimpleStringProperty();
private StringProperty emailAddress = new SimpleStringProperty();
public Person(String type, int id, String firstName, String lastName, String emailAddress) {
this.userType.set(type);
this.userId.set(id);
this.firstName.set(firstName);
this.lastName.set(lastName);
this.emailAddress.set(emailAddress);
}
public String getUserType() {
return userType.get();
}
public void setUserType(String userType) {
this.userType.set(userType);
}
public StringProperty userTypeProperty() {
return userType;
}
public int getUserId() {
return userId.get();
}
public void setUserId(int userId) {
this.userId.set(userId);
}
public IntegerProperty userIdProperty() {
return userId;
}
public String getFirstName() {
return firstName.get();
}
public void setFirstName(String firstName) {
this.firstName.set(firstName);
}
public StringProperty firstNameProperty() {
return firstName;
}
public String getLastName() {
return lastName.get();
}
public void setLastName(String lastName) {
this.lastName.set(lastName);
}
public StringProperty lastNameProperty() {
return lastName;
}
public String getEmailAddress() {
return emailAddress.get();
}
public void setEmailAddress(String emailAddress) {
this.emailAddress.set(emailAddress);
}
public StringProperty emailAddressProperty() {
return emailAddress;
}
}
Main.java:
import javafx.application.Application;
import javafx.collections.FXCollections;
import javafx.collections.ObservableList;
import javafx.collections.transformation.FilteredList;
import javafx.collections.transformation.SortedList;
import javafx.geometry.Insets;
import javafx.geometry.Pos;
import javafx.scene.Scene;
import javafx.scene.control.TableColumn;
import javafx.scene.control.TableView;
import javafx.scene.control.TextField;
import javafx.scene.control.cell.PropertyValueFactory;
import javafx.scene.layout.VBox;
import javafx.stage.Stage;
import java.util.Comparator;
public class Main extends Application {
TableView<Person> tableView;
private TextField txtSearch;
public static void main(String[] args) {
launch(args);
}
#Override
public void start(Stage primaryStage) {
// Simple Interface
VBox root = new VBox(10);
root.setAlignment(Pos.CENTER);
root.setPadding(new Insets(10));
// Create the TableView of data
tableView = new TableView<>();
TableColumn<Person, Integer> colId = new TableColumn<>("ID");
TableColumn<Person, String> colFirstName = new TableColumn<>("First Name");
TableColumn<Person, String> colLastName = new TableColumn<>("Last Name");
TableColumn<Person, String> colEmailAddress = new TableColumn<>("Email Address");
// Set the ValueFactories
colId.setCellValueFactory(new PropertyValueFactory<>("userId"));
colFirstName.setCellValueFactory(new PropertyValueFactory<>("firstName"));
colLastName.setCellValueFactory(new PropertyValueFactory<>("lastName"));
colEmailAddress.setCellValueFactory(new PropertyValueFactory<>("emailAddress"));
// Add columns to the TableView
tableView.getColumns().addAll(colId, colFirstName, colLastName, colEmailAddress);
// Create the filter/search TextField
txtSearch = new TextField();
txtSearch.setPromptText("Search ...");
addSearchFilter(getPersons());
// Add the controls to the layout
root.getChildren().addAll(txtSearch, tableView);
// Show the stage
primaryStage.setScene(new Scene(root));
primaryStage.setTitle("Sample");
primaryStage.show();
}
private void addSearchFilter(ObservableList<Person> list) {
FilteredList<Person> filteredList = new FilteredList<Person>(list);
txtSearch.textProperty().addListener(((observable, oldValue, newValue) ->
filteredList.setPredicate(person -> {
// Clear any currently-selected item from the TableView
tableView.getSelectionModel().clearSelection();
// If search field is empty, show everything
if (newValue == null || newValue.trim().isEmpty()) {
return true;
}
// Grab the trimmed search string
String query = newValue.trim().toLowerCase();
// Convert the query to an array of individual search terms
String[] keywords = query.split("[\\s]+");
// Create a single string containing all the data we will match against
// BONUS QUESTION: Is there a better way to do this?
String matchString =
String.valueOf(person.getUserId())
+ person.getLastName().toLowerCase()
+ person.getEmailAddress().toLowerCase();
// Check if ALL the keywords exist in the matchString; if any are absent, return false;
for (String keyword : keywords) {
if (!matchString.contains(keyword)) return false;
}
// All entered keywords exist in this Person's searchable fields
return true;
})));
SortedList<Person> sortedList = new SortedList<>(filteredList);
// Create the Comparator to allow ranking of search results
Comparator<Person> comparator = new Comparator<Person>() {
#Override
public int compare(Person person, Person t1) {
return 0;
}
};
// Set the comparator and bind list to the TableView
sortedList.setComparator(comparator);
tableView.setItems(sortedList);
}
private ObservableList<Person> getPersons() {
ObservableList<Person> personList = FXCollections.observableArrayList();
personList.add(new Person("DECEASED", 123, "Chrissie", "Watkins", "fishfood#email.com"));
personList.add(new Person("VET", 342, "Matt", "Hooper", "m.hooper#noaa.gov"));
personList.add(new Person("VET", 526, "Martin", "Brody", "chiefofpolice#amity.gov"));
personList.add(new Person("NEW", 817, "Larry", "Vaughn", "lvaughn#amity.gov"));
return personList;
}
}
You'll see I have an empty Comparator in my Main class. This is what I need help with. I have created comparators in the past that are able to sort based on one field (from my previous question):
Comparator<DataItem> byName = new Comparator<DataItem>() {
#Override
public int compare(DataItem o1, DataItem o2) {
String searchKey = txtSearch.getText().toLowerCase();
int item1Score = findScore(o1.getName().toLowerCase(), searchKey);
int item2Score = findScore(o2.getName().toLowerCase(), searchKey);
if (item1Score > item2Score) {
return -1;
}
if (item2Score > item1Score) {
return 1;
}
return 0;
}
private int findScore(String item1Name, String searchKey) {
int sum = 0;
if (item1Name.startsWith(searchKey)) {
sum += 2;
}
if (item1Name.contains(searchKey)) {
sum += 1;
}
return sum;
}
};
I am not sure how to adapt this for multiple fields, though. Specifically, I want to be able to choose which fields should be ranked "higher."
For this example, what I want to accomplish is to sort the list in this order:
userId starts with a keyword
lastName starts with a keyword
emailAddress starts with a keyword
lastName contains a keyword
emailAddress contains a keyword
Within matches any userType = "VET" should be listed first
I am not looking for Google-level algorithms, but just some way to prioritize matches. I am not very familiar with the Comparator class and have a hard time understanding the JavaDocs for it, as it applies to my needs.
There are several posts on StackOverflow that deal with sorting by multiple fields, but all those I've found are comparing Person to Person. Here, I need to compare Person fields to the txtSearch.getText() value.
How would I go about refactoring this Comparator to set up custom sorting of this nature?
Your scoring concept is close, you just need to come up with factors and follow the rules.
So, here's a simple example:
public int score(Item item, String query) {
int score = 0;
if (item.userId().startsWith(query) {
score += 2000;
}
if (item.lastName().startsWith(query) {
score += 200;
} else if (item.lastName().contains(query) {
score += 100;
}
if (item.email().startsWith(query) {
score += 20;
} else if (item.email().contains(query) {
score += 10;
}
if (item.userType().equals("VET")) {
score += 5;
}
return score;
}
So as you can see, I took each of your criteria and turned them in to different digits within the score, and for the distinction within each criteria, I had different values (10 vs 20, for example). Finally I tacked on 5 for the "VET" type.
The assumption is that the scoring rules are not exclusive (i.e. that each rule refines the scoring, rather than stops it), and the the VET types were tie breakers within each criteria, vs to the top of the list. If VET needs to go to the top of the list (i.e. all VETs will be show before all non-VET), you can change the 5 to 10000, giving it it's own order of magnitude.
Now, using decimal numbers is just easy, but you'll run out of magnitudes after 9 (you'll overflow the int) -- you could also use other bases (base 3 in this example), giving you access to more "bits" in the integer. You could use a long, Or you could use a BigDecimal value and have as many criteria as you like.
But the basics are the same.
Once you have the score, just compare the scores of the two values in your comparator.
You can sort for multiple fields by chaining comparators together. If the first comparator declares two objects to be equal you delegate to the next comparator and continue like this until all comparators have been queried or any of them have returned a value other than 0.
Here is an example:
static class Person {
String name;
int age;
int id;
}
Comparator<Person> c3 = (p1, p2) -> {
return Integer.compare(p1.id, p2.id);
};
Comparator<Person> c2 = (p1, p2) -> {
if (p1.name.compareTo(p2.name) == 0) {
return c3.compare(p1, p2);
}
return p1.name.compareTo(p2.name);
};
Comparator<Person> c1 = (p1, p2) -> {
if (Integer.compare(p1.age, p2.age) == 0) {
return c2.compare(p1, p2);
}
return Integer.compare(p1.age, p2.age);
};
The comparators are queried in the sequence of c1 then c2 then c3.
Of course this is an overly simplified example. In production code you should preferably use a cleaner and more OOP oriented solution.
I am using a custom TextFieldTableCell in JavaFX 8 to allow users to edit the text field. When the user hits Enter, however, I want to check to see if the text field equals a certain value. If it does equal this certain value, I do not want the entry to save and for it to revert to the text it had before the user started editing. Is there a method I can override to produce this result? I cannot find one that fits what I am looking for.
Thank you in advance!
Since the model is bound to the cell's data, you can do the validation and reset part in the modell class, in your case in the Person class.
Here is a simple example how you can do it:
public class Controller implements Initializable {
#FXML
private TableColumn<Model, String> name;
#FXML
private TableView<Model> tableView;
#Override
public void initialize(URL location, ResourceBundle resources) {
name.setCellValueFactory(data -> data.getValue().nameProperty());
name.setCellFactory(cell -> new TextFieldTableCell<>(new StringConverter<String>() {
#Override
public String toString(String object) {
return object;
}
#Override
public String fromString(String string) {
return string;
}
}));
tableView.setEditable(true);
tableView.setItems(FXCollections.observableArrayList(new Model("Test")));
}
private class Model {
private StringProperty name;
ChangeListener<String> nameChangeListener = (observable, oldValue, newValue) -> {
if (!newValue.matches("[A-Z][a-zA-Z]*")) { // a validation example insert your here.
this.name.set(oldValue);
}
};
public Model(String name) {
this.name = new SimpleStringProperty(name);
this.name.addListener(nameChangeListener);
}
public String getName() {
return name.get();
}
public StringProperty nameProperty() {
return name;
}
}
}
From your description I assume that you are talking about an editable cell in a table view.
If that's the case, the following example should be working for you. You can use the .setOnEditCommit() method to add an event handler to the colum for which you would like to check the entered value.
//Create table
TableView<Person> table = new TableView<Person>();
table.setEditable(true);
//Create column
TableColumn<Person, String> column = new TableColumn<Person, String>("Full Name");
column.setCellValueFactory(new PropertyValueFactory<>("fullName"));
column.setCellFactory(TextFieldTableCell.<Person> forTableColumn());
column.setMinWidth(200);
column.setOnEditCommit(event -> {
//Get entered value
String newFullName = event.getNewValue();
//Get selected position
TablePosition<Person, String> pos = event.getTablePosition();
//Get row of position
int row = pos.getRow();
//Get data from selected row
Person person = event.getTableView().getItems().get(row);
//Check if text equals ...
if (newFullName.equals("Test")) {
person.setFullName(newFullName);
} else {
person.setFullName(event.getOldValue());
table.refresh();
}
});
I am newbie in building javafx MVVM app.
I've created a simple ViewModel:
public class PersonViewModel {
private final StringProperty name = new SimpleStringProperty();
private final IntegerProperty age = new SimpleIntegerProperty();
public PersonViewModel() {}
// getters and setters
}
and simple View:
public class PersonView implements Initializable {
#FXML
TextField name;
#FXML
TextField age;
#FXML
Button ok;
#Override
public void initialize(URL location, ResourceBundle resources) {
PersonViewModel viewModel = new PersonViewModel();
name.textProperty().bindBidirectional(viewModel.name);
age.textProperty().bindBidirectional(viewModel.age);
}
}
Can you give me any idea how to make age validation? F.e. I wanna not to allow user to put characters into age (TextField) except [a-zA-Z]. And the main idea of my question to make this validation in ViewModel) Help me pls.
P.S. I wanna make it not using not standard javafx components.
You can use a TextFormatter both to filter input in a text input control, and to convert the text into a value of a specific type. If you want the view model to define the validation rules, then define a method in there representing the validation, and delegate to that method in the filter definition for the TextFormatter. For example:
public class PersonViewModel {
private final StringProperty name = new SimpleStringProperty();
public StringProperty nameProperty() {
return name ;
}
public final String getName() {
return nameProperty().get();
}
public final void setName(String name) {
nameProperty.set(name);
}
private final IntegerProperty age = new SimpleIntegerProperty();
public IntegerProperty ageProperty() {
return age ;
}
public final int getAge() {
return ageProperty().get();
}
public final void setAge(int age) {
ageProperty.set(age);
}
public boolean validAgeInput(String input) {
// must support partial entry while editing, including empty string
// accept any integer from 0 - 135 (arbitrary upper bound example)
String regex = "([0-9]{0,2})|(1[0-2][0-9])|(13[0-5])";
return input.matches(regex);
}
}
Now you can do:
public class PersonView implements Initializable {
#FXML
TextField name;
#FXML
TextField age;
#FXML
Button ok;
#Override
public void initialize(URL location, ResourceBundle resources) {
PersonViewModel viewModel = new PersonViewModel();
UnaryOperator<Change> filter = change -> {
if (viewModel.validAgeInput(change.getControlNewText()) {
// accept
return change ;
} else {
// reject
return null ;
}
};
TextFormatter<Integer> ageFormatter = new TextFormatter<>(new IntegerStringConverter(), 0, filter);
age.setTextFormatter(ageFormatter);
ageFormatter.valueProperty().bindBidirectional(viewModel.ageProperty().asObject());
name.textProperty().bindBidirectional(viewModel.nameProperty());
}
}
The filter defined here will only accept input in the control if it matches the rule defined by the method in the PersonViewModel. The valueProperty() of the TextFormatter represents the text in the TextField after passing it to the IntegerStringConverter: this is bound bidirectionally to the ageProperty() in the model. (The call to asObject() effectively just converts between an IntegerProperty and an ObjectProperty<Integer>.)
I want do declare a Subclass of an HTMLPanel.
In its constructor I want to give it a few paramters to construct the containing html.
Because I have to call the super-constructor as first statement, I have to change the html later in the constructor.
How can I do this?
public class MyHTMLPanel extends HTMLPanel
{
public MyHTMLPanel(String id, int anotherParameter)
{ super("");
String html=""
// ... some code th construct the html
//??? this.setHtml(html);
}
}
You can find below an example I used and worked well for me.
I don't remember why I don't sub-class HTMLPanel, whether a good reason or not.
You will notice a mechanism to randomize the html ids in case you include several objects of the same type in a single page.
public abstract class HtmlPanelBase extends Composite
{
private String _dynPostfix = "";
protected final String id(final String staticId) { return staticId + _dynPostfix; }
private final String wrapId(final String id) { return "id=\"" + id + "\""; }
private final String wrapDynId(final String refId) { return wrapId(id(refId)); }
private String _htmlAsText = null;
public String getHtmlAsText() { return _htmlAsText; }
abstract protected String htmlPanelBundleHtmlText();
abstract protected List<String> idList();
protected HTMLPanel _holder = null;
private HTMLPanel createHtmlPanel(final boolean defineGloballyUniqueIds)
{
// Referent HTML panel text containing the reference id's.
_htmlAsText = htmlPanelBundleHtmlText();
if (defineGloballyUniqueIds)
{
// List of id's in the HTML Panel reference page to replace with dynamic/unique id's.
final List<String> refIdList = idList();
// Replace the reference id's with dynamic/unique id's.
for (String refId : refIdList)
_htmlAsText = _htmlAsText.replace(wrapId(refId), wrapDynId(refId));
}
// Return the HTMLPanel containing the globally unique id's.
return new HTMLPanel(_htmlAsText);
}
public HtmlPanelBase(final boolean defineGloballyUniqueIds)
{
setup(defineGloballyUniqueIds);
initWidget(_holder);
}
private void setup(final boolean defineGloballyUniqueIds)
{
if (defineGloballyUniqueIds)
_dynPostfix = "_" + UUID.uuid().replace("-", "_");
_holder = createHtmlPanel(defineGloballyUniqueIds);
}
}
And now how you could sub-class from the above base:
public class HtmlPanelTemplate extends HtmlPanelBase
{
private final static boolean _defineGloballyUniqueIds = false;
private final static int _numIdCapacity = 40;
public HtmlPanelTemplate()
{
super(_defineGloballyUniqueIds);
setup();
}
#Override
protected String htmlPanelBundleHtmlText()
{
return YourClientBundle.INSTANCE.getYourFileHtml().getText();
}
#Override
protected List<String> idList()
{
final List<String> idList = new ArrayList<String>(_numIdCapacity);
return idList;
}
private void setup()
{
}
}
You don't need to subclass HTMLPanel. You can create a simple Composite widget:
public class myPanel extends Composite {
private HTMLPanel panel = new HTMLPanel();
public myPanel(String id, int anotherParameter) {
// set HTML to panel based on your parameters
initWidget(panel);
}
}
htmlPanel.getElement().setInnerHTML(...)
Don't know whether this works in derived class' constructor. But setting up a class for specific content text isn't really a good solution.
it's my first post in here, but you have been helping me indirectly in many ways. But this kind of thing, like the title says, I still can't figure out.
I think I don't need to say I'm a noob in such a thing, and any kind of help would be great =] .. By the way, I'm using netbeans (Java).
So, here's my problem:
I have a jFrame1 with 3 textFields.
Also, in this jFrame1, I have a button that should do the following:
+Look through the whole 3 textFields and only select the words that are between "" and/or between **. Other words should not be used. Also, this button should redirect me to jFrame2.
In the other jFrame2, the 'special' words found in the 3 textFields (jFram1), should be put in there, inside a jTextArea1.
And that's where I'm lost. Because I can't find a way to get these 'special' words and throw them in there.
Let me post the code in here, so you guys can take a closer look to what I'm doing right/wrong:
//Below, the Jframe1
public class JFrame1 extends javax.swing.JFrame {
public TxtFieldsQuotationMarks tfqm = new TxtFieldsQuotationMarks();
public TxtFieldsAsterisk tfa = new TxtFieldsAsterisk();
public JFrame1()
{
initComponents();
}
//Below, the classes I created to support the textFields in JFrame1
public class TxtFieldsQuotationMarks
{
public String field1;
public String field2;
public String field3;
}
public class TxtFieldsAsterisk
{
public String field1;
public String field2;
public String field3;
}
//Bellow, the function that should do the trick (of finding those 'special words')
private String Get_Fields_FindWords()(String Value)
{
if (Value.isEmpty())
{
return "";
}
else
{
String AuxStr = Value.substring(Value.indexOf('"'),Value.length());
return AuxStr.substring(1, AuxStr.indexOf('"'));
}
}
private String Get_Fields_Asterisk_FindWords(String Value)
{
if (Value.isEmpty())
{
return "";
}
else
{
String AuxStr = Value.substring(Value.indexOf('*'),Value.length());
return AuxStr.substring(1, AuxStr.indexOf('*'));
}
}
//Below, the button in JFrame1, that should find the words and open the JFrame2 for me with those words (Quotation Marks on top and Asterisks below it)
private void btnJFrame1ActionPerformed(java.awt.event.ActionEvent evt)
{
Get_Fields_FindWords();
Get_Fields_Asterisks_FindWords();
JFrame2 jf2 = new JFrame2();
jf2.setVisible(true);
}
//Below, the methods I tried to implement, in order to save the 'special words' in the textFields (this is also in the JFrame1)
public void Get_Fields()
{
fields.field1 = Return_StringQuotationMarks(txtField1.getText());
fields.field2 = Retorna_StringAspas(txtField2.getText());
fields.field3 = Retorna_StringAspas(txtField3.getText());
}
public void Get_Fields_Asterisk()
{
fields_asterisk.field1 = Return_StringAsterisk(txtField1.getText());
fields_asterisk.field2 = Return_StringAsterisk(txtField2.getText());
fields_asterisk.field3 = Return_StringAsterisk(txtField3.getText());
}
//Finally, here's the second JFrame (Jframe2), with the textArea (textArea)
public class JFrame2 extends javax.swing.JFrame {
TxtFieldsQuotationMarks tfqm = new TxtFieldsQuotationMarks();
TxtFieldsAsterisk tfa = new TxtFieldsAsterisk();
public JFrame2()
{
initComponents();
}
}
That's pretty much it, guys. I hope you can understand what I'm trying to do and can help me somehow. I really need this thing done as soon as possible.
Well I think you can pass the words founds by constructor of JFrame2. For example:
private void btnJFrame1ActionPerformed(java.awt.event.ActionEvent evt)
{
JFrame2 jf2 = new JFrame2(
Get_Fields(txtField1.getText()),
Get_Fields(txtField2.getText()),
Get_Fields(txtField3.getText()),
Get_Fields_Asterisk(txtField1.getText()),
Get_Fields_Asterisk(txtField1.getText()),
Get_Fields_Asterisk(txtField1.getText()));
jf2.setVisible(true);
}
And the constructor of JFrame2:
public JFrame2(String field1, String field2, String field3, String asterisk1, String asterisk2, String asterisk3)
{
initComponents(field1, field2, field3, asterisk1, asterisk2, asterisk3);
}
Then you can initializate components in JFrame2 with the values searched in JFrame1.
You don't need to save it somewhere you only need it in initialization.