Call String from another method
hey,
Im pretty new to java and Im having problems with calling a String from another method
I have two public voids, in one of them I have a String which I wanna use in another method.
Thanks
here is some of my code:
public void getOrder() {
try {
DocumentBuilderFactory docBuilderFactory = DocumentBuilderFactory.newInstance();
DocumentBuilder docBuilder = docBuilderFactory.newDocumentBuilder();
Document doc = docBuilder.parse(new File("c:/orders.xml"));
// normalize text representation
doc.getDocumentElement().normalize();
System.out.println("Root element of the doc is " + doc.getDocumentElement().getNodeName());
// lees orders
NodeList orderlijst = doc.getElementsByTagName("order_naam");
System.out.println("totale aantal orders : " + orderlijst.getLength());
// Element orderitem = (Element) orderlijst.item(0);
System.out.println("name=" + doc.getElementsByTagName("order_naam").item(0).getFirstChild().getNodeValue());
String st =doc.getElementsByTagName("order_naam").item(0).getFirstChild().getNodeValue();
public void createGUI () {
this.removeAll();
lbltest = new JLabel();
lbltest.setBounds(20, 40, 150, 20);
lbltest.setFont(new Font("Verdana", Font.BOLD, 12));
this.add(lbltest);
i want to use the String st in the jLabel in createGUI
Similar Messages
-
Calling servlet from another method
Hi,
I am writing a program which requires executing another servlet from within
thie main program. I do not care to return the information from the servlet
request.
http://usx500.crn.st.com:7000/TPMCenter_V2/insertAutomationValue.do?reqCode=confirmed
Thanks for the help.The reason I continue posting this question, is because I cannot find a solution.
I have looked through the link provided, as well as many other solutions on the web,
none which have been successful. Following are two solutions which I have tried, and
niether have worked. I still am in need of some help in resolving this. If you would like
to assist me in this it would be greatly appreciated.
Dr Clap--
If you do not have a suggested solution, simply do not reply.
Solution 1 ---
try {
// Construct data
String data = URLEncoder.encode( "reqCode", "UTF-8") + "=" + URLEncoder.encode( "show", "UTF-8" ) ;
// Create a socket to the host
String hostname = "usx500.crn.st.com" ;
int port = 7000 ;
InetAddress addr = InetAddress.getByName( hostname );
Socket socket = new Socket( addr, port );
// Send header
String path = "/TPMCenter_V2/insertAutomationValue.do";
BufferedWriter wr = new BufferedWriter( new OutputStreamWriter( socket.getOutputStream(), "UTF8" ) ) ;
wr.write( "POST " + path + " HTTP/1.0\r\n" );
wr.write( "Content-Length: " + data.length() + "\r\n" ) ;
wr.write( "Content-Type: application/x-www-form-urlencoded\r\n" ) ;
wr.write("\r\n");
// Send data
wr.write(data);
wr.flush();
wr.close();
} catch (Exception e) {
e.printStackTrace() ;
}Solution 2 ---
try{
URLConnection c = new URL("http://usx500.crn.st.com:7000/TPMCenter_V2/insertAutomationValue.do?reqCode=show").openConnection();
c.connect();
}catch(MalformedURLException murle){
System.out.println(murle);
}catch(IOException ioe){
System.out.println(ioe);
} -
How do I access array elements in one method from another method?
Hi all!
How do I access the array's elements from another method so that method 2 can have access to method 1's array elements? Thanks for any help!
I am trying to create a simply program that will use a method to create an array and a SEPARATE method that will sort the array's elements (without using java's built in array features). I can create the program by simply having one method and sorting the array within that same method, BUT I want to sort the array from another method.
Here's my code so far:
public class ArraySort {
public static void createArray(int size){
double myArray[] = new double[size]; //create my new array
for(int j=0; j < myArray.length; j++)
myArray[j] = (200.0 * Math.random() + 1.0); //fill the array with random numbers
public static void sortArray(){
// I WANT THIS METHOD TO ACCESS THE ARRAY ELEMENTS IN THE METHOD ABOVE, BUT DON'T KNOW
// HOW???? Please help!
public static void main(String[] args) {
createArray(4); //call to create the array
}Thanks again!
- JohnnyThanks for the help all! I ve managed to get the program working, using java's built in array sort, but when i try to call on the array sort method from WITHIN my main method, nothing happens!
Can somebody please tell me why I am not able to call on the sort method from within my main class???? Thanks!
public class ArraySort {
public void createArray(double[] arrayName, int size){
double myArray[] = new double[size]; //create new array
for(int j=0; j < myArray.length; j++)
myArray[j] = (200.0 * Math.random() + 1.0); //populate array with
} //random Numbers
sortArray(myArray);
} //Sort array(if I delete this & try to use it in Main method --> doesn't work???
public void sortArray(double[] arrayName){
DecimalFormat time = new DecimalFormat("0.00");
Arrays.sort(arrayName); //sort array using Java's built in array method
for(int i = 0; i <arrayName.length; i++)
System.out.println(time.format(arrayName)); //print arary elements
public static void main(String[] args) {
ArraySort newArray = new ArraySort(); //create a new instance
double myArray[] = new double[0]; //create a new double array
newArray.createArray(myArray,4); //build the array of indicated size
//newArray.sortArray(myArray); //This will not work???? WHY?????// -
To read string from another file
Dear friends
I am working on a project where i need to read log files which are there on my C drive.
I got a folder and from that i need to read string from another folder and name them as URL,TS etc..so any body have any idea about this...I have no idea what you're even trying to do. Can you try explaining your problem more clearly and in more detail?
-
We have a 5s active on our account. After turning on a previously active 4s (it had the same number) The 5s can no longer place call and when you call it from another phone the 4s rings, but will not pick up. Texting over the cell networks works fine. Any suggestions??
hens0861,
Hmm, let's ensure this is working as it should be! So what phone should be active on your account? Did you switch the devices online or how to did you activate the 5s? Please share details.
KarenC_VZW
Follow us on Twitter @VZWSupport -
Calling package from another package
Hi gurus,
Quick question
Say i m in user1 schema.
I want to call package from another package in the same schema. So do i need to grant permission to the calling package to call.Thank you!!Why don't you test it?
create or replace package pack2
is
procedure t2;
end;
Package created.
create or replace package body pack2
is
procedure t2
is
begin
dbms_output.put_line('Inside Pack2 And t2');
end;
end;
Package Body created.
create or replace package pack1
is
procedure t1;
end;
Package created.
create or replace package body pack1
is
procedure t1
is
begin
pack2.t2;
dbms_output.put_line('Inside Pack1 And t1');
end;
end;
Package Body created.
begin
pack1.t1;
end;
Inside Pack2 And t2
Inside Pack1 And t1
Statement processed.
0.11 secondsRegards.
Satyaki De -
Using a variable from another method within another method
I have a couple methods. In the beginning of the class I declared the double variables. Then I have a method1 that in that class that changes those double variables. Then the last method2 runs, and is suppose to print information to the screen with the changed variable information all being called from another class. How do I get those changed double variables to be read in method2?
Sorry about all that, when I paste it in from the compiler it's skews it some, but hopefully this should be more readable
* Project Filename: Lab1s2
* Program Filename: Lab1s2.java
* I/O Files used:
* Fuction: This program will use interactive input to ask cost of a
* product in dollars and cents (eg. 17.50). If the product
* is not less than $100.00, an error message will be displayed
* and input will be requested again. Once a valid value is
* given, the program will calculate the fewest bills and change
* to be returned if the customer gives a $100.00 bill.
* Formulas: (100 - amount = change)
* Algorithm:
* Purpose: The main method calls other methods found in the MoneyXX class
* that will accomplish the function of the project.
public class Lab2sl
public static void main( String[] args ) // main method begins program execution
Money2sl myMoney2sl = new Money2sl(); // create myMoney2sl object and assign it to Money2sl
myMoney2sl.inputSL();// calls input method and pass argument
myMoney2sl.changeSL(); // calls change method
System.out.println(); // output a blank line
myMoney2sl.outputSL(); //calls outputSL to show results
* Project Filename: Money2SL.java
import java.util.Scanner;
import java.util.Calendar;
public class Money2sl
Scanner input = new Scanner( System.in ); // create Scanner to obtain input from command window
private double change,
amount; // instant variable, stores amount
private double twentyD = 20.00;
private double tenD = 10.0;
private double fiveD = 5.0;
private double dollar = 1.0;
private double quarter = 0.25;
private double dime = 0.10;
private double nickel = 0.05;
private double penny = 0.01;
private double numTwentyD;
private double numTenD;
private double numFiveD;
private double numDollar;
private double numQuarter;
private double numDime;
private double numNickel;
private double numPenny;
// inputSL() method gets amount, checks to see if it is under $100, stores amount into variable
public void inputSL() //input method
Calendar dateTime = Calendar.getInstance(); // get current date and time
//print date and time
System.out.printf( "%s\n", "nothing" );
System.out.printf( "%1$ta, %1$tB. %1$te, %1$tY %1$tr\n\n", dateTime );
//print output
System.out.println( "Please enter the amount of money (less than $100) that you will spend: "); // prompt
amount = input.nextDouble();
while ( amount > 100 )
System.out.println( "error - enter amount less than $100");
System.out.println( "Please enter the amount of money (less than $100) that you will spend: "); // prompt
amount = input.nextDouble();
} // end inputSL method
// changeSL() calculates change from amount entered out of $100
public void changeSL()
change = 100 - amount; // calculate change
while(change > 0)
if ( change - fiveD >= 0 )
numFiveD ++;
change -= fiveD;
if ( change - fiveD >= 0 )
numFiveD ++;
change -= fiveD;
if ( change - dollar >= 0 )
numDollar++;
change -= dollar;
if ( change - quarter >= 0 )
numQuarter ++;
change -= quarter;
if ( change - dime >= 0 )
numDime ++;
change -= dime;
if ( change - nickel >= 0 )
numNickel ++;
change -= nickel;
if ( change - penny >= 0 )
numPenny ++;
change -= penny;
} // end changeSL method
//outputSL() displays original amount, change dollar amount, and change in individual bills and coins
public void outputSL()
System.out.printf( "$%.2f dollars will return $%.2f, which is: ",
amount, change );
System.out.println(); // blank line
System.out.println(); // blank line
if ( numTwentyD > 0 )
if ( numTwentyD > 1)
System.out.println( numTwentyD + " twenty dollar bills" );
System.out.println( numTwentyD + " twenty dollar bill" );
if ( numTenD > 0)
if ( numTenD > 1 )
System.out.println( numTwentyD + " ten dollar bills" );
System.out.println( numTwentyD + " ten dollar bill" );
if ( numFiveD > 0)
if ( numFiveD > 1 )
System.out.println( numFiveD + " five dollar bills" );
System.out.println( numFiveD + " five dollar bill" );
if ( numDollar > 0)
if ( numDollar > 1 )
System.out.println( numDollar + " one dollar bills" );
System.out.println( numDollar + " one dollar bill" );
if ( numQuarter > 0)
if ( numQuarter > 1 )
System.out.println( numQuarter + " quarters" );
System.out.println( numDollar + " quarter" );
if ( numDime > 0)
if ( numDime > 1 )
System.out.println( numDime + " dimes" );
System.out.println( numDime + " dime" );
if ( numNickel > 0)
if ( numNickel > 1 )
System.out.println( numNickel + " nickels" );
System.out.println( numNickel + " nickel" );
if (numPenny > 0)
if ( numPenny > 1 )
System.out.println( numPenny + " pennies" );
System.out.println( numPenny + " penny" );
} -
No components painted when calling setVisible from another frame
Hello,
I have a problem here so I could use a little help with this one.
I'm having a JFrame with a button on it. When the user clicks this button, a JDialog opens. When I call the setVisible(true) method from within the constructor of the JDialog, there is no problem. But due to some reasons (concerning modal dialog) I want to call the setVisible method from withing the actionPerformed method of the button which is located on the JFrame.
I created a little test scenario to show this behaviour:
public class Main
public static void main(String[] args)
new TestGUI1();
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
public class TestGUI1 implements ActionListener
JFrame frame = new JFrame("Test 1");
JPanel panel = new JPanel();
JTextArea textarea = new JTextArea();
JButton button = new JButton("Ok");
public TestGUI1()
frame.getContentPane().setLayout(new BorderLayout());
panel.setLayout(new FlowLayout(FlowLayout.RIGHT));
frame.getContentPane().add(panel, BorderLayout.SOUTH);
frame.getContentPane().add(textarea, BorderLayout.CENTER);
panel.add(button);
button.addActionListener(this);
frame.setSize(300,300);
frame.setVisible(true);
public void actionPerformed(ActionEvent e)
if(e.getSource() == button)
TestGUI2 tg2 = new TestGUI2(frame);
tg2.setVisible(true);
import java.awt.event.*;
import java.awt.*;
import javax.swing.*;
public class TestGUI2 extends JDialog implements ActionListener
JDialog dialog = new JDialog();
JPanel panel = new JPanel();
JTextField textfield = new JTextField(20);
JButton button = new JButton("Close");
public TestGUI2(JFrame frame)
super(frame, "Test 2");
dialog.getContentPane().setLayout(new BorderLayout());
panel.setLayout(new FlowLayout(FlowLayout.RIGHT));
dialog.getContentPane().add(panel, BorderLayout.SOUTH);
dialog.getContentPane().add(textfield, BorderLayout.CENTER);
panel.add(button);
button.addActionListener(this);
dialog.pack();
public void actionPerformed(ActionEvent e)
if(e.getSource() == button)
dialog.dispose();
}So when you click the 'Ok' button on the JFrame, you will see only the title of the JDialog (= Test 2). When I resize it with the mouse, then only a gray area is shown. No components visible.
What could be the reason here?
ThxTestGUI2 extends JDialog, so it is a dialog, and you can call setVisible(true) on it
within TestGUI2 you create another JDialog dialog, and add all to this dialog,
which is not shown. get rid of 'dialog' and your constructor will look like this
public TestGUI2(JFrame frame)
super(frame, "Test 2");
getContentPane().setLayout(new BorderLayout());
panel.setLayout(new FlowLayout(FlowLayout.RIGHT));
getContentPane().add(panel, BorderLayout.SOUTH);
getContentPane().add(textfield, BorderLayout.CENTER);
panel.add(button);
button.addActionListener(this);
pack();
} -
Call Dialog from another dialog
hi everyone
can anybody tell me how can we call one dialog from another dialog..
Is it possible...???
if it is, how we can we do ...please tell me with example
thanks in advanceIs it possible...???yes
if it is, how we can we do ...please tell me with example
public static void main(String[] args) {
JDialog parent;
for (int i = 0; i < 5; i++) {
JDialog d = new JDialog(parent, true);
parent = d;
d.setVisible(true);
} -
I need to make a several calls to the methods inside EJB1 from EJB2. I was getting
the remote reference of the EJB2 inside the ejbCreate() of the EJB1, is it a good
practice ?? If not, do I need to get remote reference of the EJB2 every time I
need to call EJB2 method??
Thanks in advance.To refer a Ejb from another Ejb include <ejb-ref> in ejb-jar.xml
<session>
<ejb-name>Ejb1</ejb-name>
<ejb-ref>
<ejb-ref-name>Ejb2</ejb-ref-name>
<ejb-ref-type>Entity</ejb-ref-type>
<home>com.ejb.Ejb2Home</home>
<remote>com.ejb.Ejb2</remote>
</ejb-ref>
<session>
Include a <reference-discriptor> in weblogic-ejb-jar.xml
<weblogic-enterprise-bean>
<ejb-name>EjbSession</ejb-name>
<reference-descriptor>
<ejb-reference-description>
<ejb-ref-name>Ejb2</ejb-ref-name>
<jndi-name>com.ejb.Ejb2Home</jndi-name>
</ejb-reference-description>
</reference-descriptor>
</weblogic-enterprise-bean>
In Ejb1 bean class refer to Ejb2 method with a remote reference to Ejb2.
InitialContext initialContext = new InitialContext();
Ejb2Home ejb2Home = (Ejb2Home)initialContext.lookup("com.ejb.Ejb2Home");
Ejb2 ejb2 = ejb2Home.findByPrimaryKey();
Alex Pratt wrote:
I need to make a several calls to the methods inside EJB1 from EJB2. I was getting
the remote reference of the EJB2 inside the ejbCreate() of the EJB1, is it a good
practice ?? If not, do I need to get remote reference of the EJB2 every time I
need to call EJB2 method??
Thanks in advance. -
Delay in the Response Group Rining / Call Pickup from another Extension
Dear All,
We have just finished a deployment of Lync 2013 with Sonus 1000 as the Mediation Gateway, we have deloyed polycom VVX 600 phones,
We have two lines E1 and 5 Fxo lines (with same Pilot Number)
I would like the Receptionist to have both E1 DID number and FXO number and her phone to ring when the calls comes from DID line as well as FXO,
I have the below scenario
1) Currently the setup is that Receptionist is configured with the E.164 DID number : (Line URI is Tel:+971XXXX500;ext=500), which work perfectly fine
2) We have added receptionist in Response Group , and setting are (Formal,10 sec , Attendant)
The issue :
1) Call forwarding does not work on Response Group (which is by design it self)
2) When a call comes from the outside to FXO it goes to response group , (there is Music played and the ring on reception is delayed by 2-3 secs) ,
Customer does not want this delay , it should ring immediately with no music,
3) If the receptionist moves from one location to any other location to another , she should have the ability to remotely perform call forward to that extension by simply dialing few codes on the phone ( I already told customer
about PIN based authentication, by customer does like the idea of signing in or signing out)
In DIRE NEED OF HELP,
Regards,
Hasan Reza,Hi,
Did the issue only happen for IP Phone in Response Group or also happen for Lync client in Response Group?
If the issue only happen for IP Phone, it seems to be an known issue. Please Make sure Lync Server update to the latest version and then test again.
Here are several similar case may help you:
https://social.technet.microsoft.com/Forums/lync/en-US/196375a5-3ae9-4452-acbe-2679a8deef80/delay-when-response-group-calls-are-answered
https://social.technet.microsoft.com/Forums/lync/en-US/70306bf5-fcd3-488a-b6f4-2eee1bcc0457/lync-2010-ip-phone-calls-and-response-group-delays
Best Regards,
Eason Huang
Please remember to mark the replies as answers if they help, and unmark the answers if they provide no help. If you have feedback for TechNet Support, contact [email protected]
Eason Huang
TechNet Community Support -
Call variable from outside method
I have a method for a listSelectionListener with a variable in it called "results", I want to be able to get the information from this variable outside of this method. In my main class alled "gifts" I have a TextArea and I want "results" to be displayed in it but I can't get results into it because it's in a seperate method. Anyone know how I can do this?
Heres some relevant code:
public Gifts()
super( "Spiritual Gift Database" );
try
Class.forName(JDBC_DRIVER);
conn = DriverManager.getConnection(DATABASE_URL);
stat = conn.createStatement();
ResultSet rs = stat.executeQuery("SELECT heading1 FROM demo");
Vector vector1 = new Vector();
while(rs.next()) vector1.add(rs.getObject(1));
container = getContentPane();
container.setLayout( new FlowLayout() );
nameListPanel = new JPanel();
statListPanel = new JPanel();
buttonPanel = new JPanel();
nameList = new JList(vector1);
nameList.setVisibleRowCount( 9 );
nameList.setPrototypeCellValue("XXXXXXXXXXXX");
nameList.addListSelectionListener(
new ListSelectionListener()
public void valueChanged(ListSelectionEvent event)
try
ResultSet resultSet = stat.executeQuery("SELECT * FROM demo");
StringBuffer results = new StringBuffer();
ResultSetMetaData metaData = resultSet.getMetaData();
int numberOfColumns = metaData.getColumnCount();
for(int i = 1; i<=numberOfColumns; i++)
results.append(metaData.getColumnName(i) + "\t");
results.append("\n");
while (resultSet.next())
for(int i = 1; i<= numberOfColumns; i++)
results.append(resultSet.getObject(i) + "\t");
results.append("\n");
catch(SQLException sqlException)
JOptionPane.showMessageDialog(null,sqlException.getMessage(),
"Database Error", JOptionPane.ERROR_MESSAGE);
System.exit(1);
statList = new JTextArea(results.toString());
add = new JButton("Add Entry");Declare you variable at the class level instead of the function level, then you can see if from any method in the class.
Paul -
Recieve value from another method
hello,
I have a method like this
public String loadUser(String x){ //Init in = new Init(); String abc = x; currentUser = currentUser+abc; System.out.println("Currentuser "+currentUser); return currentUser; }I have another method
public void prepareSession(Session session) { //System.out.println("Reached b value "+user); super.prepareSession(session);}How can I recieve value of first method loadUser in my second method?
I do not want to add another parameter to prepareSession method because it is over riding.
How can I achieve this?
ThanksThe problem is:
public class AppModuleImpl extends ApplicationModuleImpl {
String user = null;
String bn; //This is empty and has nothing to do with
String h = null; // |
String ops = null; // |
// |
public String loadUser(String x){ // |
String bn = x; // this. They are two different varaiables.
System.out.println("Currentuser "+bn);
return x;
public void prepareSession(Session session) {
super.prepareSession(session);
String tg = loadUser(bn);
AppModuleImpl appl = new AppModuleImpl();
System.out.println("currentUser ??? "+tg);
}That's why bn at the end is empty
BTW I didn't notice You put anything into bn
Message was edited by:
hellbinder -
Reaching a variable from another method
I want to "reach" the String variable 'a' from the method 'aMethod()'.
What am I doing wrong when writing:
String newVariable = aMethod().a;
/CullumYou can't reach local variables.
Kaj -
Can we call wizard from another wizard
Hello Everyone,
Can we call wizard function module from another wizard function module?
i tried to call, but the road maps and the documentation part of the screen is gettting overlapped.
Are there any parameters to be changed that the wizards can be called within a wizard?
Points assured.
Thanks in advance,
PrashantHi,
Do you mean you want to access BAPI in ABAP report?
If yes, then YES we can call,
1.Create a report -> In pattern write your BAPI name.
2. It is like your FM , Read correspoding BAPI documentation
3. Fill required parametes.
4. Test run and if successful , final run it.
And from Outside,
You have to establish a connection and create a wrapper and access using avaialble APIs.
Reward if useful!
Maybe you are looking for
-
And when you right click on a link, the only options are "open link in new tab" or "open link in new window". I want to open the link in the same tab, I don't need 16 tabs opened at the same time.
-
Multiple ipads but 1 billing card
hi all ive got 4 ipads in my house all different email adresses but 1 card mine i use it as and when the kids need to p urchase things then remove card i went on tonight to purchase something and it told me to contact customer support please help has
-
Adobe Premiere Pro cc not captured Audio but throgh BMD Card out to external Monitor
Windows 7 Ultimate and Blackmajic Studeo 2 card Adobe Premier Pro cc7.2 my Video capture (Analog) through card but Audio not captured but also external out video and audio perfectly Through Blackmajic Decklink studeo card with desktop video 9.8 softw
-
Move from one text box to another w/o using tool box
I'm constantly needing to move from one editable text box to another editable text box -- or to a vector graphic and back to a text box. I'd love a keyboard shortcut to move around if there is one. Having to constantly click the cursor in the tool b
-
Encoding MPEG2-DVD from dpx image sequences produced random encoding artifacts
I'm using PPro CS 6. I've exported my 90 minute film as a DPX sequence. This image sequence is effectively my master. I then export this DPX sequence as a MPEG2-DVD and I get the following artifacts on random frames. It happens whether I'm exporting