This is my Main class
public class Main {
public static void main(String[] args) {
// TODO Auto-generated method stub
Program p = new Program();
}
}
Here is my Program class
public class Program {
public Program(){
//System.out.println("Let's begin...");
TextEditor textEditor = new TextEditor();
textEditor.setVisible(true);
textEditor.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
}
}
Here is my TextEditor class. In this class is where I have a JFrame that has a text field in which I would like the results of the fahrenheit to celcus conversion found in my Calculator class to be placed.
public class TextEditor extends JFrame implements ActionListener{
JTextArea textArea;
public TextEditor(){
super("TextMe");
this.setLayout(new BorderLayout());
loadMenuBar();
loadToolBar();
loadTextArea();
this.pack();
}
private void loadTextArea() {
// TODO Auto-generated method stub
textArea = new JTextArea();
textArea.setPreferredSize(new Dimension(800,600));
this.add(BorderLayout.CENTER, textArea);
}
@Override
public void actionPerformed(ActionEvent e) {
} loadCalculator()
private void loadCalculator() {
// TODO Auto-generated method stub
Calculator c = new Calculator();
Calculator calculator = new Calculator();
calculator.setVisible(true);
calculator.setDefaultCloseOperation(JFrame.HIDE_ON_CLOSE);
textArea.setText(String.valueOf(c.fahrenheit));
}
Here is my Calculator class which extends JFrame and implements ActionListener. In here is where a JFrame comes up with a JButton and a JTextField next to it. When the user enters a number into the text field, it does a calculation and converts Fahrenheit to Celsius. Once that is done, I would like the result to show up on the JTextArea from the TextEditor Class.
public class Calculator extends JFrame implements ActionListener{
JButton fToCButton;
JTextField fToC;
double fahrenheit;
TextEditor a = new TextEditor();
public Calculator(){
super("Unit Converter");
this.setLayout(new FlowLayout());
fToC = new JTextField(5);
fToCButton = new JButton("Ferenheit To Celcius");
fToCButton.addActionListener(this);
add(fToCButton, BorderLayout.WEST);
add(fToC);
this.pack()
@Override
public void actionPerformed(ActionEvent e) {
// TODO Auto-generated method stub
if(e.getSource() == fToCButton){
degreeConversion();
}
}
private void degreeConversion() {
// TODO Auto-generated method stub
double conversion = Double.parseDouble(fToC.getText());
fahrenheit = (((conversion -32) * 5) / 9);
a.textArea.setText(String.valueOf(fahrenheit));
System.out.println(fahrenheit);
}
}