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)"
Ads
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 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
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
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
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
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
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
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
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
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
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
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