Not Displying to the Text Area

Discussion in 'Java' started by not4_me, Feb 27, 2011.

  1. not4_me

    not4_me New Member

    Joined:
    Feb 27, 2011
    Messages:
    2
    Likes Received:
    0
    Trophy Points:
    0
    I am trying to out put to a TextArea but it is not working. I believe I am missing something. I am using NetBeans and it will run on the output box of NetBeans but not in the GUI (TextArea). Any ideas?
     
  2. virxen

    virxen Active Member

    Joined:
    Nov 24, 2009
    Messages:
    387
    Likes Received:
    90
    Trophy Points:
    28
    post your code
     
  3. not4_me

    not4_me New Member

    Joined:
    Feb 27, 2011
    Messages:
    2
    Likes Received:
    0
    Trophy Points:
    0
    Here is the code.

    Code:
    package my.tutoringreport;
    import java.text.DecimalFormat;
    import javax.swing.JOptionPane;
     
    /**
    *
    * @author Ravenhawk
    */
    public class TutoringReportUI extends javax.swing.JFrame {
    Double[][] timeWage;
    int timeWageIndex = 0;
    double minimumWage = 6.55;
     
    /** Creates new form TutoringReportUI */
    public TutoringReportUI() {
    timeWage = new Double[3][2];
     
     
    initComponents();
    }
    /** This method is called from within the constructor to
    * initialize the form.
    * WARNING: Do NOT modify this code. The content of this method is
    * always regenerated by the Form Editor.
    */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code"> 
    private void initComponents() {
    jInternalFrame1 = new javax.swing.JInternalFrame();
    jLabel1 = new javax.swing.JLabel();
    jLabel2 = new javax.swing.JLabel();
    jTextField1 = new javax.swing.JTextField();
    jTextField2 = new javax.swing.JTextField();
    jScrollPane1 = new javax.swing.JScrollPane();
    jTextArea1 = new javax.swing.JTextArea();
    jButton1 = new javax.swing.JButton();
    jButton2 = new javax.swing.JButton();
    jButton3 = new javax.swing.JButton();
    setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
    jInternalFrame1.setTitle("Tutoring Wages Report");
    jInternalFrame1.setVisible(true);
    jLabel1.setText("Tutoring Time in Minutes");
    jLabel2.setText("Payment for session in dollars and cent");
    jTextArea1.setColumns(20);
    jTextArea1.setRows(5);
    jScrollPane1.setViewportView(jTextArea1);
    jButton1.setText("Enter");
    jButton1.addActionListener(new java.awt.event.ActionListener() {
    public void actionPerformed(java.awt.event.ActionEvent evt) {
    jButton1ActionPerformed(evt);
    }
    });
    jButton2.setText("Run Report");
    jButton2.addActionListener(new java.awt.event.ActionListener() {
    public void actionPerformed(java.awt.event.ActionEvent evt) {
    jButton2ActionPerformed(evt);
    }
    });
    jButton3.setText("Quit");
    jButton3.addActionListener(new java.awt.event.ActionListener() {
    public void actionPerformed(java.awt.event.ActionEvent evt) {
    jButton3ActionPerformed(evt);
    }
    });
    javax.swing.GroupLayout jInternalFrame1Layout = new javax.swing.GroupLayout(jInternalFrame1.getContentPane());
    jInternalFrame1.getContentPane().setLayout(jInternalFrame1Layout);
    jInternalFrame1Layout.setHorizontalGroup(
    jInternalFrame1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
    .addGroup(jInternalFrame1Layout.createSequentialGroup()
    .addGap(19, 19, 19)
    .addGroup(jInternalFrame1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
    .addComponent(jLabel1)
    .addComponent(jLabel2))
    .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 185, Short.MAX_VALUE)
    .addGroup(jInternalFrame1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
    .addComponent(jTextField2)
    .addComponent(jTextField1, javax.swing.GroupLayout.DEFAULT_SIZE, 136, Short.MAX_VALUE))
    .addContainerGap(83, Short.MAX_VALUE))
    .addGroup(jInternalFrame1Layout.createSequentialGroup()
    .addContainerGap()
    .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 431, javax.swing.GroupLayout.PREFERRED_SIZE)
    .addGap(18, 18, 18)
    .addGroup(jInternalFrame1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
    .addComponent(jButton1)
    .addComponent(jButton2)
    .addComponent(jButton3))
    .addContainerGap(64, Short.MAX_VALUE))
    );
    jInternalFrame1Layout.setVerticalGroup(
    jInternalFrame1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
    .addGroup(jInternalFrame1Layout.createSequentialGroup()
    .addGap(24, 24, 24)
    .addGroup(jInternalFrame1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
    .addComponent(jLabel1)
    .addComponent(jTextField1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
    .addGap(18, 18, 18)
    .addGroup(jInternalFrame1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
    .addComponent(jLabel2)
    .addComponent(jTextField2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
    .addGap(43, 43, 43)
    .addGroup(jInternalFrame1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
    .addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 185, Short.MAX_VALUE)
    .addGroup(jInternalFrame1Layout.createSequentialGroup()
    .addComponent(jButton1)
    .addGap(18, 18, 18)
    .addComponent(jButton2)
    .addGap(18, 18, 18)
    .addComponent(jButton3)))
    .addContainerGap())
    );
    javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
    getContentPane().setLayout(layout);
    layout.setHorizontalGroup(
    layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
    .addGroup(layout.createSequentialGroup()
    .addComponent(jInternalFrame1)
    .addContainerGap())
    );
    layout.setVerticalGroup(
    layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
    .addGroup(layout.createSequentialGroup()
    .addComponent(jInternalFrame1)
    .addContainerGap())
    );
    pack();
    }// </editor-fold> 
    private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) { 
    // TODO add your handling code here:
    double time = 0;
    double wage = 0;
    try {time = Double.parseDouble(jTextField1.getText());
    } catch (NumberFormatException e1) {
    JOptionPane.showMessageDialog(null, "The time must be a decimal number", "Invalid Input",JOptionPane.ERROR_MESSAGE);
    }
    try {wage = Double.parseDouble(jTextField2.getText());
    } catch (NumberFormatException e1) {
    JOptionPane.showMessageDialog(null, "The wage must be a decimal number", "Invalid Input",JOptionPane.ERROR_MESSAGE);
    }
    if(time<=0 || time>240){
    JOptionPane.showMessageDialog(null, "The time must greater than 0 and less than or equal to 4 hours (240 min)",
    "Invalid Input",JOptionPane.ERROR_MESSAGE);
    }
    else{
    // proceed
    if(wage<=0){
    JOptionPane.showMessageDialog(null, "The wage must greater than 0",
    "Invalid Input",JOptionPane.ERROR_MESSAGE);
    }
    else{
    // proceed
    timeWage[timeWageIndex][0] = time;
    timeWage[timeWageIndex][1] = wage;
    timeWageIndex++; // increase index for next time
    jTextField1.setText("");
    jTextField2.setText("");
     
    }
    }
     
    } 
    private void jButton2ActionPerformed(java.awt.event.ActionEvent evt) { 
    // TODO add your handling code here:
     
     
    String newline = "\n";
    double timeTotal = 0;
    double wageTotal = 0;
     
    // for each entry...
    for(int i = 0; i<=timeWageIndex-1; i++){
    double time = timeWage[i][0];
    double wage = timeWage[i][1];
    timeTotal += time;
    wageTotal += wage;
    System.out.print("Minutes: " + time + " Earnings: $" + wage + newline);
    }
    DecimalFormat df = new DecimalFormat("#.##");
    double average = wageTotal / (timeTotal/60);
    System.out.print(newline + newline + "*****************************" + 
    newline + newline + newline);
     
    System.out.print("Report of wages to date:" + newline + newline);
     
    System.out.print("Total time spent tutoring: " + timeTotal + newline);
     
    System.out.print("Total earnings: $" + wageTotal + newline);
     
    System.out.print("Average per hour wage: $" + (average) + newline + newline);
     
    System.out.print("Minimum wage is currently: $" + minimumWage + newline);
    if(average<minimumWage)
     
    System.out.println("Your average wages are less than average");
    else if(average>minimumWage && average < minimumWage*2.0)
    System.out.print("Your average wages are average");
    else if(average >= minimumWage*2.0)
     
    System.out.print("Your average wages are above average");
     
    } 
     
    private void jButton3ActionPerformed(java.awt.event.ActionEvent evt) { 
    // TODO add your handling code here:
    System.exit(0);
     
     
    } 
     
     
    /**
    * @param args the command line arguments
    */
    public static void main(String args[]) {
    java.awt.EventQueue.invokeLater(new Runnable() {
    public void run() {
    new TutoringReportUI().setVisible(true);
    }
     
    Last edited by a moderator: Feb 28, 2011
  4. virxen

    virxen Active Member

    Joined:
    Nov 24, 2009
    Messages:
    387
    Likes Received:
    90
    Trophy Points:
    28
    if you replace for example
    System.out.print("Report of wages to date:" + newline + newline);

    with

    jTextArea1.setText("Report of wages to date:" + newline + newline);

    you will have the desired.
     

Share This Page

  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice