compiles but doesn't run?

Everything ran great until I added a text area and a scroll pane, It compiles ok but doesn't run I feel I am close any hints as to how off these new components are(area,scroll)




import java.awt.*;  
import javax.swing.*;  
import java.awt.event.*;  
import java.text.*;  
 
public class Hw_prog1 extends JFrame {

Hw_prog1Event TRON = new Hw_prog1Event(this);  
JButton Calculate;
JButton Clear;  
JButton Exit;
JTextArea area;///////////////////////////////////New component
JScrollPane scrollPane;///////////////////////////////////New component





Panel File1  = new Panel();  
Label PrincipalLabel = new Label("$Enter Loan Amount:",Label.CENTER);   //create first row (File)      
TextField LonAmt = new TextField(10);  

Panel File2 = new Panel();  
Label RateLabel = new Label("0.0Enter Interest Rate:",Label.CENTER);   //create second row (File)      
TextField Rat = new TextField(10);  

Panel File3 = new Panel();  
Label TermLabel = new Label("Enter Term-Years:",Label.CENTER);   //create third row (File)      
TextField Trm = new TextField(10);  

Panel File4 = new Panel();  
Label PaymentLabel = new Label("Monthly Payments:",Label.CENTER);   //create forth row (File)      
TextField MthlyPymnt = new TextField(10);  

Panel File5 = new Panel();   //create fifth row (Buttons)

Panel File6 = new Panel(); ///////////////////////////////////New component  


 

   
 
//create  borders(Grid layout)  
public Hw_prog1() {  //Reference the main method
super("McBride.Financial.MortCal");  //Calling setSize  
setSize(875,130);   //set size

//name Buttons
Calculate = new JButton("Calculate");  
Clear = new JButton("New Amount");  
Exit = new JButton("Exit");  
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); //inform Frame to close
   
GridLayout layout =new GridLayout(1, 5, 10, 10); //calls the TextFeild & sets paramerters  
Container pane = getContentPane();  //holds the feilds in place & generates a ‚ÄòContainer‚Äô object that represents the pane
pane.setLayout(layout); // checks known parameters







PrincipalLabel.setForeground(Color.magenta);
RateLabel.setForeground(Color.blue);
TermLabel.setForeground(Color.magenta);
PaymentLabel.setForeground(Color.red);

Calculate.setForeground(Color.magenta);
Clear.setForeground(Color.blue);
Exit.setForeground(Color.red);


pane.setForeground(Color.blue);


//TRON listens for Button fuctions
Calculate.addActionListener(TRON);  
Clear.addActionListener(TRON);  
Exit.addActionListener(TRON);

//‚ÄòFlowLayout‚Äô components fall into place from left to right  
FlowLayout mgr = new FlowLayout(FlowLayout.CENTER,10, 10); //sets parameters  
File1 .setLayout(mgr); //Directs the user were to place data  
File1 .add(PrincipalLabel); //add Component  
File1 .add(LonAmt); //add Component    
pane.add(File1 );  

FlowLayout layout2 = new FlowLayout(FlowLayout.CENTER,10, 10);  
File2.setLayout(layout2);  
File2.add(RateLabel);  
File2.add(Rat);  
pane.add(File2);  

FlowLayout layout3 = new FlowLayout(FlowLayout.CENTER,10, 10);  
File3.setLayout(layout3);  
File3.add(TermLabel);  
File3.add(Trm);  
pane.add(File3);  

FlowLayout layout4 = new FlowLayout(FlowLayout.CENTER,10, 10);  
MthlyPymnt.setEditable(false);  
File4.setLayout(layout4);  
File4.add(PaymentLabel);  
File4.add(MthlyPymnt);  
pane.add(File4);  

FlowLayout layout5 = new FlowLayout(FlowLayout.CENTER,5, 5);  
File5.setLayout(layout5);  
File5.add(Calculate);  
File5.add(Clear);  
File5.add(Exit);  
pane.add(File5);

FlowLayout layout6 = new FlowLayout(FlowLayout.CENTER);  //////////////////////////////////New component
File6.setLayout(layout6);///////////////////////////////////New component
File6.add(scrollPane);///////////////////////////////////New component
pane.add(File6);///////////////////////////////////New component

area = new JTextArea(5, 10);  // 5 rows and 10 columns///////////////////////////////////New component
scrollPane = new JScrollPane(area);  // add the text area to the scroll pane///////////////////New component



setVisible(true);  
}  

public static void main(String[] arguments) {

Hw_prog1 frame = new Hw_prog1();  


}
class Hw_prog1Event implements ActionListener {  
Hw_prog1 virtual;  

public Hw_prog1Event(Hw_prog1 in) {  
virtual=in;  
}  
public void actionPerformed(ActionEvent event) {  
String command = event.getActionCommand();  
if (event.getSource() == Calculate)  
 LaunchComputation();  
if (event.getSource() == Clear)  
reset();  
if (event.getSource() == Exit)  
System.exit(0);  
}  
void LaunchComputation() {  // sub-program to do math
 try   //when called
 {  
double LonAmt = Double.valueOf(virtual.LonAmt.getText()).doubleValue();   // Object & string, double value when Tron calls virtual
double Rat = Double.valueOf(virtual.Rat.getText()).doubleValue();  
int Trm = Integer.parseInt(virtual.Trm.getText());  
int totalmonths = (Trm*12);  
double Payment = 0;  
String monthlyPayment = new String();  
NumberFormat currency = NumberFormat.getCurrencyInstance();  
double I = (Rat/100.0/12.0);  

Payment = (LonAmt*I)/(1-Math.pow(1/(1+I),totalmonths));  
virtual.MthlyPymnt.setText(currency.format(Payment));  
} catch (NumberFormatException ex){  
}  
}  
protected void reset(){  
virtual.LonAmt.setText(null);  
virtual.Rat.setText(null);  
virtual.Trm.setText(null);  
virtual.MthlyPymnt.setText(null);  
}  
}  

 
}  
   
   

charliebabyAsked:
Who is Participating?
 
ForceRsConnect With a Mentor Commented:
File6.add(scrollPane); // scrollpane was null when it was added.  Must move:
JTextArea area = new JTextArea(5, 10); // 5 rows and 10 columns
            JScrollPane scrollPane = new JScrollPane(area); // add the text area to
                                                                                    // the scroll pane

To above
File6.add(scrollPane);

This works:

import java.awt.*;
import javax.swing.*;
import java.awt.event.*;
import java.text.*;

