Can some body tell me where my code is going wrong

I have been trying to print a jTextArea and have been having trouble. Can some body look at my code and tell me where I am going wrong please, Thank You.
I have pasted the code below. P.S. I have only attempted to print the jTextArea I have not done anything else. The program was written in the hope that I could learn how to print a jTextArea and no other function in an aim to transfer the successful code to other applications that I enter information into the jTextArea.
* print.java
* Created on 05 August 2007, 23:34
package my.print;
* @author morgan
import java.awt.print.*;
public class print extends javax.swing.JFrame {
/** Creates new form print */
public print() {
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.
// <editor-fold defaultstate="collapsed" desc=" Generated Code ">
private void initComponents() {
jScrollPane1 = new javax.swing.JScrollPane();
jTextArea1 = new javax.swing.JTextArea();
jButton1 = new javax.swing.JButton();
setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
jTextArea1.setColumns(20);
jTextArea1.setRows(5);
jScrollPane1.setViewportView(jTextArea1);
jButton1.setText("jButton1");
jButton1.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
jButton1ActionPerformed(evt);
javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
getContentPane().setLayout(layout);
layout.setHorizontalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addGap(88, 88, 88)
.addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(jButton1)
.addContainerGap(67, Short.MAX_VALUE))
layout.setVerticalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addGap(95, 95, 95)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(jButton1)
.addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
.addContainerGap(109, Short.MAX_VALUE))
pack();
}// </editor-fold>
private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {
try {
jTextArea1.print();
} catch (java.awt.print.PrinterException exc) { // ... }
* @param args the command line arguments
public static void main(String args[]){
java.awt.EventQueue.invokeLater(new Runnable() {
public void run() {
new print().setVisible(true);
// Variables declaration - do not modify
private javax.swing.JButton jButton1;
private javax.swing.JScrollPane jScrollPane1;
private javax.swing.JTextArea jTextArea1;
// End of variables declaration
}

sorry i hope that this preserves the code.
* print.java
* Created on 05 August 2007, 23:34
package my.print;
* @author  morgan
import java.awt.print.*;
public class print extends javax.swing.JFrame {
    /** Creates new form print */
    public print() {
            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.
    // <editor-fold defaultstate="collapsed" desc=" Generated Code ">
    private void initComponents() {
        jScrollPane1 = new javax.swing.JScrollPane();
        jTextArea1 = new javax.swing.JTextArea();
        jButton1 = new javax.swing.JButton();
        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
        jTextArea1.setColumns(20);
        jTextArea1.setRows(5);
        jScrollPane1.setViewportView(jTextArea1);
        jButton1.setText("jButton1");
        jButton1.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton1ActionPerformed(evt);
        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addGap(88, 88, 88)
                .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jButton1)
                .addContainerGap(67, Short.MAX_VALUE))
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addGap(95, 95, 95)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jButton1)
                    .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addContainerGap(109, Short.MAX_VALUE))
        pack();
    }// </editor-fold>
    private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {
try {
    jTextArea1.print();
} catch (java.awt.print.PrinterException exc) { // ... }
     * @param args the command line arguments
    public static void main(String args[]){
        java.awt.EventQueue.invokeLater(new Runnable() {
             public void run() {
                new print().setVisible(true);
    // Variables declaration - do not modify
    private javax.swing.JButton jButton1;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JTextArea jTextArea1;
    // End of variables declaration
    }The preview looked correct. Thank you for the URL. I have been writting my program in netbeans 5.5.1. unfortunately it simplifies the code that you have to put in but at the same time it makes it difficult to follow code examples that are intended to develope the whole of the code from scratch. I have tried looking at the netbeans guidance documentation but find that it doesn't always work even when I follow the direct code for the demonstrations. Anyway thanks for the guidance and for getting back to me so soon.

Similar Messages

  • Can someone tell me where my code is going wrong

    Hi I am trying to save the information in a jtextfield and then reopen that data at a later date in the same jtextfield. I have put the code in and it runs but when I try to save the jtextfield it does not create a file so when I try to reopen it there is no file to open as none was made, but i can get the save filechooser and open filechooser to open just not do what I want them to.
    Thanks the Lord of the realm.
    * NewJFrame.java
    * Created on 10 November 2007, 20:03
    package javaapplication56;
    import java.awt.Component;
    import java.io.File;
    import javax.swing.JFileChooser;
    * @author  morgan
    public class NewJFrame extends javax.swing.JFrame {
        /** Creates new form NewJFrame */
        public NewJFrame() {
            initComponents();
        //Create a file chooser
    final JFileChooser fc = new JFileChooser();
        /** 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.
        // <editor-fold defaultstate="collapsed" desc=" Generated Code ">                         
        private void initComponents() {
            jTextField1 = new javax.swing.JTextField();
            jScrollPane1 = new javax.swing.JScrollPane();
            jTextArea1 = new javax.swing.JTextArea();
            jButton2 = new javax.swing.JButton();
            jButton4 = new javax.swing.JButton();
            jButton1 = new javax.swing.JButton();
            setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
            jTextArea1.setColumns(20);
            jTextArea1.setRows(5);
            jScrollPane1.setViewportView(jTextArea1);
            jButton2.setText("calculate");
            jButton2.addActionListener(new java.awt.event.ActionListener() {
                public void actionPerformed(java.awt.event.ActionEvent evt) {
                    jButton2ActionPerformed(evt);
            jButton4.setText("OPEN");
            jButton4.addActionListener(new java.awt.event.ActionListener() {
                public void actionPerformed(java.awt.event.ActionEvent evt) {
                    jButton4ActionPerformed(evt);
            jButton1.setText("SAVE");
            jButton1.addActionListener(new java.awt.event.ActionListener() {
                public void actionPerformed(java.awt.event.ActionEvent evt) {
                    jButton1ActionPerformed(evt);
            javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
            getContentPane().setLayout(layout);
            layout.setHorizontalGroup(
                layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                    .addGap(80, 80, 80)
                    .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                        .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addComponent(jTextField1, javax.swing.GroupLayout.PREFERRED_SIZE, 87, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 52, Short.MAX_VALUE)
                    .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false)
                            .addComponent(jButton4, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                            .addComponent(jButton2, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                        .addComponent(jButton1))
                    .addGap(27, 27, 27))
            layout.linkSize(javax.swing.SwingConstants.HORIZONTAL, new java.awt.Component[] {jButton1, jButton2, jButton4});
            layout.setVerticalGroup(
                layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                .addGroup(layout.createSequentialGroup()
                    .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                        .addGroup(layout.createSequentialGroup()
                            .addGap(30, 30, 30)
                            .addComponent(jTextField1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addGap(54, 54, 54)
                            .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addGroup(layout.createSequentialGroup()
                            .addGap(49, 49, 49)
                            .addComponent(jButton2)
                            .addGap(46, 46, 46)
                            .addComponent(jButton4)
                            .addGap(20, 20, 20)
                            .addComponent(jButton1)))
                    .addContainerGap(100, Short.MAX_VALUE))
            pack();
        }// </editor-fold>                       
        private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {                                        
    JFileChooser jfc = new JFileChooser(new File(jTextField1.getText()));
        if (evt.getSource() == jButton1) {
                int returnVal = jfc.showSaveDialog(this);
                if (returnVal == JFileChooser.APPROVE_OPTION) {
                    File file = jfc.getSelectedFile();
        private void jButton4ActionPerformed(java.awt.event.ActionEvent evt) {                                        
          if (evt.getSource() == jButton4) {
            int returnVal = fc.showOpenDialog(NewJFrame.this);
            if (returnVal == JFileChooser.APPROVE_OPTION) {
                File file = fc.getSelectedFile();
                //This is where a real application would open the file.
                append("Opening: " + file.getName() + "." + newline);
            } else {
                append("Open command cancelled by user." + newline);
        private void jButton2ActionPerformed(java.awt.event.ActionEvent evt) {                                        
    float num1, result;
        num1 = Float.parseFloat(jTextField1.getText());
              result = num1;
                     jTextArea1.setText(String.valueOf(result));
        private String newline;
        private Object aComponent;
         * @param args the command line arguments
        public static void main(String args[]) {
            java.awt.EventQueue.invokeLater(new Runnable() {
                public void run() {
                    new NewJFrame().setVisible(true);
        private void append(String string) {
            throw new UnsupportedOperationException("Not yet implemented");
        // Variables declaration - do not modify                    
        private javax.swing.JButton jButton1;
        private javax.swing.JButton jButton2;
        private javax.swing.JButton jButton4;
        private javax.swing.JScrollPane jScrollPane1;
        private javax.swing.JTextArea jTextArea1;
        private javax.swing.JTextField jTextField1;
        // End of variables declaration                  
    }Edited by: Reg_Dwight on Dec 19, 2007 5:10 PM

    Reg_Dwight wrote:
    please can you be more specific I am new at filechoosers and I am unsure of you reply although I am grateful for it though.I can see you are using an IDE. I agree, it looks so easy but the code under an IDE-generated GUI can be so complicated.
    I'm no expert, but I can tell you that I started with java.io.File, java.io.PrintWriter, and java.util.Scanner for simple I/O. It's only now that I am hard-coding GUI components even though I use an IDE.
    My unsolicited advice is to run through those three classes first, preferably as book topics, so that you can get a feel for file I/O.

  • Real Estate: Can some body tell me configuration of Guest House Process

    I m working on RE Business Process:
    Can some body tell the exact configuration of Guest House Process.
    If u find, Plz let me Know.
    Regards,
    Mahadev.
    Edited by: Mahadevappa Shrimanth on Apr 14, 2008 8:29 AM

    Hi Ahmed ,
    Did you got any update regarding the above query ?
    Do you have any idea about the extraction/ data source for 0REFX_C14.
    Regards
    PA

  • Can any body tel me the pin code of macBook pro

    Tel me the pin code combition of macBook pro.

    What exactly do you mean by the pin code combination of the MacBook Pro?  Are you looking for the model number for an MBP?  That will change for specific year/updates to the hardware.  Look at http://www.everymac.com for specific MBP year/models and see if what you want is in the available information.

  • Can some body tell me how i can get the music i put on my old ipod to my new ipod

    can someone tell me how i can get the music i put on my ipod from my music collection to my new ipod please

    Import the music into your iTunes libary
    To import music into your iTunes library on the computer go to iTunes>Help>iTunes Help>Add items to iTunes and follow the instructions
    And then sync to your iPod
    iTunes: Syncing media content to iOS devices and iPod

  • Please can some-one tell me where to find the price differences between the ACA and ACE exams.

    Please can someone tell me the price difference (in ZAR) between the ACE and ACA exams.

    Why did you post this in the forum for Adobe Reader?

  • HT204088 i got my credit card statment and i have big charges paid to i tune i dont know about it the only app i use and i pay it through you is keku and usually it is about 25$ a month now i have four handreds dollars charged can some body tell me how

    hi

    First, log into your iTunes Store account and see if the purchases are reflected in the Purchase History.
    http://support.apple.com/kb/HT2727
    If they are and you're sure you or someone you know didn't make the purchase, immediately change the password to your iTunes Store account, making sure it's not something easily guessed or looked up. Then go here:
    http://www.apple.com/support/itunes/contact/
    and follow the instructions to report the issue to the iTunes Store. 
    If the charges are not reflected in the Purchase History, then it's most likely a fraudulent charge to your credit card directly rather than an unauthorized purchase through your iTunes Store account and it will be up to your bank to handle.
    Regards.

  • HT4623 Hi . My iPhone 4S Facebook page won't rotate either it's lock or unlock what should I do for it could some body tell me about this problem plz

    Hello dear I want to ask that when I am using the Facebook app in my iPhone 4S I want rotate the screen but its not turn over in side ways other all pager or apps like text massages , safari browser , all rotate but only having problem with my Facebook that I can not rotate so please can some body tell me what should I do for this problem .
    Waiting for positive answer.
    I look forward to hear from you people soon thanks
    Regards ,
    Syed Basharat Ali

    They may not have the updated Facebook app. I have a 4S and my Facebook will not rotate. You can use Google and find more information about this. I'm just reporting what is going on and why it is happening.
    Google:
    http://www.google.com/search?q=ios+facebook+app+rotation&sourceid=ie7&rls=com.mi crosoft:en-us:IE-Address&ie=&oe=
    One of the links from Macrumors:
    http://forums.macrumors.com/showthread.php?t=1427794
    Message was edited by: ChrisJ4203

  • Can some body help me to develop labview code for generating pulse to drive ac servo motor

    can some body help me to develop labview code for generating pulse to drive ac servo motor... i am using NI 9401 card ....tnx

    Driving an AC servo motor would (I missed AC on the previous msg) requires some complex hardware. This is generally done by drivers specifically designed for this purpose. I doubt you will be able to accomplish this with the hardware you currently have and it might be cheaper to just buy a driver for it and control the speed through the driver.

  • Hi i want to download BW , please can any body tell me that where can

    hi i want to download BW , please can any body tell me that where can i have that
    thanks
    basu

    BW is not available, as far as I am aware, for free download at this time.
    matt

  • Hi, folks can some body help me¡  How  I can  use  de second  code  to  the  Itunes card  to  use  the  Itunes card.... My  number is vanished, how  i can submit  my  Itunes card?

    Hi, folks can some body help me¡  How  I can  use  de second  code  to  the  Itunes card  to  use  the  Itunes card.... My  number is vanished, how  i can submit  my  Itunes card?

    iTunes Store: Invalid, inactive, or illegible codes
    http://support.apple.com/kb/TS1292

  • Recently Iam purchased a Iphone from U.S, but iam residing in India, so can any body tell me in india how can i get support as my phone charger is not working from where in india i can replace i

    Recently Iam purchased a Iphone from U.S, but iam residing in India, so can any body tell me in india how can i get support as my phone charger is not working from where in india i can replace it

    gosharma wrote:
    What if we have Applecare? Applecare is worldwide. Isnt it?
    Not on an iPhone.

  • Can any body tell me when we do full buffering db tables

    hello all
    can any body tell me when we do full buffering  , what changes will occurs in database server?
    After buffer we added some fields in database table what changes will be there in database server?

    Hi Swamy,
    refer this link
    http://help.sap.com/saphelp_47x200/helpdata/en/cf/21f244446011d189700000e8322d00/content.htm
    http://help.sap.com/saphelp_47x200/helpdata/en/3d/935324d37011d194ba00a0c94260a5/content.htm
    http://abapprogramming.blogspot.com/2007/11/buffering-in-sap-abap.html
    Table Buffer:Table Buffer is a  place on the RAM where we store the whole table temperorly.Single Buffer:It is one type of buffering techniques through which we can store single record of a table on RAM temperorly. If more details are present ...
    This r some think to buffer the data in application server. Buffer not allowed will buffer data in AS.  Data will be fetched directly from Database server. Buffer switched on means it buffers data in AP means data is fetched from application Server. Buffer switched allowed but switched off.  Full buffer to store the table in AP. Generic buffer - It is a comparison of fields i.e. data retired by the matching record.
    Cheers
    Mohinder Singh Chauhan

  • Hi, i want to control my vi from multiple systems using ethernet options can any body tell me how to do that? thans in advance

    hi, i want to control my vi from multiple systems using ethernet options can any body tell me how to do that?  thans in advance

    There are multiple ways of doing this. Here are some of them..
    The Web Publishing tool allows you to publish the front panel and you can control the front panel remotely.http://www.ni.com/white-paper/2911/en/
    The TCP/IP socket can allow you to pass codes "strings" to another computer. Lookup the server client example.
    regards,
    Gautham

  • Can any body tell how RSGEN works

    Can any body tell how RSGEN works and where it stores the generated code and where the path is maintained.
    Regards
    Mave

    Ya I am sorry I mean SGEN , my  problem is I had ran that SGEN but each time I restart my system and access any TCODE the system starts compiling its happeneing every time I restart. What I suppose my system cannot able to locate the generated loads of ABAP sources .
    How the system actually recognize the generated loads from the tablespace somewhere may be tablespace path is defined ?
    OR suggest any alternative.
    Regards
    Mithun

Maybe you are looking for

  • Skype Click to call interferes with ClipBoard

    I have found the strange behavior that as soon as Click to call has recognized a phone number (be it in IE or FF) on a webpage, it disables functionality of the clipboard: when trying to copy/paste within an MS Office program, only the text is copied

  • My Lion woes, panes, detect display

    My complaints so far.  I am sure I will come to love the new features in Lion though when I get done with my bi', okay, will stop there.  Some complaints are dependent on me using screen zooming / scaling all the time due to my distance I sit from my

  • Capacity of the computer to handle all programmes from Adobe - and at least: photoshop, illustrator and Indesign and a website.

    Can you tell me what kind of capacity the computer needs in order to handle all programmes from Adobe - and at least: Photoshop, Illustrator and Indesign and a Website (Adobe or Wordpress)? My computer an Acer from 2005 with a 32 bit Ram and Window V

  • Newport ESP300 & MFA stage problem

    I am having a problem with moving the stages from the home position. I perform a 'Find Home Signal' operation, and all the axis home ok. When I then try and perform an Asolute Move, I get a Hardware Limit Error and the stage stops moving.  It seems t

  • How can I INstall ECATT ?

    Dear All, I have installed sap ERP ecc6 "IDES" i want now to install ECATT From where i can download the ECATT ?? can you please guide me how can i do this using a step by step tutorial Thanks