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



Home Answers Viewqa Java-Beginners Use varibles from another class
Login         

View Questions and Answers by Category

Advertisements


 
Have Programming Question? Ask it here!
 
 
 


Jorge
Use varibles from another class
2 Answer(s)      3 years and 7 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 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
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
Advertisements
 

 

 

DMCA.com