public class Hw_prog1      extends
                                    JFrame {

      Hw_prog1Event TRON = new Hw_prog1Event(this);

      JButton Calculate;

      JButton Clear;

      JButton Exit;

      JTextArea area;

      JScrollPane scrollPane;

      Panel File1 = new Panel();

      Label PrincipalLabel = new Label("$Enter Loan Amount:", Label.CENTER); // create
                                                                                                                  // first
                                                                                                                  // row
                                                                                                                  // (File)

      TextField LonAmt = new TextField(10);

      Panel File2 = new Panel();

      Label RateLabel = new Label("0.0Enter Interest Rate:", Label.CENTER); // create
                                                                                                                  // second
                                                                                                                  // row
                                                                                                                  // (File)

      TextField Rat = new TextField(10);

      Panel File3 = new Panel();

      Label TermLabel = new Label("Enter Term-Years:", Label.CENTER); // create
                                                                                                      // third row
                                                                                                      // (File)

      TextField Trm = new TextField(10);

      Panel File4 = new Panel();

      Label PaymentLabel = new Label("Monthly Payments:", Label.CENTER); // create
                                                                                                            // forth
                                                                                                            // row
                                                                                                            // (File)

      TextField MthlyPymnt = new TextField(10);

      Panel File5 = new Panel(); // create fifth row (Buttons)

      Panel File6 = new Panel();

      // create borders(Grid layout)
      public Hw_prog1() { // Reference the main method
            super("McBride.Financial.MortCal"); // Calling setSize
            setSize(875, 130); // set size

            // name Buttons
            Calculate = new JButton("Calculate");
            Clear = new JButton("New Amount");
            Exit = new JButton("Exit");
            setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); // inform Frame to close

            GridLayout layout = new GridLayout(1, 5, 10, 10); // calls the
                                                                                          // TextFeild & sets
                                                                                          // paramerters
            Container pane = getContentPane(); // holds the feilds in place &
                                                                  // generates a ‚ÄòContainer‚Äô
                                                                  // object that represents the pane
            pane.setLayout(layout); // checks known parameters

            PrincipalLabel.setForeground(Color.magenta);
            RateLabel.setForeground(Color.blue);
            TermLabel.setForeground(Color.magenta);
            PaymentLabel.setForeground(Color.red);

            Calculate.setForeground(Color.magenta);
            Clear.setForeground(Color.blue);
            Exit.setForeground(Color.red);

            pane.setForeground(Color.blue);

            // TRON listens for Button fuctions
            Calculate.addActionListener(TRON);
            Clear.addActionListener(TRON);
            Exit.addActionListener(TRON);

            // ‚ÄòFlowLayout‚Äô components fall into place from left to right
            FlowLayout mgr = new FlowLayout(FlowLayout.CENTER, 10, 10); // sets
                                                                                                      // parameters
            File1.setLayout(mgr); // Directs the user were to place data
            File1.add(PrincipalLabel); // add Component
            File1.add(LonAmt); // add Component
            pane.add(File1);

            FlowLayout layout2 = new FlowLayout(FlowLayout.CENTER, 10, 10);
            File2.setLayout(layout2);
            File2.add(RateLabel);
            File2.add(Rat);
            pane.add(File2);

            FlowLayout layout3 = new FlowLayout(FlowLayout.CENTER, 10, 10);
            File3.setLayout(layout3);
            File3.add(TermLabel);
            File3.add(Trm);
            pane.add(File3);

            FlowLayout layout4 = new FlowLayout(FlowLayout.CENTER, 10, 10);
            MthlyPymnt.setEditable(false);
            File4.setLayout(layout4);
            File4.add(PaymentLabel);
            File4.add(MthlyPymnt);
            pane.add(File4);

            FlowLayout layout5 = new FlowLayout(FlowLayout.CENTER, 5, 5);
            File5.setLayout(layout5);
            File5.add(Calculate);
            File5.add(Clear);
            File5.add(Exit);
            pane.add(File5);

            FlowLayout layout6 = new FlowLayout(FlowLayout.CENTER);
            File6.setLayout(layout6);
            JTextArea area = new JTextArea(5, 10); // 5 rows and 10 columns
            JScrollPane scrollPane = new JScrollPane(area); // add the text area to
                                                                                    // the scroll pane

            File6.add(scrollPane);
            pane.add(File6);

            setVisible(true);
      }

      public static void main(String[] arguments) {

            Hw_prog1 frame = new Hw_prog1();

      }

      class Hw_prog1Event implements ActionListener {
            Hw_prog1 virtual;

            public Hw_prog1Event(Hw_prog1 in) {
                  virtual = in;
            }

            public void actionPerformed(ActionEvent event) {
                  String command = event.getActionCommand();
                  if(event.getSource() == Calculate)
                        LaunchComputation();
                  if(event.getSource() == Clear)
                        reset();
                  if(event.getSource() == Exit)
                        System.exit(0);
            }

            void LaunchComputation() { // sub-program to do math
                  try // when called
                  {
                        double LonAmt = Double.valueOf(virtual.LonAmt.getText()).doubleValue(); // Object
                                                                                                                                    // &
                                                                                                                                    // string,
                                                                                                                                    // double
                                                                                                                                    // value
                                                                                                                                    // when
                                                                                                                                    // Tron
                                                                                                                                    // calls
                                                                                                                                    // virtual
                        double Rat = Double.valueOf(virtual.Rat.getText()).doubleValue();
                        int Trm = Integer.parseInt(virtual.Trm.getText());
                        int totalmonths = (Trm * 12);
                        double Payment = 0;
                        String monthlyPayment = new String();
                        NumberFormat currency = NumberFormat.getCurrencyInstance();
                        double I = (Rat / 100.0 / 12.0);

                        Payment = (LonAmt * I) / (1 - Math.pow(1 / (1 + I), totalmonths));
                        virtual.MthlyPymnt.setText(currency.format(Payment));
                  } catch (NumberFormatException ex) {
                  }
            }

            protected void reset() {
                  virtual.LonAmt.setText(null);
                  virtual.Rat.setText(null);
                  virtual.Trm.setText(null);
                  virtual.MthlyPymnt.setText(null);
            }
      }

}
0
 
