I posted two code snippets below. Both codes work individually. Now, when I run the Easy file and click on the "Start" button, I want the AddNumber class to be implemented. I want to say that instead of AddNumber running on the console, is there a way to make AddNumber run in JTextArea, which I created in the first class by clicking the "Start" button? I thought maybe an action listener? (How do we do this with buttons) But I'm not sure. Is there any other way to get JTextArea to act as a console for other .java files?
import java.awt.*;
import javax.swing.*;
import java.awt.event.*;
public class Easy extends JFrame{
JTextArea text=new JTextArea();
JPanel panel=new JPanel(new GridLayout(2,2));
JButton button1 =new JButton("Start");
public Easy(){
panel.add(text);
panel.add(button1);
add(panel,BorderLayout.CENTER);
button1.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent ae){
}
});
}
public static void main(String arg[]){
Easy frame=new Easy();
frame.setSize(300,100);
frame.setVisible(true);
}
}
Second class:
import java.util.Scanner;
class AddNumber
{
public static void main(String args[])
{
int x, y, z;
System.out.println("Enter two numbers to be added ");
Scanner in = new Scanner(System.in);
x = in.nextInt();
y = in.nextInt();
z = x + y;
System.out.println("Sum of entered numbers = "+z);
}
}
I saw a few posts about PrintStream ... but I don't think this applies here. Please help me. Thanks:)
UPDATE: , : http://www.codeproject.com/Articles/328417/Java-Console-apps-made-easy#HowtousethisJavaConsole1, , " , "... ?
EDIT: ... ... , , ... .. IDE..