Java FX observableList. Observation scheme [closed] - java

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 3 days ago.
Improve this question
FXCollections.observableList
Documentation said:
Note that mutation operations made directly to the underlying list are
not reported to observers of any ObservableList that wraps it.
Code for example:
public class Test {
public static void tst() {
ArrayList<Person> arrayList = new ArrayList<>();
ObservableList<Person> people = FXCollections.observableList(arrayList);
Person person = new Person("Tom");
arrayList.add(person);
person.setName("Mary");
// How update people after that
}
public static class Person {
private String name;
public Person(String name) {
this.name = name;
}
public void setName(String name) {
this.name = name;
}
}
}
What are some ways to observe the change or addition of SIMPLE objects?

Related

How to create a private array and access it by the main method in java? [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 2 years ago.
Improve this question
I want to create a class outside the public class but in the same file, and in that class I wanna create a private array which can only be accessed by creating object through the previous public class. I also wanna store data to that array through the public class.
I suggest you to start learning java, this will save you from asking this kind of question next time. For the moment you can find how to achieve what you are asking for in the example bellow :
public class Learning {
public static void main(String[] args) {
Course course = new Course();
List<String> materials = new ArrayList<>();
materials.add("java basic courses");
materials.add("OOP courses");
// here we use setters to set course materials and notes
course.setMaterials(materials);
course.setNotes(new int[] {19,20});
System.out.println("Display course materials");
for (String material : course.getMaterials()) {
System.out.println("Material : " + material);
}
System.out.println("Display Notes");
for (int note : course.getNotes()) {
System.out.println("Note : " + note);
}
}
}
class Course {
private List<String> materials;
private int[] notes;
public List<String> getMaterials() {
return materials;
}
public void setMaterials(List<String> materials) {
this.materials = materials;
}
public int[] getNotes() {
return notes;
}
public void setNotes(int[] notes) {
this.notes = notes;
}
}

Creating a class that has integers, getter/setters, with input validation [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 2 years ago.
Improve this question
I am working on this Java program where I am supposed to write a class called kumquat that has an integer age with getter and setters. Additionally, I need to do input validation. I can't figure out what I'm doing wrong. I'm sorry if this is really simple I'm just still really new to this.
public class Person
{
private int age;
public int getAge()
{
return age;
}
public void setAge(int newAge)
{
this.age = newAge;
}
}
and then my main
public class Kumquat
{
public static void main(int[] args)
{
Person myObj = new Person();
myObj.setAge("5");
System.out.println(myObj.getAge());
}
}
Everything is ok in the Person class. Although in your main the method Person::setAge receives an int as parameter and you're trying to pass a String in line myObj.setAge("5");. Try passing an int like myObj.setAge(5); instead.
you should write String instead of int and setAge should not be string
public static void main(String[] args)
{
Person myObj = new Person();
myObj.setAge(5);
System.out.println(myObj.getAge());
}

Object Orientation, Inheritance, Abstraction [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 6 years ago.
Improve this question
class Student {
private String name;
private int age;
public static String city;
Student() {
}
Student(int a) {
age = a;
}
public void setName(String n) {
name = n;
}
public String getName() {
return name;
}
private int getAge() {
return age;
}
public void setCity(String c) {
city = c;
}
public String getCity() {
return city;
}
}
When considering the features of object orientation, which feature(s) is/are shown clearly in the program?
How can I know that above code is:
Abstraction
Encapsulation
Data hiding
Inheritance
Polymorphism
abstraction - No (you don't have any abstract members or classes in your code).
Encapsulation - yes ( Binding code and data together - the class itself) .
polymorphism - no ( no multiple functions with same names ) .
inheritance - no (There is no class that inherits this one and vice versa )

What should be the Java object for this JSON String? [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 7 years ago.
Improve this question
{"userId":"vincent","favTracks":{"favourite":"15","unFavourite":"121"}}
What can be the Java object for the above JSON String?
It really depends on how you want to map it. If you're using Jackson, for example, with the default mapping settings, your classes could look something like:
class MyObject {
private String userId;
private FavTracks favTracks;
public String getUserId() {
return userId;
}
public void setUserId(String userId) {
this.userId = userId;
}
public FavTracks getFavTracks() {
return favTracks;
}
public void setFavTracks(FavTracks favTracks) {
this.favTracks = favTracks;
}
}
class FavTracks {
private String favourite;
private String unFavourite;
public String getFavourite() {
return favourite;
}
public void setFavourite(String favourite) {
this.favourite = favourite;
}
public String getUnFavourite() {
return unFavourite;
}
public void setUnFavourite(String unFavourite) {
this.unFavourite = unFavourite;
}
}
One remark: in your current example, the favourite and unFavourite properties are of a string type. Maybe a numeric type is more suitable?

How to access remote Object [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Closed 9 years ago.
Questions concerning problems with code you've written must describe the specific problem — and include valid code to reproduce it — in the question itself. See SSCCE.org for guidance.
Questions must demonstrate a minimal understanding of the problem being solved. Tell us what you've tried to do, why it didn't work, and how it should work. See also: Stack Overflow question checklist
Improve this question
I'm new to Java. I want to create Java Object with test data and access the object from remote class. I created this object:
public class TestAgentData
{
public TestAgentDataObj tad;
public class TestAgentDataObj
{
public int agentId = 1234;
public String agentName = "AgentName";
public String description = "AgentDscription";
public TestAgentDataObj(int agentId, String agentName, String description)
{
this.agentId = agentId;
this.agentName = agentName;
this.description = description;
}
public int getAgentId()
{
return agentId;
}
public void setAgentId(int agentId)
{
this.agentId = agentId;
}
public String getAgentName()
{
return agentName;
}
public void setAgentName(String agentName)
{
this.agentName = agentName;
}
public String getDescription()
{
return description;
}
public void setDescription(String description)
{
this.description = description;
}
}
public TestAgentDataObj getTad()
{
return tad;
}
public void setTad(TestAgentDataObj tad)
{
this.tad = tad;
}
}
I tried to access the object from remote class:
Object eded = new TestAgentData.getTad();
But I get error in Netbeans. Can you tell what is the proper way to access data in a Java Object?
I think you need a better understanding about java. There are big errors in this.
You cannot way you create your object is wrong its new TestAgentData()
You can't call getTad() from an object of type Object because there is no getTad() method defined in Object class. Rather do the following
TestAgentDataObj obj=new TestAgentData().new TestAgentDataObj();
TestAgentData eded = new TestAgentData();
eded.setTad(obj);
TestAgentDataObj result=eded.getTad();

Categories

Resources