I am new to JavaFX. I would like to display a bar chart of items that are arranged according to their values.
I have the codes below that I call the function updateChart() after some user interaction. The list is sorted according to their values and on the 1st time the chart is populated, the order is displayed correctly.
However, when I pass in a new list with the same labels but with a different value, the bar chart is still displayed in the same order as the 1st time it is populated, even though I called clear().
@FXML
private BarChart<Number, String> certaintyFactorChart;
//update chart based on cf values
public void updateChart(List<AbstractMap.SimpleEntry<String, Double>> cfValues){
certaintyFactorChart.getData().clear();
I'm using BarChart and I've a very strange problem. Is not very simple create a test case to understand where is the problem.
In the first image is displayed a bar with the value of 2 but as you can see the y axis is not correct.
In the second image the value displayed is 4 but the y axis is completely busted.
Important thing: In my real app I change data of the chart every time the user change a combobox value (the period).
First image Second image
This is a test case that simulate what I'm doing in my app with the only difference that data are fetched remotely with an async request in my real app.
Chart.java
public class Chart extends Application implements Initializable { @FXML private BarChart<String, Integer> chart; private ObjectProperty<ObservableList<Series<String, Integer>>> seriesProperty = new SimpleObjectProperty<ObservableList<Series<String, Integer>>>();
[Code] .....
Unfortunately with this simple test case the chart display correctly data.
Currently I try to integrate a JavaFX BarChart into my existing Java application. Therefore I need a BufferedImage of my BarChart, so that I can render that snapshot on a Graphics instance.
I adapted the existing BarChartSample.java (Chart Sample | JavaFX Tutorials and Documentation) and removed all animations. The code itselfs works fine but I identified one problem -> my TickLabels are missing
The TickLabels are visible If I use JDK 1.7u51 but if I change to JDK 1.8u05.... than the stlye of my BarChart will be changed and my tick labels are not visible.
Is it possible to save dynamically created UI elements (e.g. tabs, buttons) and restoring them in a later session for the user? The user should be able to customize the application UI and creating buttons as shortcuts for tools.
import java.util.ArrayList; import java.util.Arrays; import java.util.List; public class array { public static void main(String[] args)
[Code] ...
Is there a way to write this, where, alpha is one array.
Write a program that declares an array "alpha" of 50 elements of type "double". Initialize the array so that the first 25 elements are equal to the square of the index variable and the last 25 elements are equal to three times the index variable. Output the array so that 10 elements per line are printed.
If I have an array of 50 integers, can I break that to read in lines of 10?
I am trying to make a 2d array that keeps track of comparison counts. what I have so far works ok but writes over the previous elements with 0. can't seem to find where I am re-initializing the previous elements.
//this is one of my fill sort arrays
public void fillSelectionArray(int index, long countSum) { //rand = new Random( ); //for ( int i = 0; i < listsize; i++) { selectionList[ index -1] = countSum; // }
public void createPersons() { Random rand = new Random(); for(int index = 0; index < persons.length; index++) { Person person = new Person(rand.nextInt(maxAge), persons[index]); setOfPersons.add(person);
[Code] ....
setOfPersons is a TreeSet, persons[] is an array of strings that contains 10 names. Why printPersons() prints only the half names of setOfPersons?
The library array has two books and I want to copy one of them to the reserved books when you type in the ISBN
public void borrowBook(String ISBN) { int i = 0; if(numberOfBooks < MAX_BOOKS-1) { if(libraryBooks[i].getBookISBN().equals(ISBN)) { for(i=0;i<MAX_BOOKS-1;i++) reservedBooks[i] = libraryBooks[i]; } else System.out.println("There is no such book"); } else System.out.println("You have reached the maximum number of allowed books"); }
It shows me error: incompatible types - LibrarySystem cannot be converted into ReservedBook. How can I fix it?
Referring Code 1, the book says line 16 of the code removes the element "Three" but line 17 does not remove the element "Four" because of Statement 1. The question is does remove(Object o) method invoke the == or the equals method because statement 1 and 2 seem to be in conflict
Statement 1:
Two objects are equal if their object references point to the same object. (which is nothing but definition of ==)
Statement 2:
The author refers to Statement 1 and says "As mentioned earlier, the method remove compares the objects for equality before removing it from ArrayList by calling method equals."
Java Code:
import java.util.ArrayList; public class DeleteElementsFromArrayList { public static void main(String args[]) { ArrayList<StringBuilder> myArrList = new ArrayList<>(); StringBuilder sb1 = new StringBuilder("One");
I would like to create a java gui (with CRUD elements) that connect to MySQL server DB and display a table records (also insert, edit, delete data to table), and I want to know how create such a gui.
So I am trying to create a code that searches if a word is square free. The user inputs a word (into an array) and then the code is suppose to see if it is square free. A word being square free means that the word doesn't contain any consecutive sub words. For example, "abcabc" is not a square free word because abc is repeated, but "abcdabc" is a square free word because there is a "d" separating the "abc".
So far I have this :
import java.util.Scanner; public class A3Q2 { public static void main(String[] args) { // part (a) of the main Scanner keyboard = new Scanner(System.in);
[Code] ....
I've been trying to experiment with different ways such as checking to see if there any duplicate elements such as,
public static char isSquareFree(char[] word){ for(char i = 1; i < word.length; i++) { if(word[i] == word[i - 'a']) { System.out.println("Duplicate: " + word[i]); } } return word; } }
// for every attribute not mentioned in the rule r enumAtt = ruleE.enumerateAttributes(); while (enumAtt.hasMoreElements()) { Attribute attr = (Attribute) enumAtt.nextElement(); if (isMentionedIn(attr, r.m_test)) {continue;} int M = attr.numValues();
[Code] ....
It repeats only the last rule , why is that !!!!!!
I have a 2D arraylist, named as adjLists, which contains arraylists, containing values like these. Each two values are a "pair" and each third is a "flag" for the pair.
I use code above to search for specified value pairs in these lists. vertexnum is the number of "sub arraylists" in adjLists.
for (int l = 0; l < vertexnum; l++) { if (adjLists.get(l).get(0) == p.x && adjLists.get(l).get(1) == p.y) { for (int h = 0; h < adjLists.get(l).size(); h += 3) { for (int g = 0; g < vertexnum; g++) { if ((vertexSprite[g].getX() + vertexSprite[g].getWidth() / 2) == adjLists.get(l).get(h)
[Code] ....
This code is to search exact values and replace their flag in every occurences. It can not find all the occurences of the values/pair in the lists, it replaces flag value only a few time. Value of score should be incremented with plus 1 after each found occurence, but this code increments it more than the number of matches.
I'm currently in the process of creating a shopping cart simulation. The main GUI consists of two lists, one is a list of the inventory. (products stored within a .dat file which is automatically loaded upon launch) The other is blank and is to model my shopping basket. The idea is to be able to scan items from my inventory into the checkout basket. As this is happening i want a text field i created to dynamically update with the cost of all the items in the basket.
Below is the method for my scan button, which is supposed to perform the above :
public void actionPerformed(ActionEvent evt) { //Get the newly added list values. JList list = productList.getSelectedValuesList(); double totalAddedValue = 0.0; double oldCartValue = 0.0;
ok so for class I'm supposed to Write a class DeleteElements that prints out an array and asks the user which number should be deleted and then deletes that number, if it exists from the array.
The first part tells me to
Step 1 o Start by simply searching the element.
o Pseudocode: -Create an array and populate it with random positive integers. -Print the array to show the user which elements the array contains. -Use a WHILE loop to search the element—a WHILE loop is better than a FOR loop because you can stop when the element is found by using a Boolean value in the loop condition—and also keep track of the location where the element might be found. -If the element is not found, output the error message, “Number not found.” -Otherwise output the message, “Number found at index #.” where # is the index where the element is. -Print out the array.
Example of output: 34 65 12 76 45 39 86 71 67 Number to delete: 76 Number found at index 3
This is what I've got so far but I can't seem to get the "number not found part to print out only once".
public class DeleteElement { public static final int ARR_LENGTH = 10; public static void main(String[] args) { Scanner input = new Scanner(System.in); Random ran = new Random();
[Code] ....
Current output result if value does not exist:
61 89 52 16 20 71 37 91 4 36 Number to delete: 23 Number not found. Number not found. Number not found. Number not found. Number not found. Number not found. Number not found. Number not found. Number not found. Number not found. Current output result if value exists:
97 48 51 22 89 5 42 97 43 96 Number to delete: 89 Number found at index 4
Maybe I'm not understanding the part about the boolean value.
I have tried to print array elements using standard print statement. I am getting errors. How to print them. Here is my code:
class arrayEx1{ public static void main(String args[]) { int a[]=new int[3]; //Declaring Single Diomentional Array a[0]=10; a[1]=20; a[2]=30; int total=a[0]+a[1]+a[2]; System.out.println("Values stored in a[0],a[1],a[2]elements are :" + a[0] a[1] a[2]); System.out.println("Total values of a[0],a[1],a[2]elements is :"+ total); } }
if i give comma (,) in between above print stament (print statement 1) stil i am getting errors.
Currently I am having difficulties styling a particular prime faces element in a JSF application for work. I'm tasked with giving the ui a styling and color scheme acceptable to our project design. However I am finding myself unable to "hook" a particular pf element with an ID so that I can proceed with styling a imported .css file.
I'm trying to style the commandLink button to display in Orange 20px font with Italic but when I inspect the element in chrome after being rendered It doesn't even show its style linked to the assigned ID. The class style for mainMenuItem is being applied to the commandlink but is immediately over written by ui-widget. I'm trying to style that one single component(override/replace ui-widget with the properties in the #loggedInUserID)
Current .XHTML code and the css file has been linked with
<h:outputStylesheet library="css" name="masterPW.css"/> <div class="mainMenuItem"><p:commandLink id="loggedInUserId" styleClass="maserPW.css" value="#{loginController.userFullName}"/> </div><!--End of mainMenuItem-UserID div -->
public class werek4d { public static void main(String[] args) { int counter = 1; int[] anArray = new int[101] ; for (int i = 0; i <= 99; i++){ anArray[i] = i + 1; System.out.println(i + ": " + anArray[i] + " ");
[Code] ....
My aim is to generate a lists containing 1 to 100. I will then count the number of integers divisible by 3. After doing so, I want to delete the integers that are NOT divisible by 3 in the lists. I tried doing it, but I seem to keep on getting the same lists.
I have an ArrayList of tens of thousands of elements, and want to remove the items at a given set of sorted indices like {1,5,29,318,499,583}. It seems like this operation could be performed in linear time and space by first finding a cumulative sum of the shifts needed to move everything to their right positions and then shifting every item. On the other hand, removing and shifting one by one would seem to require many more shifts. Is there a way to do this in Java's ArrayList?
I am working on a assignment that has to do with array lists, it mainly has to do with adding new elements, telling then where it is it located, if the memory block is empty , ect. so far i have been having problems with my indexOf method which should display the array cell number that a input element E is in, and if it is not in there it should display a -1.
public class MyArrayList<E> { private E[] data_store = (E[])new Object[2]; private int sizeofa = 0; private void resize()// makes the array list bigger if need { E[] bigspacemaker = (E[])new Object[data_store.length * 2]; for(int x = 0 ; x< sizeofa ; x++)
[Code] ....
Error message: Exception in thread "main" java.lang.ArrayIndexOutOfBoundsException: 512 at MyArrayList.indexOf(MyArrayList.java:28) at MyArrayListDemo1.main(MyArrayListDemo1.java:26)
I have two ArrayLists and I want to compare them for common elements, and based on the result I want to update the first Arraylist to only have these elements. sort of like the opposite of RemoveAll() which removes elements in common and keep the ones that are unique. so far I thought of using for loop and .contains() in case it was fault,element not present, remove from list. but I was wondering in what other ways, perhaps APIs i can use to do that?
Lets suppose that I pass to the sort method a list of 2 objects of the same class (which implements Comparable interface). I read (in head first java) that one object is compared relative to another with one object calling the CompareTo() while the other object being passed as a parameter to the same method. Now am I safe in assuming that the first object in the list calls the method with the second object being passed as a parameter.And also how does the CompareTo() work if there are more than 2 elements in the list. Which objcet calls the method and which is passed as a parameter?