CEHJConnect With a Mentor Commented:
You shouldn't mix AWT and Swing
0
 
charliebabyAuthor Commented:
for example?
0
Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 
CEHJCommented:
Panel, Label are AWT. JScrollPane etc, Swing
0
 
charliebabyAuthor Commented:
Is this better, still compiles but won't run, What do I have to do to see the area JTextArea area; and
JScrollPane scrollPane;, will close this question on next correspondence, and post new one


import java.awt.*;  
import javax.swing.*;  
import java.awt.event.*;  
import java.text.*;  
 
public class Hw_prog1 extends JFrame {

Hw_prog1Event TRON = new Hw_prog1Event(this);  
JButton Calculate;
JButton Clear;  
JButton Exit;
JTextArea area;
JScrollPane scrollPane;





Panel File1  = new Panel();  
Label PrincipalLabel = new Label("$Enter Loan Amount:",Label.CENTER);   //create first row (File)      
TextField LonAmt = new TextField(10);  

Panel File2 = new Panel();  
Label RateLabel = new Label("0.0Enter Interest Rate:",Label.CENTER);   //create second row (File)      
TextField Rat = new TextField(10);  

Panel File3 = new Panel();  
Label TermLabel = new Label("Enter Term-Years:",Label.CENTER);   //create third row (File)      
TextField Trm = new TextField(10);  

Panel File4 = new Panel();  
Label PaymentLabel = new Label("Monthly Payments:",Label.CENTER);   //create forth row (File)      
TextField MthlyPymnt = new TextField(10);  

Panel File5 = new Panel();   //create fifth row (Buttons)

Panel File6 = new Panel();  


 

   
 
//create  borders(Grid layout)  
public Hw_prog1() {  //Reference the main method
super("McBride.Financial.MortCal");  //Calling setSize  
setSize(875,130);   //set size

//name Buttons
Calculate = new JButton("Calculate");  
Clear = new JButton("New Amount");  
Exit = new JButton("Exit");  
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); //inform Frame to close
   
GridLayout layout =new GridLayout(1, 5, 10, 10); //calls the TextFeild & sets paramerters  
Container pane = getContentPane();  //holds the feilds in place & generates a ‚ÄòContainer‚Äô object that represents the pane
pane.setLayout(layout); // checks known parameters







PrincipalLabel.setForeground(Color.magenta);
RateLabel.setForeground(Color.blue);
TermLabel.setForeground(Color.magenta);
PaymentLabel.setForeground(Color.red);

Calculate.setForeground(Color.magenta);
Clear.setForeground(Color.blue);
Exit.setForeground(Color.red);


pane.setForeground(Color.blue);


//TRON listens for Button fuctions
Calculate.addActionListener(TRON);  
Clear.addActionListener(TRON);  
Exit.addActionListener(TRON);

//‚ÄòFlowLayout‚Äô components fall into place from left to right  
FlowLayout mgr = new FlowLayout(FlowLayout.CENTER,10, 10); //sets parameters  
File1 .setLayout(mgr); //Directs the user were to place data  
File1 .add(PrincipalLabel); //add Component  
File1 .add(LonAmt); //add Component    
pane.add(File1 );  

FlowLayout layout2 = new FlowLayout(FlowLayout.CENTER,10, 10);  
File2.setLayout(layout2);  
File2.add(RateLabel);  
File2.add(Rat);  
pane.add(File2);  

FlowLayout layout3 = new FlowLayout(FlowLayout.CENTER,10, 10);  
File3.setLayout(layout3);  
File3.add(TermLabel);  
File3.add(Trm);  
pane.add(File3);  

FlowLayout layout4 = new FlowLayout(FlowLayout.CENTER,10, 10);  
MthlyPymnt.setEditable(false);  
File4.setLayout(layout4);  
File4.add(PaymentLabel);  
File4.add(MthlyPymnt);  
pane.add(File4);  

FlowLayout layout5 = new FlowLayout(FlowLayout.CENTER,5, 5);  
File5.setLayout(layout5);  
File5.add(Calculate);  
File5.add(Clear);  
File5.add(Exit);  
pane.add(File5);

FlowLayout layout6 = new FlowLayout(FlowLayout.CENTER);  
File6.setLayout(layout6);
File6.add(scrollPane);
pane.add(File6);

JTextArea area = new JTextArea (5, 10);  // 5 rows and 10 columns
JScrollPane scrollPane = new JScrollPane(area);  // add the text area to the scroll pane



setVisible(true);  
}  

