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 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){

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. (adsbygoogle = window.adsbygoogle || []).push
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
Advertisements
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
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 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
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
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..._TO_REPLACE_1 Try the following code: import java.util.*; class A { static int regd
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
Run a .exe from a class
Run a .exe from a class  how to lauch a .exe file from a class in Java and to check the success ful execution of the same
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
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
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
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
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
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
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
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
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
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
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
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 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
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
Use of Local Inner class
Use of Local Inner class       The Java language enables you to define a class inside another... illustrates an example from Local Inner class. The code include a Outer class Inner
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> <
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
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
_OBJC_CLASS_$_MFMailComposeViewController", referenced from:
_OBJC_CLASS_$_MFMailComposeViewController", referenced from:   While configuring the email feature in my ipad application, i get the following error message. "OBJCCLASS$MFMailComposeViewController", referenced from: Can
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
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
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
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
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
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
calling one jap page from another jsp page
calling one jap page from another jsp page  i created a button in one jsp page i need to call another jsp page as an action to that button. so how can i call.. plz any one explain. its urgent
how to pass an array from one jsp to another jsp - JSP-Servlet
how to pass an array from one jsp to another jsp  hi friedns, can any One tell me how to send an array from one jsp to another jsp,pls any one send the code for this.also porvid the code how to retrive the arry in another jsp
how to write function of copy from one to another location in this code
how to write function of copy from one to another location in this code  I need to write a code to copy a file from one location to another using... class Browse extends JFrame implements ActionListener { JButton button1
how to go from one frame to another frame in swings - Java Beginners
how to go from one frame to another frame in swings  Hi, My task is to go from one frame to another.......... let us think that iam having two... program from roseindia.........but, the program is done in applets or swings
take data from one table and insert same in another
take data from one table and insert same in another  I want to know when a new field update in table and the same data has to update in another table
ModuleNotFoundError: No module named 'herit-from-base_class'
ModuleNotFoundError: No module named 'herit-from-base_class'  Hi...: No module named 'herit-from-base_class' How to remove the ModuleNotFoundError: No module named 'herit-from-base_class' error? Thanks   Hi
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

Ads