Latest Tutorials| Questions and Answers|Ask Questions?|Site Map



Home Answers Viewqa Java-Beginners Use varibles from another class

Have Programming Question? Ask it here!
 
 
 


Jorge
Use varibles from another class
2 Answer(s)      3 years and 5 months ago
Posted in : Java Beginners


**I have two classes. class 1:** public class askfigures extends JFrame {

method from class1: public void button4ActionPerformed(ActionEvent e) {String n1 = textField1.getText(); int number = Integer.parseInt(n1); System.out.println("dsf") this.dispose(); Askvalues values = new Askvalues(); values.initComponents();

I want to use the variable number in another class.

another class: public class Askvalues extends JFrame {

in the method: private void button4ActionPerformed(ActionEvent e){


Advertisement
View Answers

March 30, 2011 at 12:04 PM


import java.awt.*;
import javax.swing.*;
import java.awt.event.*;

class AskFigures{
        AskFigures(){
        JLabel lab=new JLabel("Enter Number: ");
        final JTextField text=new JTextField();
        JButton b=new JButton("Get");
        b.addActionListener(new ActionListener(){
            public void actionPerformed(ActionEvent e){
            String value=text.getText();
            int num=Integer.parseInt(value);
            AskValues v=new AskValues(num);
            }
        });
        JFrame f=new JFrame();
        JPanel p=new JPanel(new GridLayout(2,2));
        p.add(lab);
        p.add(text);
        p.add(b);
        f.add(p);
        f.setVisible(true);
        f.pack();
    }
    public static void main(String[] args) 
    {
        new AskFigures();
    }
}
class AskValues{
    AskValues(int number){
        JLabel lab=new JLabel();
        lab.setText(Integer.toString(number));
        lab.setBounds(10,10,100,20);
        JFrame frame=new JFrame();
        frame.setLayout(null);
        frame.add(lab);
        frame.setSize(100,60);
        frame.setVisible(true);
    }    
    }


March 30, 2011 at 7:46 PM


Eres un genio!!! You're a genious. thankyou so much!!! I get it now,

the class that send the variable I should create an object to send it. and the receiving it I have to get through the method with it's type "eg.(int)"



Related Tutorials/Questions & Answers:
Use varibles from another class
Use varibles from another class  **I have two classes. class 1:** public class askfigures extends JFrame { method from class1: public void... in another class. another class: public class Askvalues extends JFrame
how to use string of one class into another Class
how to use string of one class into another Class  I created textField(JTextField t1=new JTextField();(it is in ClassA. The input of this textField i.e t1.getText() is to be used in different(another Class say in ClassB. How can
Advertisements
how to pass a string from one class to another
string from one class to another. import java.util.*; class A{ static String... String from class A: "+b); } }   Here is another example of passing string from one class to another. import java.io.*; class Class1 { public
get the value from another class - Java Beginners
get the value from another class  Hello to all, I have stupid question. I have main.java and ConfigXML.java(read my config xml file). Code from...)).getNodeValue().trim(); from my ConfigXML.java in main.java. Sorry for my bad
How to call the run method from another class?
How to call the run method from another class?  Sorry... run() { new FereastraPrincipala().setVisible(true); from the class... want to call this from AdaugaComanda.java, so that changes can be seen
How to pass variable from one class to another in java
How to pass variable from one class to another in java  How to pass variable from one class to another in java?   Example: public class...; } } //Another class Class2. public class Class2 { public static void main(String
ArrayList as an argument to another class
ArrayList as an argument to another class  how do you pass arraylists as arguments to another class, and how does the method/class accept this arraylist for use
Java call method from another class
Java call method from another class   ...; methods of another class. For this we have created two java files..., multiply, division and modulus have been created inside the class CallingMethod
how to use one form out of multiple form from one jsp to another jsp
how to use one form out of multiple form from one jsp to another jsp  Hi All. please give me your valuable advise for below requirement.. I have... one form from abc.jsp as it is to another .jsp(say def.jsp).Your advise
Get JTextField value from another class
Get JTextField value from another class   ... value from other class. For this, we have created two classes ClassA.java and ClassB.java. In ClassA, we have defined a textbox 'text1' that will get the value from
how to pass class variable to another class
how to pass class variable to another class  i need to access a variable from a class to another class currently running at the same time. using... the following code: import java.util.*; class A { static int regd; static int
are my declared varibles right - Java Beginners
are my declared varibles right  here is what i have so far juswt wondering if my varibles are correct. public class Bug { public Bug(int initialPosition) { } public void move() { } public void
Use of Local Inner class
Use of Local Inner class       The Java language enables you to define a class inside another class. Such a class is defined as Nested Class or Local Inner class. The Nested
Show a hidden frame previously from another from
Show a hidden frame previously from another from  How can i show a hidden frame previously by this code: jframe_name.hide(); and make it visible from another frame i'm waiting for the answer, and i'll be thankfull
how to use StringTokenizer to retrieve the class name, attributes name and methods name from the Java Source Code
how to use StringTokenizer to retrieve the class name, attributes name and methods name from the Java Source Code  hi, I have done a program whereby... one problem which is retrieve the Class Name, Attributes Name and Methods Names
passing from 1 jsp to another - JSP-Servlet
passing from 1 jsp to another  Hi Sir, What are the ways and means of passing from 1 jsp page to another page.what are the different types of methods?  Hi Friend, You can use tag,sedRedirect() method
calling one jsp from another jsp page
calling one jsp from another jsp page  need coding for calling one jsp from another jsp including the xml file.Its urgent
Need to access data from another application
Need to access data from another application  Hi Tech masters, I want to develop a reporting application.for that I need to access data from a third party application. I want to access data from a software called service
Use of Throwable Class
Use of Throwable Class Throwable class is the super class of all the exceptional class and error class. Only objects of this class can be thrown & caught... are derived from throwable class. To create your own class of throwable objects
mysql select into table from another table example
mysql select into table from another table example  Can you suggest the correct example of select into table from another table example in MySQL... from one table into another table. Check the example at MySQLselect into new
copying data from one table to another
copying data from one table to another  i need to copy data from one table to another table.. i.e the 1st eid of employee table must be copied... and so on... i need these querys to use in my JSP code
passing data from one jframe to another
passing data from one jframe to another  I have two JFrame,built by using the GUI Editor netbeans 6.9.i have to pass a data from a Jtextfield in the first Jframe to another JLabel in the other JFrame.Can you please help me,how
File copy from one directory to another in java
File copy from one directory to another in java  I am trying to find very good code example for copying a file from one directory to another... from a directory to another directory. How to achieve this? Is there any API
update one table from another table
update one table from another table  hello, i need to update one table fields by using another table fields. I have to tables Products.... for example TotalQuantity field from Products table should be updated if i
How to forward the control from one jsp to another?
How to forward the control from one jsp to another?  Hi! This is Prasad Jandrajupalli. I have the 3 JSP's, but I want communicate with each... is not communicate with the Third JSP. I want forward the control from first jsp to second
Use Group Class in SWT
Use Group Class in SWT       In this section, you will learn how to use Group class. In SWT, the class Group of package org.eclipse.swt.widgets provides an etched border
Data Conversion from int to another type
Data conversion is the conversion of data from one type to another type. In this section we will learn about data conversion from int primitive type to another data type like String, boolean and char etc
Data Conversion from String to another type
Data conversion is the conversion of data from one type to another type. In this section we will learn about data conversion from String primitive type to another data type like int, boolean and char etc
Data Conversion from short to another type
Data conversion is the conversion of data from one type to another type. In this section we will learn about data conversion from short primitive type to another data type like String, boolean and char etc
Data Conversion from byte to another type
Data conversion is the conversion of data from one type to another type. In this section we will learn about data conversion from byte primitive type to another data type like String, boolean and char etc
Data Conversion from double to another type
Data conversion is the conversion of data from one type to another type. In this section we will learn about data conversion from double primitive type to another data type like String, boolean and char etc
Data Conversion from long to another type
Data conversion is the conversion of data from one type to another type. In this section we will learn about data conversion from long primitive type to another data type like String, boolean and char etc
Data Conversion from float to another type
Data conversion is the conversion of data from one type to another type. In this section we will learn about data conversion from float primitive type to another data type like String, boolean and char etc
How to navigate from one jsf to another in eclipse
How to navigate from one jsf to another in eclipse  Hi there is my...; <from-view-id>/JSF/UserDetail.jsp</from-view-id> <navigation-case> <from-outcome>success</from-outcome> <
to bring checked data from one page to another
to bring checked data from one page to another  thanks for your help but my problem is different, i am stating my problem below. in my project... fetching data from the database on second jsp page with checkbox corresponding each
Loading a jsp page (with record from database) from another jsp page
Loading a jsp page (with record from database) from another jsp page  Suppose I have two jsp pages Search.jsp and Getdata.jsp. There are two fields... with records from database(against Serial no and year).That is, as soon
swings:how to link from one form to another form
swings:how to link from one form to another form  how to link from one form to another form
Use of PreferenceStore class
Use of PreferenceStore class       This section demonstrates you the use of class...() of this class loads the preference store from the given file. The method  
Java Array Values to Global Varibles - Java Beginners
to pass on to the rate and periods variables in the class declarations. Any help..."); System.out.print("\nPlease select from the loan options listed above...... ThankYou... Code is : import java.io.*; public class GlobalArray
how to copy file from one directory to another in java with examples
how to copy file from one directory to another in java with examples  how to copy file from one directory to another in java with examples? I want... copy from one directory to another in java. Thanks
how can we pass parameters from jsp href to another servlet
how can we pass parameters from jsp href to another servlet  how can we pass parameters from jsp href to another servlet
overriding in derived class from abstract class
overriding in derived class from abstract class  why should override base class method in derived class? Instead of override abstract class method, we can make method implementation in derived class itself know
validate jtextfield in two different class use keylistener
validate jtextfield in two different class use keylistener  validate jtextfield in java swing will use two class, design part in one class and method calling in one class will use Keylisteners or change listeners
Copy data from one JTextField to another JTextField
Copy data from one JTextField to another JTextField..., you will learn how to copy the data from one JTextField into another... and then paste into another JTextField. JTextField is used in the swing
why we use abstract class in java?
why we use abstract class in java?  what is the the purpose of abstract class.Give example when to use abstract and when use interface
File copy from one drive to another. - Java Beginners
File copy from one drive to another.  I want to copy a .mp3 file from one drive(let d: drive)to another drive(let e: drive) in my Windows XP. How can I do
Pass cookie from one site to another within the same domain
Pass cookie from one site to another within the same domain  Hi, I want to pass a cookie from one website to another within the same domain. This is just to identify whether the same user is logged in or not. Can anyone help me
problem in sending data from one ip to another ip in JAVA
problem in sending data from one ip to another ip in JAVA  Hi guys . this is naveen kumar...i need a help. i want to connect one ip to another ip (like ping),after that i want send the data with my system(Ip) to another ip
Use of putChar() method of ByteBuffer class.
Use of putChar() method of ByteBuffer class.  In this tutorial, we...: The java.nio.ByteBuffer class extends java.nio.Buffer class. It provides... getChar() The getChar() method read  2 byte from current position
Why we use singleton class in hibernate sessionfactory?
Why we use singleton class in hibernate sessionfactory?  Hello, Please tell me why we use singleton class in hibernate sessionfactory? hibernate sessionfactory singleton example would be very helpful. Thanks
 

 

 

DMCA.com