public static void main(String[] arguments) {

Hw_prog1 frame = new Hw_prog1();  


}
class Hw_prog1Event implements ActionListener {  
Hw_prog1 virtual;  

public Hw_prog1Event(Hw_prog1 in) {  
virtual=in;  
}  
public void actionPerformed(ActionEvent event) {  
String command = event.getActionCommand();  
if (event.getSource() == Calculate)  
 LaunchComputation();  
if (event.getSource() == Clear)  
reset();  
if (event.getSource() == Exit)  
System.exit(0);  
}  
void LaunchComputation() {  // sub-program to do math
 try   //when called
 {  
double LonAmt = Double.valueOf(virtual.LonAmt.getText()).doubleValue();   // Object & string, double value when Tron calls virtual
double Rat = Double.valueOf(virtual.Rat.getText()).doubleValue();  
int Trm = Integer.parseInt(virtual.Trm.getText());  
int totalmonths = (Trm*12);  
double Payment = 0;  
String monthlyPayment = new String();  
NumberFormat currency = NumberFormat.getCurrencyInstance();  
double I = (Rat/100.0/12.0);  

Payment = (LonAmt*I)/(1-Math.pow(1/(1+I),totalmonths));  
virtual.MthlyPymnt.setText(currency.format(Payment));  
} catch (NumberFormatException ex){  
}  
}  
protected void reset(){  
virtual.LonAmt.setText(null);  
virtual.Rat.setText(null);  
virtual.Trm.setText(null);  
virtual.MthlyPymnt.setText(null);  
}  
}  

 
}  
   
   

0
 
objectsCommented:
> You shouldn't mix AWT and Swing
> Panel, Label are AWT. JScrollPane etc, Swing

that won't stop it running
why did u accept that comment?
0
 
charliebabyAuthor Commented:
sorry wanted to split the points is there anything I can do now, to split them between  ForceRs  and CEHJ
0
 
ForceRsCommented:
Don't worry about.  No problem.  Glad to help.
0
 
charliebabyAuthor Commented:
you are all so cool, Thank you so much I take it that the scroll panel will take affect as soon as there is text to scroll to?
0
 
ForceRsCommented:
Yes -- works for me.
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.