Multiple classes and drawImage

First I should start by saying I am VERY new to Java. I have written a program that
uses multiple classes, and i would like to place boolean b =
g.drawImage(cardPics[j],x2,yPos,50,75),this); in my class. I have passed Graphics g
from paint. I am able to use g.drawString, etc, but when I try to drawImage, it will
not even compile. I CAN use
boolean b = g.drawImage(cardPics[j],x2,yPos,50,75,this); in paint outside of the
classes, so I believe I have the image array set up right.
This is what the compilers reads:
cannot resolve symbol
boolean b =g.drawImage(cardPics[j],x2,yPos,50,75,this);
(The symbol that it is referring to is the period between g and drawImage)
Any help is greatly appreciated.
Thankyou
Apryl

The last argument to drawImage must be an ImageObserver. Therefore, for this line of code to work, it must be placed in a non-static method of a class that implements ImageObserver.

Similar Messages

  • Question about multiple classes and Linked Lists

    Lets say you have 4 classes: LinkedList which is the main class, Node, Card, and Hand. im not putting any constructors yet
    The card class keeps track of a card such as a king of diamonds:
    public class Card {
    string suit;
    string rank;
    the node class has a Card object and another node object so it would be
    public class Node {
    Card c;
    Node next;
    the hand class keeps track of the users hand. This program will ask the user if they want to add, remove, print out the hand, or print out the score of the hand, I guess it would be like this
    public class Hand {
    Node head;
    The linkedlist class will contain all the methods for doing the above
    now my questions are. Lets say I want to add a card, so I would have to add a new Node which contains the card. If i wanted to access the new nodes card contents, lets call this node g, can i do, g.c.suit and g.c.rank in which this case c is the card object in Node. Also, these are not going to be nested classes, they are going to be 4 seperate classes, if I declare all variables as private will I need to extend the classes or not and if there is a better way, let me know. Thanks alot for all your help and previous help.

    here is an example of Card and Hand ...
    not saying its good design
    but it does work
    public class Cards {
    public static void main(String[ ] args) {
    Card c1 = new Card ("ace", "diamonds");
    Card c2 = new Card ("two", "spades");
    Card c3 = new Card ("three", "hearts");
    Hand a1 = new Hand ();
    a1.add(c1);
    a1.add(c2);
    a1.add(c3);
    System.out.println("\nshowing hand ...");
    a1.show();
    System.out.println("\ndeleting " + c2.num + " " + c2.suite);
    a1.del(c2);
    System.out.println("\nshowing hand ...");
    a1.show();
    } // main
    } // class
    class Hand exists in 3 states
    and is designed to be a chain of cards ...
    1. when class Hand is first created
       a. it has no card
       b. and no nextHand link
    2. when somecard is added to this Hand
       a. it has a card
       b. and the nextHand link is null
    3. when somecard is attempted to be added to this Hand
       and it already has a card
       then a nextHand is created
       and the somecard is added to the nextHand
       a. so the Hand has a card
       b. and the Hand has a nextHand
    class Hand {
    public Card acard;
    public Hand nextHand;
    public Hand () {
      acard = null;
      nextHand = null;
    public void add (Card somecard) {
      if (acard == null) {
        acard = somecard;
        return;
      if (nextHand == null) nextHand = new Hand();
      nextHand.add (somecard);
    delete this Hand by making this Hand
    refer to the next Hand
    thus skipping over this Hand in the nextHand chain
    for example, removing Hand 3 ...
    1  -  2  -  3  -  4   becomes
    1  -  2  -  4
    public void del (Card somecard) {
      if (acard == somecard) {
        if (nextHand != null) acard = nextHand.acard;
        else acard = null;
        if (nextHand != null) nextHand = nextHand.nextHand;
        return;
      nextHand.del(somecard);
    public void show() {
      if (acard == null) return;
      System.out.println(acard.num + " " + acard.suite);
      if (nextHand != null) nextHand.show ();
    } // class
    class Card {
    public String num;
    public String suite;
    Card (String num, String suite) {
      this.num = num;
      this.suite = suite;
    } // class

  • Developp with multiple class and module

    Hi all,
    I'm a beginner with developping Add-on with SAP. All the example show a "SubMain" which call a unique class where all the code is. I'd like to simplify my code in creating separate module and i have problem with the SBO_Application.
    Here is my code, when I declare Sbo_Application in a general module, the Sub_connect is OK but not the Handles of the SBO_Application_AppEvent. If I declare it like this code. the sub_connect is wrong.
    Have you an idea?
    Sorry for my bad English.
    Thanks in advance
    Sylvie
    Module SubMain
        Public Sub Main()
            Dim obj_Easypay As New Class_Easypay    ' execute the add-on code
            System.Windows.Forms.Application.Run()  ' Starting the Application
        End Sub
    End Module
    Friend Class Class_Easypay
        Public WithEvents SBO_Application As SAPbouiCOM.Application
        Public Sub New()
            MyBase.New()
            'Connection to SAP Business one application
            Sub_Connect_SBO()
        End Sub
        Private Sub SBO_Application_AppEvent(ByVal EventType As SAPbouiCOM.BoAppEventTypes) Handles SBO_Application.AppEvent
             SBO_Application.Messagebox(" ")
        end sub
    end class

    Hello,
    I have readed that your project has been stopped but for logging i am answering your question:
    You should create a global variable for holding the application object tp manupulate with outside your class.
    Module SubMain
      Public g_SBO_Application As SAPbouiCOM.Application ' this is for all modules, without events
      Public Sub Main()
      Dim obj_Easypay As New Class_Easypay ' execute the add-on code
      System.Windows.Forms.Application.Run() ' Starting the Application
      End Sub
    End Module
    ' Do not use Friend class -  memory weaks
    Friend Class Class_Easypay
    Private WithEvents SBO_Application As SAPbouiCOM.Application ' local you can use only inside form the class
    Public Sub New()
      MyBase.New()
      'Connection to SAP Business one application
      Sub_Connect_SBO()
       g_SBO_Application = SBO_Applicatio
    End Sub
    'Use Private
    Private Sub sbo_application_AppEvent (ByVal EventType As SAPbouiCOM.BoAppEventTypes) Handles sbo_application.AppEvent      
      Test ()' or MyModule1.Test()  
    end sub
    end class
    Module MyModule1
      Sub Test
        g_SBO_Application.statusbar.settext("TEST")
      End sub
    End Module
    Module MyModule
      Sub MyApp_EventHandler(sbo_application_AppEvent)
        g_SBO_Application.statusbar.settext("TEST")
      End sub
    End Module
    Regards,
    János

  • DrawImage() and multiple classes

    First I should start by saying I am VERY new to Java. I have written a program that uses multiple classes, and i would like to place      boolean b = g.drawImage(cardPics,x2,yPos,50,75),this); in my class. I have passed Graphics g from paint. I am able to use g.drawString, etc, but when I try to drawImage, it will not even compile. I CAN use
    boolean b = g.drawImage(cardPics[i],x2,yPos,50,75),this); in paint outside of the classes, so I believe I have the image array set up right.
    This is what the compilers reads:
    cannot resolve symbol
         boolean b =g.drawImage(cardPics[i],x2,yPos,50,75),this);
    (The symbol that it is referring to is the period between g and drawImage)
    Any help is greatly appreciated.
    Thankyou
    Apryl

    Actually, I did fiigure it out. The problem was that drawImage was being handed an ImageObserver, when infact it didn't need one. But drawImage needs an imageObserver as a parameter, so instead using 'this' you replace it with null.
    Thanks for all of the help

  • How to compile and register a Java CFX tag with multiple class files?

    All-
    If this is the wrong forum for CFX questions, please let me
    know.
    I need to determine how to compile and register a Java CFX
    tag that contains multiple class files. One class file implements
    the CustomTag interface and the other class files implement various
    supporting classes. All of the documentation that I have found
    talks about using a single class file. I am assuming that a JAR
    file will be involved, but I am not sure of the specifics.
    Thanks in advance for your help.
    -Josh

    Yes, it will involve a jar. Use your java IDE (eclipse,
    etcetera ..) to create a jar containing all of the classes. Check
    your ide's documentation for how to create jar files. After you
    have created the jar, place the jar in the CF class path so CF will
    recognize it. For example the {cf_root}/WEB-INF/lib directory. CF
    must be restarted before it will detect the new jar. After
    restarting CF, register the CFX tag in the ColdFusion Administrator
    using the name of the class that implements the CustomTag
    interface.
    Though it is worth noting you can also instantiate java
    classes directly from ColdFusion (ie without using a CFX
    tag).

  • Multiple Artists and Genres per Song

    I listen to lots of electronic music, and I'm a professional DJ.
    Electronic music is a very diverse and complex music category, and have lots of genres and sub-genres. Electronic music producers usually try to transpose genre boundaries, and they usually produce songs contained in two or more equally important genres. For instance, a track can be contained in the genres "house" and "techno", or "disco", "techno" and "acid".
    Also, it's really very common that electronic music artists collaborate with each other. Songs produced in collaboration do not belong to one single artist, but to two or more. In this case, it's not correct to say that one is the main artist, and the others are second artists (collaborators, composers remixes, or whatever) - they all detain the same equal authorship status over the composed track.
    The problem with iTunes is that it supports one single genre, and one single artist per song. Sure, there's the album artist, but, again, that doesn't apply to albums where multiple artists participate with equal importance. And using "V.A." or "Various Artists" in the song artist or album artist fields is ugly and useless - it doesn't say anything relevant.
    I know that Smart Playlists and Grouping features can help alleviate this deficiency, but they don't solve them at all. They're not elegant and complete solutions. If you browse the iTunes library, you will still see tracks as having only one genre and one artist, which is very frustrating.
    What I ask is really easy to implement. In fact, it wouldn't require to alter the existing ID3 and tag scheme. Just split artists and genres using a colon or semicolon character. For instance, in the "Artist" tag, iTunes can store the following:
        "Christian Smith; Mark Broom; Renato Cohen"
    and then, in the browser, iTunes could display "Christian Smith", "Mark Broom" and "Renato Cohen" as three distinct artists.
    The same could be used for the "Genre" tag:
        "Techno; House; Progressive"
    could be see, in the browser, as three different genres: "Techno", "House" and "Progressive".
    I've made an extensive web research, and I know that this deficiency  doesn't annoy only me, but lots of other users. And it's a pretty old request too - dated from 2003.
    Please, Apple, implement this feature. My huge electronic music collection really needs to be categorized into multiple artists and multiple genres.
    Thank you.

    Well said comment...
    The solution to this problem overall is simple.
    If I pull out my Ipod, and go to the section to browse by artist, then all artists would be listed individually in the list if they are separated in a song by the '&' symbol.  In the main music list in itunes, this would not result in multiple copies of the file.
    The same situation would apply in the genre browser.  If there is a tag with "POP & Chinese" then the song would appear if I was searching in pop OR Chinese.  It would not show a Genre called "POP & Chinese" in the genre browser.  It would show POP and Chinese SEPARATELY in the list!!!
    This is not a issue of some programming esoterica nor does it require some super genius to figure out.
    Wake up Apple programmers....
    Even smartlists are broken in the ipad/ipod and don't work the same way as they do in itunes. WHAT ARE YOU DOING WITH THAT A5X chip that you can't fix this problem?  I make a smartlist for the genre section at least and this allows me to accomplish what I stated above with genres by using the smartlists instead of the genre browser.
    The artist browser and genre browser are worthless to me...  since MANY of my songs have multi-artist and multi-genre separated by '&' and the stupid browser lists all the permutations instead of delimiting the genres and artists.
    My genre list looks sorta like this:
    Pop & chinese & instrumental
    Pop & japanese
    Pop & Soundtrack & Anime & Japanese
    Pop & score & anime
    Pop & chinese & vocal
    Pop & electronica
    What a mess...  but I can't categorize my stuff any other way without making it hard to decide which place to put a song.  Does a chinese soundtrack pop song get filed under chinese? or pop? or soundtrack?  I SHOULD be able to find the song regardless of which sub-genre I look under in the genre browser.
    This is basically simple.  The people that understand this are basically right and Apple is WRONG on this...  no matter what detractors on this thread say. The devices and software could easily be tweaked to dramatically improve the user experience but Apple is poor at getting involved in discussion forums like this to allow us to help them fix these issues.  Some of the product developers on the app store are far more receptive to suggestions than Apple is.  They are not getting enough of the advantages of crowd sourcing.
    I would fly out to Cupertino and correct MANY UI mistakes/errors for them if they will have me out there...
    I'll hold my breath and wait for a message to have me come out there.  There are still a lot of things about OSX and iOS that can be made simpler too.  still FAR too much extraneous junk and poor implementation of cloud capabilities.
    Why on earth does itunes have a "get info" menu dropdown to get into track data?  Why is the track data separated into 7 submenus separated by tabs?  The whole data entry situation in itunes is way too complex.  It's downright painful.
    Why are there no 24bit audio files yet for premium prices?  Are the people at apple doing too much LSD?  WHAT IS GOING ON?  You have to be disabled not to hear the difference between great recordings and that 256kbps garbage the peddle.  come to my house on the 107db sensitivity speakers with a Class A amplifier and tell me you can't tell the difference and I will have your hearing checked.
    hopefully the itunes department will contact someone on this thread to provide a list of the mistakes in itunes/ipod software so the problems can all be fixed.
    An AUDIOPHILE needs to take over itunes and fix this nonsense STAT.  It's simply embarassing at this point.  Where are my 24 bit files on my 1000gb ipod?  WHY IS THERE NO AUDIOPHILE IPOD? They can use there 100 billion cash hoard and make a GOOD home distribution system beyond "airplay/airport".
    Why is mediocrity being considered at Apple when they do so many other things great?  Considering I own half a million dollars in stock, believe me I do appreciate the company at large.  I am only ranting about the treatment of audiophiles and the complete dumbing down of the music experience to mass garbage when we live in the 21st century.   What we see is important (retina display) but what we hear is not?
    /rant off...
    Apple feel free to contact me and I can tell you how to develop the BEST product for music ever implemented...  I don't need compensation...  I want products that I WANT to buy!!!!

  • Accessing the same object from multiple classes.

    For the life of me I can't workout how I can access things from classes that haven't created them.
    I don't want to have to use "new" multiple times in seperate classes as that would erase manipulated values.
    I want to be able to access and manipulate an array of objects from multiple classes without resetting the array object values. How do I create a new object then be able to use it from all classes rather than re-creating it?
    Also I need my GUI to recognize the changes my buttons are making to data and reload itself so they show up.
    All help is good help!
    regards,
    Luke Grainger

    As long as you have a headquarters it shouldn't be to painfull. You simply keep a refrence to your ShipDataBase and Arsenal and all your irrellevant stuff in Headquarters. So the start of your Headquarters class would look something like:
    public class Headquarters{
      public Arsenal arsenal;
      public ShipDatabase db;
    //constructor
      public Headquarters(){
        arsenal = new Arsenal(this, ....);
        db = new ShipDatabase(...);
    //The Arsenal class:
    public class Arsenal{
      public Headquarter hq;
      public Arsenal(Headquarter hq, ....){
        this.hq = hq;
        .Then in your ShipDatabase you should, as good programing goes, keep the arraylist as a private class variable, and then make simple public methods to access it. Methods like getShipList(), addToShipList(Ship ship)....
    So when you want to add a ship from arsenal you write:
    hq.db.addToShipList(ship);
    .Or you could of course use a more direct refrence:
    ShipDatabase db = hq.db;
    or even
    ShipList = hq.db.getShipList();
    but this requires that the shiplist in the DB is kept public....
    Hope it was comprehensive enough, and that I answered what you where wondering.
    Sjur
    PS: Initialise the array is what you do right here:
    //constructor
    shipList = new Ship[6];
    shipList[0] = new Ship("Sentry", 15, 10, "Scout");
    " " " "etc
    shipList[5] = new Ship("Sentry", 15, 10, "Scout");PPS: To make code snippets etc. more readable please read this article:
    http://forum.java.sun.com/faq.jsp#messageformat

  • Difference between abstract class and the normal class

    Hi...........
    can anyone tell me use of abstract class instead of normal class
    The main doubt for me is...
    1.why we are defining the abstract method in a abstract class and then implementing that in to the normal class.instead of that we can straight way create and implement the method in normal class right...../

    Class vs. interface
    Some say you should define all classes in terms of interfaces, but I think recommendation seems a bit extreme. I use interfaces when I see that something in my design will change frequently.
    For example, the Strategy pattern lets you swap new algorithms and processes into your program without altering the objects that use them. A media player might know how to play CDs, MP3s, and wav files. Of course, you don't want to hardcode those playback algorithms into the player; that will make it difficult to add a new format like AVI. Furthermore, your code will be littered with useless case statements. And to add insult to injury, you will need to update those case statements each time you add a new algorithm. All in all, this is not a very object-oriented way to program.
    With the Strategy pattern, you can simply encapsulate the algorithm behind an object. If you do that, you can provide new media plug-ins at any time. Let's call the plug-in class MediaStrategy. That object would have one method: playStream(Stream s). So to add a new algorithm, we simply extend our algorithm class. Now, when the program encounters the new media type, it simply delegates the playing of the stream to our media strategy. Of course, you'll need some plumbing to properly instantiate the algorithm strategies you will need.
    This is an excellent place to use an interface. We've used the Strategy pattern, which clearly indicates a place in the design that will change. Thus, you should define the strategy as an interface. You should generally favor interfaces over inheritance when you want an object to have a certain type; in this case, MediaStrategy. Relying on inheritance for type identity is dangerous; it locks you into a particular inheritance hierarchy. Java doesn't allow multiple inheritance, so you can't extend something that gives you a useful implementation or more type identity.
    Interface vs. abstract class
    Choosing interfaces and abstract classes is not an either/or proposition. If you need to change your design, make it an interface. However, you may have abstract classes that provide some default behavior. Abstract classes are excellent candidates inside of application frameworks.
    Abstract classes let you define some behaviors; they force your subclasses to provide others. For example, if you have an application framework, an abstract class may provide default services such as event and message handling. Those services allow your application to plug in to your application framework. However, there is some application-specific functionality that only your application can perform. Such functionality might include startup and shutdown tasks, which are often application-dependent. So instead of trying to define that behavior itself, the abstract base class can declare abstract shutdown and startup methods. The base class knows that it needs those methods, but an abstract class lets your class admit that it doesn't know how to perform those actions; it only knows that it must initiate the actions. When it is time to start up, the abstract class can call the startup method. When the base class calls this method, Java calls the method defined by the child class.

  • Read multiple files and save all into one output file(AGAIN)

    Hi, guys
    I need your help for reading data from multiple files and save the results into one output file. When files are selected from file chooser, my program read the data line by line , do some calculations and save the result into the output. I made an array to store input files and it seems to be working fine, but when it comes to SaveFile() function, issues NullPointException message.
    public class FileReduction1 extends JFrame implements ActionListener
       // GUI definition and layout
        /* ACTION PERFORMED */
        public void actionPerformed(ActionEvent event) {
            if (event.getActionCommand().equals("Open File")) getFileName();
        /* OPEN THE FILE */
        private void getFileName() {
            // Display file dialog so user can select file to open
         JFileChooser fileChooser = new JFileChooser();
         fileChooser.setFileSelectionMode(JFileChooser.FILES_ONLY);
            fileChooser.setMultiSelectionEnabled(true);
         int result = fileChooser.showOpenDialog(this);
         // If cancel button selected return
         if (result == JFileChooser.CANCEL_OPTION) return;
            if (result == JFileChooser.APPROVE_OPTION)
             files = fileChooser.getSelectedFiles();
                textArea.setText("");
                if(files.length>0)
                    filelist="";
                    System.out.println("files length"+files.length);
                    for(int i=0;i<files.length;i++)
                         System.out.println(files.getName());
    filelist+=files[i].getName()+" ,";
    if (checkFileName(files[i]) )
    openButton.setEnabled(true);
    readButton.setEnabled(true);
    textArea.append("file "+files[i].getName()+"is a proper file"+"\n");
    readFile(files[i]);
    textfield.setText(filelist);
    else{JOptionPane.showMessageDialog(this,"Please select file(s)",
                    "Error 5: ",JOptionPane.ERROR_MESSAGE); }
         // Obtain selected file
    /* READ FILE */
    private void readFile(File fileName_in) {
    // Disable read button
    readButton.setEnabled(false);
    // Dimension data structure
         getNumberOfLines(fileName_in);
         data = new String[numLines][4];
         // Read file
         readTheFile(fileName_in);
         // Rnable open button
         openButton.setEnabled(true);
    /* GET NUMBER OF LINES */
    /* Get number of lines in file and prepare data structure. */
    private void getNumberOfLines(File fileName_in) {
    int counter = 0;
         // Open the file
         openFile(fileName_in);
         // Loop through file incrementing counter
         try {
         String line = fileInput.readLine();
         while (line != null) {
         counter++;
              System.out.println("(" + counter + ") " + line);
    line = fileInput.readLine();
         numLines = counter;
    closeFile(fileName_in);
         catch(IOException ioException) {
         JOptionPane.showMessageDialog(this,"Error reading File",
                   "Error 5: ",JOptionPane.ERROR_MESSAGE);
         closeFile(fileName_in);
         System.exit(1);
    /* READ FILE */
    private void readTheFile(File fileName_in)
    // Open the file
    //int row=0;
    int col=0;
    openFile(fileName_in);
    System.out.println("Read the file");
    // Loop through file incrementing counter
    try
    String line = fileInput.readLine();
    while (line != null)
    boolean containsDoubles = false;
    double temp;
    String[] lineParts = line.split("\t");
    try
    for (col=0;col<lineParts.length;col++)
    temp=Double.parseDouble(lineParts[col]);
    data[row][col] = lineParts[col];
    containsDoubles = true;
    System.out.print("data["+row+"]["+col+"]="+lineParts[col]+" ");
    } catch (Exception e) {row=0; col=0; temp=0.0;}
    if (containsDoubles){ row++;}
    System.out.println();
    line = fileInput.readLine();
    catch(IOException ioException)
    JOptionPane.showMessageDialog(this,"Error reading File", "Error 5: ",JOptionPane.ERROR_MESSAGE);
    closeFile(fileName_in);
    System.exit(1);
    //System.out.println("length"+data.length);
    closeFile(fileName_in);
    process(fileName_in);
    /* CHECK FILE NAME */
    /* Return flase if selected file is a directory, access is denied or is
    not a file name. */
    private boolean checkFileName(File fileName_in) {
         if (fileName_in.exists()) {
         if (fileName_in.canRead()) {
              if (fileName_in.isFile()) return(true);
              else JOptionPane.showMessageDialog(null,
                        "ERROR 3: File is a directory");
         else JOptionPane.showMessageDialog(null,
                        "ERROR 2: Access denied");
         else JOptionPane.showMessageDialog(null,
                        "ERROR 1: No such file!");
         // Return
         return(false);
    /* OPEN FILE */
    private void openFile(File fileName_in) {
         try {
         // Open file
         FileReader file = new FileReader(fileName_in);
         fileInput = new BufferedReader(file);
         catch(IOException ioException) {
         JOptionPane.showMessageDialog(this,"Error Opening File",
                   "Error 4: ",JOptionPane.ERROR_MESSAGE);
         textArea.append("OPEN FILE\n---------\n");
         textArea.append(fileName_in.getPath());
         textArea.append("\n");
         //System.out.println("File opened successfully");
    /* CLOSE FILE */
    private void closeFile(File fileName_in) {
    if (fileInput != null) {
         try {
              fileInput.close();
         catch (IOException ioException) {
         JOptionPane.showMessageDialog(this,"Error Opening File",
                   "Error 4: ",JOptionPane.ERROR_MESSAGE);
    System.out.println("File closed");
    private void process(File fileName_in) {
    //getNumberOfLines();
         //data = new String[numLines][3];
         // Read file
    double temp,temp1;
         //readTheFile();
    //System.out.println("row:"+row);
    //int number=data.length;
    //System.out.println(number);
    for (int i=0; i<row; i++)
    temp=Double.parseDouble(data[i][1]);
    sumx+=temp;
    temp1=Double.parseDouble(data[i][3]);
    sumy+=temp1;
    multixy+=(temp*temp1);
    square_x_sum+=(temp*temp);
    square_y_sum+=(temp1*temp1);
    //System.out.println("Sum(x)="+sumx);
    double tempup=(row*multixy)-(sumx*sumy);
    double tempdown=(row*square_x_sum)-(sumx*sumx);
    slope=tempup/tempdown;
    double tempbup=sumy-(slope*sumx);
    intb=tempbup/row;
    double tempside=(row*square_y_sum)-(sumy*sumy);
    double cordown=Math.sqrt(tempdown*tempside);
    corr=tempup/cordown;
    r_sqrt=corr*corr;
         textArea.append("Data for file"+ fileName_in.getName()+" have been processed successfully.");
         textArea.append("\n");
         textArea.append("Please enter output file name including extension.");
    System.out.println("number"+row);
    System.out.println("slope(m)="+slope);
    System.out.println("intecept b="+intb);
    System.out.println("correlation="+corr);
    System.out.println("correlation="+r_sqrt);
    saveFile();
    private void saveFile()
    textArea.append("SAVE FILE\n---------\n");
    if (openFile1())
         try {
              outputToFile();
    catch (IOException ioException) {
              JOptionPane.showMessageDialog(this,"Error Writing to File",
                   "Error",JOptionPane.ERROR_MESSAGE);
    private boolean openFile1 ()
         // search for the file path
    StringBuffer stringpath;
    title=textfield1.getText().trim();
    int temp=fileName_in.getName().length();
    int temp_path=fileName_in.getPath().length();
    int startd=(temp_path-temp);
    stringpath=new StringBuffer(fileName_in.getPath());
    stringpath.delete(startd, temp_path+1);
    //System.out.println("file-path="+temp_path);
    //System.out.println("length-file="+temp);
    path=stringpath.toString();
    fileName_out = new File(path, title);
    //System.out.println(file_out.getName());
    if (fileName_out==null || fileName_out.getName().equals(""))
         JOptionPane.showMessageDialog(this,"Invalid File name",
                   "Invalid File name",JOptionPane.ERROR_MESSAGE);
         return(false);
         else
    try
    boolean created = fileName_out.createNewFile();
    if(created)
    fileOutput = new PrintWriter(new FileWriter(fileName_out));
    fileOutput.println("File Name"+"\t"+"Slope(m)"+"\t"+"y-intercept(b)"+"\t"+"Coefficient(r)"+"\t"+"Correlation(R-Squared)");
    return(true);
    else
    fileOutput = new PrintWriter(new FileWriter(fileName_out,true));
    return(true);
    catch (IOException exc)
    JOptionPane.showMessageDialog(this,"Please enter the file name","Error",JOptionPane.ERROR_MESSAGE);
    return(false);
    private void outputToFile() throws IOException
    // Initial output
         textArea.append("File name = " + fileName_out + "\n");
         // Test if data exists
         if (data != null)
         fileOutput.println(fileName_in.getName() +"\t"+ slope+"\t"+intb+"\t"+corr+"\t"+r_sqrt);
    textArea.append("File output complete\n\n");
         else
    textArea.append("No data\n\n");
         // End by closing file
    initialcomp();
         fileOutput.close();
    private void initialcomp()
    slope=0.0;
    intb=0.0;
    corr=0.0;
    r_sqrt=0.0;
    sumx=0.0; sumy=0.0; multixy=0.0; square_x_sum=0.0; square_y_sum=0.0;
    for(int i=0;i<data.length;i++)
    for(int j=0;j<data[i].length;j++)
    data[i][j]=null;
    /* MAIN METHOD */
    public static void main(String[] args) throws IOException
         // Create instance of class FileChooser
         FileReduction1 newFile = new FileReduction1("File Reduction Program");
         // Make window vissible
         newFile.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
         newFile.setSize(500,400);
    newFile.setVisible(true);
    Sorry about the long lines.
    As you can see, all input files saved in array called files, however when OpenFile1() function is called, it take input (fileName_in) as a single file not an array. I'm assuming this causes the exception.
    When there's muptiple inputs, program should take each file from getFileName() to outputToFile() sequentially.
    Does anybody have an idea to solve this?
    Thanks a lot!!

    you naming convention is confussing. you should follows Java naming convention..you have a getXXX but decalred the return type as "void"...get usully means to return something...
    your code is doing too much..and hard to follows..
    1. get the selected files
    for each selected file
    process the file and return the result
    write out the result.
    /** close the precious resource */
    public void closeResource(Reader in){
        if (in != null){
            try{ in.close(); }
            catch (Exception e){}
    /** get the total number of line in a file */
    public int getLineCount(File file) throws IOException{
        BufferedReader in = null;
        int lineCount = 0;
        try{
            in = new BufferedReader(new FileReader(file));
            while ((in.readLine() != null)
                lineCount++;
            return lineCount;
        finally{ closeResource (in);  }
    /** read the file */
    public void processFile(File inFile, File outFile) throws IOException{
        BufferedReader in = null;
        StringBuffer result = new StringBuffer();
        try{
            in = new BufferedReader(new FileReader(inFile));
            String line = null;
            while ((in.readLine() != null){
                .. do something with the line
                result.append(....);
            writeToFile(outFile, result.toString());
        finally{ closeResource (in);  }
    public void writeToFile(File outFile, String result) throws IOException{
        PrintWriter out = null;
        try{
            out = new PrintWriter(new FileWriter(outFile, true));  // true for appending to the end of the file
            out.println(result);
        finally{  if (out != null){ try{ out.close(); } catch (Exception e){} }  }
    }

  • Multiple columns and rows in MessageService

    I am attempting to create a message (via MessageService) which has multiple lines of data, and each line has multiple data columns.
    Background:  My program reads data from a web store, and creates Sales Orders in SBO.  A single run might process multiple orders.  When all orders have been entered, the program should send a (single) message to a list of recipients.  The message will have one line of data for each sales order produced.  Each line will contain two fields: the linked SBO sales order number, and the unlinked web order number.
    When the message is initially created, I'm defining the multiple columns and initializing the data lines:
    pMessageDataColumns = oMessage.MessageDataColumns
    pMessageDataColumn = pMessageDataColumns.Add()
    pMessageDataColumn.ColumnName = "SalesOrder"
    pMessageDataColumn.Link = BoYesNoEnum.tYES
    pMessageDataColumn = pMessageDataColumns.Add()
    pMessageDataColumn.ColumnName = "WebOrder"
    pMessageDataColumn.Link = BoYesNoEnum.tNO
    oLines = pMessageDataColumn.MessageDataLines()
    Later, as each Sales Order is processed, I'm attempting to inject the two data values into the message data:
    oLine = oLines.Add()
    oLine.Value = Str(pOrd.DocNum)
    oLine.Object = 17
    oLine.ObjectKey = Str(pOrd.DocEntry)
    oLine = oLines.Add()
    oLine.Value = pOrd.WebOrder
    The above code would be invoked for each Sales Order processed.  However, it generates an "Internal error (-5002) occurred" when the message is ultimately sent.
    The SDK documentation states:
    The MessageDataLine is a child data structure related to the MessageDataColumn. It contains the value of a specified cell in the Data table, which is defined by its column number (vtIndex of Item of MessageDataColumns) and row number (vtIndex of Item of MessageDataLines).
    I guess I don't understand the relationship between adding a "line" in my data display versus adding data into a "column".  It appears that the "oLines.Add()" is used to bump across the columns of the data.  If so, how do I advance to the next entire row of data in the message?
    Thanks, Dave

        Class Item
            Public ItemCode As String
            Public Dscription As String
        End Class
    Dim ItemCodes as new list( of item)
    Dim one as new item
    one.ItemCode = "ItemCode"
    one. Dscription ="Name of Item"
    itemcodes.add (one)
            Try
                Dim oCmpSvc As SAPbobsCOM.CompanyService = _ocmp.GetCompanyService()
                Dim oMsgSvc As SAPbobsCOM.MessagesService = oCmpSvc.GetBusinessService(ServiceTypes.MessagesService)
                Dim oMsg As SAPbobsCOM.Message = oMsgSvc.GetDataInterface(MessagesServiceDataInterfaces.msdiMessage)
                oMsg.Subject = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss")
                oMsg.Text = Msg
                Dim oMsgDataColumn As SAPbobsCOM.MessageDataColumn
                If ItemCodes.Count > 0 Then
                    oMsgDataColumn = oMsg.MessageDataColumns.Add()
                    oMsgDataColumn.ColumnName = "Product / Item Code"
                    oMsgDataColumn.Link = BoYesNoEnum.tYES
                    For Each oneitem As Item In ItemCodes
                        Dim oMsgDataLine As SAPbobsCOM.MessageDataLine = oMsgDataColumn.MessageDataLines.Add()
                        oMsgDataLine.Object = "4"
                        oMsgDataLine.ObjectKey = oneitem.ItemCode
                        oMsgDataLine.Value = oneitem.Dscription
                    Next
                    oMsgDataColumn = oMsg.MessageDataColumns.Add()
                    oMsgDataColumn.ColumnName = "Description"
                    oMsgDataColumn.Link = BoYesNoEnum.tNO
                    For Each oneitem As Item In ItemCodes
                        Dim oMsgDataLine As SAPbobsCOM.MessageDataLine = oMsgDataColumn.MessageDataLines.Add()
                        oMsgDataLine.Value = oneitem.Dscription
                    Next
                End If
                        Dim oMsgRecipient As SAPbobsCOM.Recipient = oMsg.RecipientCollection.Add()
                        oMsgRecipient.UserCode = "manager"
                        oMsgRecipient.SendInternal = BoYesNoEnum.tYES
                        oMsgRecipient.SendEmail = BoYesNoEnum.tNO
                oMsgSvc.SendMessage(oMsg)
                MsgBox("SAP B1 internal Message sent...")
            Catch ex As Exception
                MsgBox("Unable to send SAP B1 internal message. Error:" + ex.Message)
            End Try
        End Sub

  • Transfer assets collectively to new class and create new assets like ABUMN

    We need to change the account determination for a few Asset Classes that already have assets with postings.  As a result we must create new asset classes and assign a new account determination.
    Is there a program that would allow transfer assets collectively to a new asset class and create new assets automatically similar to ABUMN?  T-code ABUMN allows you to transfer multiple assets but you must create the new assets first.  ABUMN will transfer and create new asset but only does one asset at a time. 
    There are hundreds of assets with postings to be transferred from the old asset classes to the corresponding new asset classes.
    Appreciate whatever input you can provide.
    Tara

    download the asset master data(original) and create new asstes using lsmw or any third party tool also.

  • How to use for loops with Multiple Initializers and Incrementers

    I found that my for loop is printing out wrong, because I am using two for loops. I have searched but all I can find out is you can't use multiple inializers and increments, does anyone know how to get around this? How would I use an array for this?
    Thanks very much for your help.
    import java.util.Random;
    import java.util.Arrays;
    /** Generate numnodes value for random integers in the range 0..499. */
    public final class RandomInteger {
    public static final void main(String... aArgs){
    log("Generating 6 random integers in range 0..499.");
    int numnodes = 6;
    //Randomly generate a number between 0 and 499 for the x and y coordinates for the nodes
    Random randomGenerator = new Random();
    for (int x = 0; x < numnodes; ++x) {
    int randomInt = randomGenerator.nextInt(500);
    Random randomGenerator2 = new Random();
    for (int y = 0;y < numnodes; ++y) {
    int randomInt2 = randomGenerator2.nextInt(500);
    log("Generated : " + randomInt + " " + randomInt2);
    log("Done.");
    }

    Sorry that code works, but I want to use both my x and y coordinates to get a random number from 0 to 499 in both of them, then I want to do some comparisons of the values, then return it to another function. As it stands now, I get the wrong results when I run it, as you can see at the bottom.
    Thanks very much for your help. I have been stumped all mornign on this and have looked everywhere trying to find an example. I don't won't to use math random. I am on a tight deadline to finish and at the rate I am going, I will not complete it.
    /** Generate numnodes value for random integers in
    the range 0..499. */
    public final class RandomInteger {
    public static final void main(String... aArgs){
    log("Generating 6 random integers in range
    0..499.");
    int numnodes = 6;
    //Randomly generate a number between 0 and 499 for
    the x and y coordinates for the nodes
    Random randomGenerator = new Random();
    for (int x = 0; x < numnodes; ++x) {
    int randomInt = randomGenerator.nextInt(500);
    Random randomGenerator2 = new Random();
    for (int y = 0;y < numnodes; ++y) {
    int randomInt2 = randomGenerator2.nextInt(500);
    log("Generated : " + randomInt + " " + randomInt2);
    log("Done.");
    private static void log(String aMessage){
    System.out.println(aMessage);
    Output:
    --------------------Configuration:
    <Default>--------------------
    Generating 6 random integers in range 0..499.
    Generated : 98 254
    Generated : 98 347
    Generated : 98 359
    Generated : 98 25
    Generated : 98 277
    Generated : 98 148
    Generated : 416 401
    Generated : 416 165
    Generated : 416 354
    Generated : 416 169
    Generated : 416 144
    Generated : 416 354
    Generated : 295 158
    Generated : 295 138
    Generated : 295 349
    Generated : 295 324
    Generated : 295 18
    Generated : 295 193
    Generated : 197 451
    Generated : 197 416
    Generated : 197 480
    Generated : 197 33
    Generated : 197 490
    Generated : 197 494
    Generated : 324 412
    Generated : 324 490
    Generated : 324 213
    Generated : 324 386
    Generated : 324 467
    Generated : 324 163
    Generated : 379 180
    Generated : 379 446
    Generated : 379 314
    Generated : 379 52
    Generated : 379 113
    Generated : 379 271
    Done.
    Process completed.

  • Multiple classes in the same source file

    I'm not sure what this is called, having multiple classes in the same source file. At first I thought it ws called subclassing but then I googled it and found that subclasses are just derived classes. Here's an example of what I'm talking about.
    public class A {
    class B {
    class C {
    }So first of all, what is having multiple classes in the same source file called?
    Secondly, what are the advantages/disadvantages of this?
    Thirdly, can you have a class completely WITHIN a class (same source file but inside the class not outside) and what are the advantages/disadvantages of this?

    Advantage: You can reduce the number of source files specialy when your secondry classes are used only in the public class of the file.
    Disadvantage: Normaly it make things more clear if we have one-to-one correspondance of class and source files. This make things easy when you want to find the java file of a perticuler class file. Also If you later wanted to create a seperate public class with a same name as one of those secondry classes you got lots of changes to do.
    You can avoid this by creating them as nested classes
    ex:-
    public class MyPublicClass{
       private static class MyInnerClass{
    }this way the inner class will create a class file with name "MyPublicClass$MyInnerClass.class" instead of just "MyInnerClass.class"
    And also if you declare the inner class as public you can access them from out side

  • Multiple classes in one file?

    I would like to do the following
    #import <UIKit/UIKit.h>
    @interface O : NSObject
    @end
    @interface A : O
    - (void) hi;
    @end
    @interface B : O
    - (void) hi;
    @end
    but the compiler complains. I do not want to create (O.h, O.m), (A.h, A.m), and (B.h, B.m) files. Surely one can declare multiple classes in a single file? If so, how. If not, why not?
    -Doug Danforth

    I've done that, should work. What is the compiler complaining about?
    Could it be the missing semicolons after the @end statements?

  • Part interchangeability with FFF class and FFFC - HERB material type

    Experts-
    Have you worked with Part interchangeability with FFF class and FFFC or HERB material type?
    I am looking for cross-reference functionality for interchangeable materials from maintenance/service perspective. We have users changing manufacturer's part number as and when needed and maintaining cross-reference via classification. Maintaining SAP part number and HERS is too much data maintenance, so we are looking for simple solution.
    We are in standard ECC 6.0. (No APO). I checked OSS 181764, but it doesn't help us in instructions for enhancement.
    If this needs activation for DIMP or A&D, do you know enhancement for this?
    Thanks for your help.
    RP

    Hi
    I have been involved with a client who is interested to know the implementation of FFF functionality. Can you share your experience  in a bit more details.
    The client is interested in using parts where multiple models are available in the market and few of them are interchangeable. They would like to purchase it as an asset and then manage the inventory as non valued material. How does it work throuh the APO for forecasting and demand planning functionalities.
    Thanks in advance.

Maybe you are looking for

  • How do I move a photo into an album in the new Photos application?

    How do I move a photo into an album in the new Photos application?

  • Ram Issues

    I Have 2 sticks of ram worked fine together for 3weeks running at ddr400. Today I restart my system and I get a nopost. I check the lights and I have  Early Chipset Initalization. Also I can boot and use the computer with 1 stick of ram out tested wi

  • Integrate EchoSign with Microsoft Word

    Hello, We use EchoSign to send documents for signature which are generated from our Recruitment System. These documents are person specific and are pre-filled with certain details plus the tag for the EchoSign signature. Currently, when the Recruitme

  • Create a service contract under SAP CRM

    Hi, I try to create a service contract under SAP CRM with transaction code CRMD_ORDER but when I click on "Create" button, nothing display ! Is it possible to create a contract under SAP CRM ? In the end, I would like to replicate a contract from CRM

  • Create non-valuated material using MMU1 and MM01

    Hi MM expertise, To create non-valuated material, we need to use standard SAP transaction MMU1. Earlier on, I created the non-valuated material using MM01. Want to know any impact and different between MM01 and MMU1. Regards, sim