How To Print Methods In Javafx Using Scenes

Jun 5, 2014

i want to print the results from a method on a scene or anything that will print the results. lets say i have a method that returns a string, i want to print those results using javafx and not by printing to the console

View Replies


ADVERTISEMENT

JavaFX 2.0 :: Keep PrintStream Redirect Across Multiple Scenes

Feb 26, 2015

I have a JavaFX application with multiple scenes. In this applications one scene plays the role of "master" role and the others are loaded according to actions on the "master" scene(buttons,menu items)

The issue is that i need to redirect all the PrintStream activity to a specific TextArea on the "master" scene...

So everything that normally goes to the console to get redirected to that specific TextArea and this should be global,on every scene that is outputting something it should displayed on the specific TextArea on the "master" scene
 
The code i am using right now on the "master" scene is :
 
            Node node =primaryStage.getScene().lookup("#ShowInfo");
            TextArea ta =(TextArea)node;
            FXConsole console = FXConsole.getInstance(ta);
            PrintStream ps = new PrintStream(console, true);
            System.setOut(ps);
            System.setErr(ps);
            System.out.println("Test");
 
For the rest of the scenes i am using the Singleton Pattern to keep the pointing to the Specific TextArea
 
       FXConsole console = FXConsole.getInstance(null);
        PrintStream ps = new PrintStream(console, true);
        System.setOut(ps);
        System.setErr(ps);
        System.out.print("Hello There");
        ps.close();
 
The issue is that i don't like this implementation so ...is there a better solution

View Replies View Related

Keep PrintStream Redirect Across Multiple Scenes

Feb 26, 2015

I have a JavaFX application with multiple scenes. In the application one scene plays the "master" role and the others are loaded according to actions . The issue i have is that i need to redirect all the PrintStream activity to a specific TextArea on the "master" scene, and by "all" i am meaning every PrintStream activity on every scene should be redirected to this specific TextArea . The code i am using on the "master" is :

Node node =primaryStage.getScene().lookup("#ShowInfo");
TextArea ta =(TextArea)node;
FXConsole console = FXConsole.getInstance(ta);
PrintStream ps = new PrintStream(console, true);
System.setOut(ps);
System.setErr(ps);
System.out.println("Test");

I am using the Singleton pattern for the rest of the scenes :

FXConsole console = FXConsole.getInstance(null);
PrintStream ps = new PrintStream(console, true);
System.setOut(ps);
System.setErr(ps);
System.out.print("Hello There");
ps.close();

The issue is that i don't like this implementation ....

View Replies View Related

Print Grades Using Only Methods - Cannot Find Symbol Error

Nov 25, 2014

The program is just a simple one to print grades using only methods. The problem is Im trying to use a returned value in another method but the compiler keeps telling me it cannot find the symbol "mark". the problem areas are marked in blue. I am basically trying to input a value into the keyboard and then use it in another method.

public static void main(String[] args) {
printTitle();
enterMark();
gradeCalculator(mark);
printGrade();

[Code] .....

View Replies View Related

Invoke Some Methods In For Loop In Order To Print Some Info Stored In A List

Apr 28, 2014

I am trying to invoke some methods in a for loop in order to print some info stored in a List. But for some reason, compiler pops a message saying "cannot find symbol - method getEmpID(). You are using a symbol here (a name for a variable, method or class) that has not been declared in any visible scope." But I am pretty sure that method getEmpID (as also getName(), getAfm(), and payment() ) have been declared as public.

Note: My List contains objects of different type (SalariedEmployee, HourlyEmployee). I hope this is not the factor causing this problem.

Java Code:

import java.util.*;
abstract class Employee{
private String name = "";
private String afm = "";
private long EmpID;
static long count=0;

[code]....

View Replies View Related

How To Access Methods From Other Classes Using Buttons In Javafx

Jun 4, 2014

I have a javafx class that has buttons and textfields. Here is the code for a button, and i want the button to make a new object but im having trouble setting the constructor

Label label = new Label("Type");
GridPane.setHalignment(label, HPos.RIGHT);
TextField textField = new TextField();

Label label2 = new Label("First Name");
GridPane.setHalignment(label2, HPos.RIGHT);
TextField textField2 = new TextField();

[Code] ....

after i create the object i will insert the object in an arraylist of person objects

View Replies View Related

Does JavaFX Methods And Objects Works Into Java Application

Nov 22, 2014

I was doing a project in a usual Java Application, but now maybe I have to use some tools that are contained in javafx.scene.media.MediaPlayer so I wonder if can it all work? Will javafx methods and such works?

I have to use javafx.scene.media.MediaPlayer beacuse I have to create a very simple audio player (one jbutton and one jcombobox).

View Replies View Related

JavaFX 2.0 :: Other Methods To Load CSS File From MySQL DB Table

Jan 29, 2015

I am trying to load a CSS file from a mySql DB  table (each row represent a customer that use the application, and each one can set  his own CSS file).

How can I convert the Stream / String that I loaded from the Clob column to something that I can use here XXXX

scene().getStylesheets().add( XXXX );
  
I found alot of examples, but they all talking about files from filesystem, or URLs. My CSS file is in the application memory. I want to prevent the option to write my string as a new file and then read it again. I have no problem with loading the CSS file from database, this part is O.K.

View Replies View Related

How To Make Print Employee Button To Print Info Of Other Class

Apr 12, 2014

Basically the class is supposed to have a static variable that keeps track of the number of companies (numberOfCompanies) that have been created and a static method that returns the value of this variable. I need to have a constructor and a method to addEmployee, a method to printCompany, and a toString method. The addEmployee method will check that there is only 1 salesperson, 2 designers, and 4 manufacturing persons at a time and will check that there are no more than 7 employees of the company.

The addEmployee method will return a String indicating what the error is (i.e. "There is already a sales person in this company") or a null if the employee was added. If attempting to name a third company, an error message will be shown. what i have so far but my print company mmethod returns null company class :in which i am obliged to use inputdialog because it says that it cannot return void when i use the showmeassage diaolog.

company class:

import java.util.ArrayList;
import javax.swing.JOptionPane;
public class Company {
private ArrayList<Employees> list ;
private static int numberOfCompanies;

[Code] ....

error message when print button is clicked:

Exception in thread "AWT-EventQueue-0" java.lang.RuntimeException: JOptionPane: parentComponent does not have a valid parent
at javax.swing.JOptionPane.createInternalFrame(Unknown Source)
at javax.swing.JOptionPane.showInternalOptionDialog(Unknown Source)
at javax.swing.JOptionPane.showInternalMessageDialog(Unknown Source)

[Code] ......

View Replies View Related

Two Threads - One Will Print Odd And Other Will Print Even Numbers In Sequence

Jul 25, 2014

I want to create two thread one thread will print odd number and another thread will print even number. but the number should be in a sequence like

1 2 3 4 5 6 7 8 9 10

View Replies View Related

Using Methods Within Methods

Jan 10, 2014

I have written two methods called "contains" and "overlaps". The method "contains" is to detemine whether a point (x, y coordinate) is within the surface area of a square object. The location of the square objects is determined by the location of the upper left corner of the square.The method "overlaps" is to determine whether two square objects overlap each other.

I have written these as two separate methods. However I want to change the method "overlaps", so that it uses the method "contains" within it. I.e. using a method within a method. Thereby hopefully making the "overlaps" method a bit more clear and easy to read.

Java Code:

/** Returns true of the point with the coordinates x,y, are within the square. */
public boolean contains(int x, int y){
int sx = location.getX(); //"location" refers to a square object
int sy = location.getY(); // getX() and getY() are to find it's coordinates
// "side" is the side length of the square
if (x >= sx && x <= (sx + side) && y >= sy && y <= (sy + side)){

[code]....

View Replies View Related

How To Run Two Methods At The Same Time

Jun 22, 2014

Below is the main class of a project ive been working on, the goal is to start a countdown specified by the user. When the countdown reaches zero the base drops in the song that is being played. (Its not done yet) The main problem that arises is the fact that my song plays, and AFTER that, the timer starts.

Output:

Please input countdown in HH:mm:ss format.
00:00:41
Start?
Yes

The name of of the song is: Skrillex & Damian "Jr Gong" Marley - "Make It Bun Dem"

The time of base drop is: 00:00:41 //Song starts here

//Song is done
//Then timer starts
00:00:41
00:00:40
00:00:39

[code].....

View Replies View Related

Using Methods Of Interface

Feb 5, 2014

I have following code. In this code CSClient is an interface. All methods of CSClient are implementaed in CSClientImpl class. Do I not need CS Client Impl imported in this code ?

How can I call getBranch() of CSClient, which is not implemented in CSClient as " this. getCsClient(). get Branch (new CSVPath(vpath), true);" ? This code works fine without any error in eclipse.

How can a method getBranch(), which is implemented in CSClientImpl class be used in this code without importing CSClientImpl ?

package com.rbc.teamsite.client;

import java.io.File;
import java.io.FileWriter;
import java.io.InputStream;
import java.io.PrintWriter;
import java.text.SimpleDateFormat;
import java.util.ArrayList;

[code]....

View Replies View Related

Methods That Do And Do Not Return Any Value

Oct 8, 2014

Write the header for a method named send that has one parameter of type String, and does not return a value.Write the header for a method named average that has two parameters, both of type int, and returns an int value.

View Replies View Related

Methods Of Using ItemListener

Dec 1, 2014

I have seen these two methods of using ItemListener. I am curios which is better and why. What are the differences?

ItemListener a;
Choice ce = new Choice();
ce.addItemListener(a);

[code]....

View Replies View Related

Put Some Of Code Into Methods

Apr 14, 2015

I have had to create a text analyser. I have created the program but it is all within the main method. The specification states that I have to have at least two methods within my Program.

import java.io.*;
import java.text.SimpleDateFormat;
import java.util.*;
import javax.swing.*;
import javax.swing.filechooser.FileNameExtensionFilter;
public class Analyser {
public static void main(String[] args) throws FileNotFoundException,
UnsupportedEncodingException {

[code]....

View Replies View Related

How To Add Methods In Attachments

May 1, 2015

Java Code:

package methods;
import java.util.*;
import javax.swing.*;
public class Methods {
public static void main(String[] args) {
// TODO Auto-generated method stub
char choicee2;

[Code] .....

View Replies View Related

Arrays Outside Of Methods

Aug 22, 2014

I'm working on a side project, which will eventually hopefully be a Pokedex, and I've just been going to it at the end of every chapter and using the stuff I've learned to work on it.So I just read chapter 3, which is all about variables and teaches how to use arrays.

my question is, does an array have to be declared inside a method? Because I'm trying to create an array inside a class without any methods and without the main, and I continuously get errors. Here's a quick working of my code that won't compile.

class blah {
blah a[] = new blah[7];
a[0] = new blah();
}

The error message focuses on a[0] = new blah(); Telling me the 0 should be a ], the = is an illegal start of type, so on and so forth. The program compiles completely fine if it's within a method, like this:

class blah {
void a() {
blah a[] = new blah[7];
a[0] = new blah();

}

}

Or if I have public static void main (String[]args); But I'm trying to practice working outside of main.So does an array have to be within a method,

View Replies View Related

Can Use Same Files In Different Methods

Oct 20, 2014

I'm reading from one file and writing it into another.I then want to delete the first file and use the second (it will get the first files name) .My sample java file works completely fine but it doesn't work on my actual file -it looks like it populates my test file like it should but it does not delete the original. Occasionally DMap.xml won't delete either - I try and rename it and normally I get the error of 'the file is open in Java platform SE binary' so the files is open somewhere - but I thought I had closed it correctly so have I done that wrong? I have put the basic code :

public class DeleteEnvironmentsWindow extends JDialog {
String xmlFile = "c:DMap.xml";
String fromFile =xmlFile
public void removeEnvironment(){
DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
DocumentBuilder builder = null;
Document doc = null;

[code]....

View Replies View Related

I/O Printing From Two Methods

May 3, 2015

Lets say in method 1 I want to print the numbers 1 - 10. Easy stuff. I then print that to the

PrintStream outFile = new PrintStream(new File ("output5_01")); I declared.

Now I'm in another methods, How do I print lets say 11- 20 without erasing the first methods printed results?

so my desired results would be

outFile
-------------------------------
(From 1st method) 1- 10
(From 2nd method) 11-20

As of now the second method always over writes the first. None of my books cover this and its very frustrating when the entire code is done but this won't let me write to the file

View Replies View Related

Why Can't Java Run Two Methods

Feb 14, 2015

I'm new to Java, and I just created this script:

public class HelloWorld {
public static void main(String[] args) {
String firstLine;
String startUp;
int hour, minute;

[code]...

Every time I try to run this is eclipse, I only get the first part, so it reads in the console: "Hello, world. The time is now 9:15. I'm tired."I want it to read: "Hello, world. The time is now 9:15. I'm tired. (new line) Today is Wednesday."

View Replies View Related

Can Using Same Files In Different Methods

Oct 20, 2014

know my code sample file of renaming a file and deleting an original file will work fine but when I use the code within my main java file - it appears to populate the file that I want populating fine but wont delete the origional. I have everything on my c drive so I can very easily keep track of what files I do and don't have.

Can using the same files in different methods cause problems? (Beginning Java forum at JavaRanch)

View Replies View Related

JSF :: How To Invoke JavaBean Methods In JSP

Sep 24, 2014

I have a requirement , as part of that i have to get one UI value (JSP/JSF) , due to code avaialability the value i can't get in JSP directly for that i uses Javascript that value have to pass to JavaBean method which return some string. Codes have given below :

JavaBean method:

public void setExchangeCurrency(String exchangeCurrency) {
this.exchangeCurrency = exchangeCurrency;
}

/**
* @return the exchangeCurrency
*/
public String getExchangeCurrency(String cutryCode) {
ResultSet resultSet = null;
String sqlQuery = null;

[Code] ....

View Replies View Related

Passing Values To Different Methods?

Mar 1, 2015

I am trying to pass the values for UPPER_BOUND and LOWER_BOUND from the main method into the getValidNumber method. However, I'm not sure how to do this. The rest of the code is correct as far as I know, I just need to get the values for the bounds into the getValidNumber method. How would I do this? the notes in the main method explain what I need to do.

public static void main(String[] args) throws FileNotFoundException {
Scanner kb = new Scanner (System.in);
final double LOWER_BOUND = 0;
final double UPPER_BOUND = 100;
//Call the getValidNumber method, passing it the values LOWER_BOUND and UPPER_BOUND.
//Take the returned value and store it in a variable called num.
//Print out the value of num (here in the main method)
 
[Code] .....

View Replies View Related

Creating Objects From Methods?

Mar 20, 2014

public class demo
{
Public class static void main(String[]args) {
//Creating a variable that will be a reference to the object
Peoples person_one;

[Code] ....

I have assembled this code below that has a void method which will creat a new object. Problem I encounter is that in

Create_object(person_one);

the person_one has an error saying not initialized. I'm jus trying to learn on my own ways here and practice so may know what's wrong with this? I know I can use a return object from methods but what about this approach?

View Replies View Related

Methods In Object Class

Jan 16, 2014

We know that all classes in Java extend the Object class. But methods in Object class are declared as public.I think if they were declared as protected, then also there wont have been any issue. So, what is the reason behind making them as public?

View Replies View Related







Copyrights 2005-15 www.BigResource.com, All rights reserved